postgresqlflywaydatabase-versioningdatabase-management

How to Baseline an sql script so that it won't show in the pending migrations in flyway


I have an existing postgresql database. I am trying to apply version control tool like flyway. I am using desktop app community version 6.6.1.0. I am trying to create a baseline script from here. But it seems like it does not support in the community mode.

Although I run the flyway baseline command successfully but it does not generate any sql script file. To overcome from this problem I am trying to create a manual sql script from the existing database and tried to baseline the pending file. Although it ran successfully, but the file still shows in the pending migrations list. I don't want this file to show in the pending migrations file list. How can I do it?


Solution

  • Finally, I got a solution to my problem.

    After researching the documentation I got that the Baseline migrations are prefixed with B followed by the version of your database they represent. For example: B5__my_database.sql. So if I rename my SQL script like this and apply the baseline migrations into my existing database then it will be removed from my pending migrations list.

    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 ignored. More information here