Method to revert all applied migrations

See original GitHub issue

Issue type:

[ ] question [ ] bug report [X] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [X] postgres [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[X] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

There are methods to run all pending migrations and undo only the last migration. It would be useful to also have a method to revert all applied migrations. I would like to use this during tests so as to apply all migrations before a test, and revert all of them after the test.

I have migrations that create TEXT SEARCH CONFIGURATIONs, for example, which are not deleted by the dropDatabase() command. This would ensure that the database would be in a clean state and also test the down part of migrations. The command to undo the last migration cannot be used for this since it does not return anything both when a migration was reverted and when there were no more migrations to revert.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
edevilcommented, Oct 29, 2018

@pleerock Thanks! That’s probably enough.

5reactions
pleerockcommented, Oct 28, 2018

here is how this can be achieved right now:

const migrationExecutor = new MigrationExecutor(connection);
const migrations = migrationExecutor.getMigrations();
for (let migration of migrations) {
     migrationExecutor.undoLastMigration();
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to revert the last migration? - python - Stack Overflow
You can revert by migrating to the previous migration. For example, if your last two migrations are: 0010_previous_migration; 0011_migration_to_revert.
Read more >
Undo Migrations - Tutorial - Flyway
This brief tutorial will teach how to use undo migrations. ... Now let's create undo migrations for these two applied versioned migrations.
Read more >
How to Reset Migrations - Simple is Better Than Complex
Scenario 1: · 1. Remove the all migrations files within your project · 2. Drop the current database, or delete the db.sqlite3 if...
Read more >
Managing Migrations - EF Core - Microsoft Learn
In some extreme cases, it may be necessary to remove all migrations and start over. This can be easily done by deleting your...
Read more >
How Do I Reset Django Migration - raturi.in
If there are any pending migrations, apply them first. If you see the below message, You are good to go. ... You must...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found