Over the lifetime of a project, many database objects may be created and destroyed across many migrations which leaves behind a lengthy history of migrations that need to be applied in order to bring a new environment up to speed.
Instead, you might wish to add a single, cumulative migration that represents the state of your database after all of those migrations have been applied without disrupting existing environments.
Flyway Teams Edition gives you a way to achieve this using Baseline Migrations.
Baseline migrations are prefixed with
B followed by the version of your database they represent. For example:
B5__my_database.sql represents the state of your database after applying all versioned migrations up to and including
Baseline migrations are only used when deploying to new environments. If used in an environment where some Flyway migrations have already been applied, baseline migrations will be ignored. New environments will choose the latest baseline migration as the starting point when you run
migrate. Every migration with a version below the latest baseline migration’s version is marked as
baselinecommand and are executed during the
This mechanism is fully automated and requires no modification in your pipeline to begin using. Simply add your baseline migrations when you need them and they will be utilized.
B prefix is configurable with the baselineMigrationPrefix parameter.
Baseline migrations were formally known as State Scripts. These can be used as baseline migrations without modification, by either changing the prefix of your state scripts to be
B or setting the value of the baselineMigrationPrefix parameter to
Click here to see a tutorial on using baseline migrations.