Reputation: 112
I'm currently learning nestjs. When I meet typeorm and it's script to generate migration, it create every table in one file. Now in my workplace, we use expressjs here, they create migrations file for every table. The structure will look more or less like below:
|- src
|- migrations
|- 20211003174831-user.js
|- 20211003175002-product.js
|- 20211003175307-invoice.js
|- 20211003175601-invoice-product.js
While I prefer nestjs approach, I was wondering which is the best approach in creating migrations file. If the better approach is the example above, what is the pros and it's cons. Any help will be appreciated, thank you.
Edit: Long story short, which one better is better for table migrations method, one file for every tables or multiple files for every table like the example above.
Upvotes: 0
Views: 457
Reputation: 3320
The best approach in creating migration files depends on your preferences.
However, a good practice to avoid bugs and time wasting is to create entities by generating the migrations files using typeorm migration:generate
as you did above but it can be complicated to read.
Creating the migrations manually using typeorm migration:create
using the TypeORM migration API is a good practice too but it takes a long time and could be a source of bugs, especially concerning the columns types.
Generating migrations is also useful when you need to alter a table or columns, you don't need to search the modifications on your own.
Finally, never use synchronize
in production.
Upvotes: 1