Please see the content first: DB first (using PostgreSQL) in .NET 5
We knowed that our program's release path is from DEV to QAS to PRD.
1. Create new objects in your DB of DEV, and export all sql scripts into a file.
for exapmle: I have exported a file as below, it called 20211215.sql .
2. Copy the file into your source code project, it will be under the 'Migrations' folder, the file name must be start with 'yyyyMMDDHHmmss', why are we do? Becase there are many times release in our project, we need to keep order to execute program migration. Set a property of CopyToOutputDirectory for the file, it will be copied to output directory when the program depolyed.
3. We have a method to run migrations. In order to execute DB migration automatically, we will create a table like code first to record all migrations. Read all files from 'Migrations' folder, and check the file if it was migrated, it's false, it will be done one by one.
4. Source code: CodeAndDbFirst