Revert migrations running in reverse order
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[x] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.18
(or put your version here)
Steps to reproduce or a small repository showing the problem:
I created two migrations, one on August and the other today. After running this last migration I wanted to check that the down
would be applied correctly. However I run into the following:
Before running revert:
> db.migrations.find()
{ "_id" : ObjectId("5d7118c2bfc3a0f771f3ea4a"), "timestamp" : 1566560354098, "name" : "UpdateContacts1566560354098" }
{ "_id" : ObjectId("5d7118c2bfc3a0f771f3ea4b"), "timestamp" : 1567689639607, "name" : "MergeConfigs1567689639607" }
Running revert:
2 migrations are already loaded in the database.
UpdateContacts1566560354098 is the last executed migration. It was executed on Fri Aug 23 2019 13:39:14 GMT+0200 (Central European Summer Time).
Now reverting it...
Migration UpdateContacts1566560354098 has been reverted successfully.
After running revert:
> db.migrations.find()
{ "_id" : ObjectId("5d7118c2bfc3a0f771f3ea4b"), "timestamp" : 1567689639607, "name" : "MergeConfigs1567689639607" }
Is this a known issue of some sort? Is there any flag or anything which I might be missing?
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
How to revert the last migration? - python - Stack Overflow
To reverse all migrations for an app, you can run: ... Solution: Write a Database router with method allow_migrate in order to differentiate...
Read more >Undo Migrations - Tutorial - Flyway
This brief tutorial will teach how to use undo migrations. It will take you through the steps on how to create and use...
Read more >What order does migrate:rollback execute? - Laracasts
The answer is, migrations rollback in the order they are created based on the date in the filename... which very well may be...
Read more >Why Reversible Migrations Are Important and How to Write ...
Yes, migrations are reversible! What does it mean? When you run a migration, it runs by a default the up method which is...
Read more >Rolling Back Migrations with Flyway - Baeldung
In our undo migration, notice how the filename-prefix is 'U' compared with the normal migration prefix of 'V'. Also, in our undo migration...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@DimaIT, I like option 1. We can add a comment to
getLatestExecutedMigration
with a precondition likeMigration array must be sorted by descending ID.
@RecuencoJones, thanks for clarification. Now your solution looks much more reasonable to me. I think it’s makes sense to add comment describing situation with mongo ids to your code.
That may work, but seems kind of tricky.
I have couple more ideas:
id
inloadExecutedMigrations
. ThangetLatestExecutedMigration
needs just peek the last one._id
in reverse order.getLatestExecutedMigration
will pick the first migration, wich will be the latest one. I think it’s the simpliest fix that can be made.