Reputation: 848
I have a a strange question to ask. I started working on a project and I need to integrate flyway to make it execute any new migrations on application start-up. The flyway dependency and config exists, pointing at a batch of migration scripts, but these were previously executed against the target 'by hand' without flyway having been used. The prod database full of user data. I can not tell you why it was organised like this.
What I want to do is to integrate flyway to make it check that migration folder and to add a command to the pipeline. And I have a concern that if I don't configure flyway properly will it execute all those migrations from the beginning on start-up? (this can corrupt existing data) Or it will it only execute newly added migrations?
Upvotes: 1
Views: 2747
Reputation: 5899
Flyway will by default try to execute all migrations that haven't been logged as run in the flyway_schema_history table.
But... there is a flyway baseline feature which instructs Flyway to ignore any migrations that have a version equal to or lower than a specified version.
So assuming the "already run migrations" are given an earlier version number (which is baked into the filename), and you ensure that you set a baselineVersion to be a number that is above these run migrations, then you should be good to go.
Upvotes: 2
Reputation: 7521
You can launch application against clean test database, Flyway will run all migrations and save the records to flyway_schema_history
table. Then you manually create flyway_schema_history
on prod database, populate it with records taken from test table. When you launch prod application, Flyway will scan flyway_schema_history
table and consider that all migrations are already executed, and will not run your scripts so data will not be corrupted.
Upvotes: 2