Don't run repeatable migrations first time
come_flyway_with_me
Posts: 3 New member
I'm just trying to set flyway up on an existing DB. I want to set all my existing functions and views as repeatable migrations, but I don't want flyway to run them the first time I run migrate, I just want their existing checksum to be added to the history table as though they have been run by flyway in the past.
I thought I would be able to use repair in some way but repair doesn't seem to be working the way I expected.
I have tried manually inserting a record into the flyway_schema_history table with a NULL checksum and then running repair. This did nothing repair didn't set the checksum at all.
I also tried creating the SQL file with a dummy statement like `SELECT 1;` in it, I then ran migrate which added a record to the schema history table, I then updated the SQL file with the function DDL and ran repair. The schema history table was not updated. I then ran migrate and it re-ran the updated repeatable migration and successfully created the function in the DB.
I'm running repair using the exact same options I'm using for migrate, but just changing the command from `migrate` to `repair`
Is repair the right way to go? Am I doing something wrong?
I thought I would be able to use repair in some way but repair doesn't seem to be working the way I expected.
I have tried manually inserting a record into the flyway_schema_history table with a NULL checksum and then running repair. This did nothing repair didn't set the checksum at all.
I also tried creating the SQL file with a dummy statement like `SELECT 1;` in it, I then ran migrate which added a record to the schema history table, I then updated the SQL file with the function DDL and ran repair. The schema history table was not updated. I then ran migrate and it re-ran the updated repeatable migration and successfully created the function in the DB.
I'm running repair using the exact same options I'm using for migrate, but just changing the command from `migrate` to `repair`
Is repair the right way to go? Am I doing something wrong?
Best Answer
-
Peter_Laws Posts: 289 Silver 2Thank you for coming to flyway with us, and also your question!
The path of least resistance would simply be to remove the repeatable migrations from the repo temporarily, run your migrations and then add them back. However, if you particularly want to populate your schema history table with them in the correct format you can use -skipExecutingMigrations="true"
I also ran a quick example for you here, no scripts were run but the schema_history table has been populated with the R script, marked as successful.
Answers
My apologies this wasn't incorporated into my first suggestion, you can use script-config-files on repeatable migrations too.
So continuing to use my 'R__cabbages.sql' script from earlier, if I add another file called 'R__cabbages.sql.conf', with the contents of 'shouldExecute=false' I can tell flyway to ignore it and it will continue to ignore it until I change that value to true, or delete the script config file.
I judge this a better solution as firstly you don't have to mess about with the file system, but also you can version control your choices if you so wish.