'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:

  1. take dump/snapshot of a database you trust is in correct state (usually the production one)
  2. 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
  3. create a new fresh db with identical settings as your "final" db
  4. delete all your old migration files
  5. generate (run migration:generate script) a new migration
  6. 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.
  7. commit changes and prepare them for release
  8. 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)
  9. now you should be ready to move on with your life
  10. 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