'How to consolidate TypeORM migrations
At the moment I'm not a guru on TypeORM and have made a few mistakes with my migrations - with our non-production database now in a state where I'd like it, is it possible to consolidate the TypeORM migrations into a single file of "create table 1 ... (n)" and remove all the other migrations?
All documents I find tell me "how" to migrate, but I haven't seen anything on a "reset and make this the default"
Thanks
Solution 1:[1]
well basically what you want to do is following:
- take dump/snapshot of a database you trust is in correct state (usually the production one)
- run typeorm migration:generate agains it - this should not generate any new migration or your code is not in sync with your db - migrate and start over
- create a new fresh db with identical settings as your "final" db
- delete all your old migration files
- generate (run migration:generate script) a new migration
- run the migration against the empty db - if everything passes, nice, if not, you have a problem :) - either tweak your entities or change the migration or start over from 1.
- commit changes and prepare them for release
- wipe migration table in your target database(s) and manually insert new record for your new migration (you can copy one from the empty db you just migrated)
- now you should be ready to move on with your life
- to test everything is ok just change some entity, generate migration for it and go trough the whole deployment to make sure everything works okay
we have done it in various startups in the past and you should not have any problems as far as you didn`t do any incompatible manual changes to your database schemas
do I need to add to backup everything before and after? :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Tomáš Strej?ek |