Tuesday, 28 July 2020

Best way to run migrations on new NOT NULL columns with TypeORM?

I use TypeORM with Postgres in my NestJS project. I disabled the synchronisation mode and use Typeorm to generate migrations and then perform them. However, sometimes, I need to add a new column into my entity which has the NOT NULL property. When this happens, I cannot migrate my DB with already has some data due to NOT NULL constraint of the new column. I have to wipe my DB clean first, then do the migration.How can I perform my migrations in a fancier manner? Especially when this needs to be deployed to a production server with real data in the DB.Thanks!tl;dr:how do I migrate and seed data at the same time to prevent NOT NULL constraints?

Submitted July 28, 2020 at 10:57AM by recycled_bin

No comments:

Post a Comment