Home > Software engineering >  When to execute database migration?
When to execute database migration?

Time:06-18

New to database migration. Assuming I have:

  1. A new and empty database
  2. A new server with migration files that never being executed

Now, I start my server and new tables will be created because the server executed the migration operations. My questions are:

  1. Should the migration operations be executed again if the server is turned off and on?
  2. If there is no new migration files being added to the server, there shouldn't be any changes to the existing database, correct? From what I have tested, the database does not have anything done to it if there is no new migration files being added to the server.

CodePudding user response:

Your initial database creation scripts should be idempotent. They should be able to execute in an if not exists create table fashion.

If your codebase defining the application changes at all, the framework you use to autogenerate your migration files should pick up on that and generate the deltas for you.

  • Related