Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flyway 5.0.7 warning about using schema_version table

We use the Flyway Gradle plugin to do our migrations offline (i.e. we migrate while the system is down). We recently upgraded to Flyway 5.0.7 and we see this warning now for migrations:

Could not find schema history table XXXXXXX.flyway_schema_history, but found XXXXXXX.schema_version instead. You are seeing this message because Flyway changed its default for flyway.table in version 5.0.0 to flyway_schema_history and you are still relying on the old default (schema_version). Set flyway.table=schema_version in your configuration to fix this. This fallback mechanism will be removed in Flyway 6.0.0.

(I've used the XXXXXXX to obscure the actual schema name).

So, it appears that we can avoid the error by setting flyway.table=schema_version. But, it also says this mechanism will be removed in Flyway 6.0.0.

Are we supposed to do something to make this compatible going forward? Do we have to manually rename the schema_version table to flyway_schema_history? Or is there a way to make Flyway do it? If not, what is going to happen when Flyway 6.0.0 comes out? Will it automatically migrate the data to the appropriate table name?

like image 553
Tony C. Avatar asked Mar 02 '18 05:03

Tony C.


People also ask

What is Flyway table?

Flyway uses a schema history table to track the version of each database, recording in it every versioned migration file applied to build that version. It's worth understanding exactly how Flyway uses this table, the possible dangers of moving it to a non-default location and how to do it safely, if required.

Is Flyway still used?

Why use Flyway? Flyway is used by 300,000 active users, from single developers to large IT teams in major companies. We can say we're the world's most popular open source migrations framework for database deployments.

How does Flyway connect to database?

In order to connect with your database, Flyway needs the appropriate JDBC driver to be available in its drivers directory. To see if Flyway ships with the JDBC driver for your database, visit the Driver section of the documentation page for your database. For example, here is the Oracle Drivers section.


2 Answers

The default for flyway.table has been changed from schema_version to flyway_schema_history. And they have also provided automatic fallback to old default with a warning to avoid breaking existing installations using the old default.

It means from flyway 5, If you do not specify flyway.table property inside your configuration file, then flyway will look for the table flyway_schema_history in db, and if not found it will look for the table schema_version as a fallback and if the old table is found then will warn with the message that you are getting now. From flyway 6, this fallback mechanism will be removed. If you do not provide flyway.table property, it will look for flyway_schema_history in db, if not found it will not look for schema_version table even if you have any and will create a new table named flyway_schema_history to maintain functionality.

In flyway 6, your existing system will run fine if you set flyway.table=schema_version, you do not need to change table name in db. But if you do not set the property, then you must have to change the table name, otherwise flyway will not recognize existing schema_version table, will treat the system as a new one, will create flyway_schema_history table and will start executing scripts from start.

Hoping it will help.

like image 114
Monzurul Shimul Avatar answered Sep 30 '22 00:09

Monzurul Shimul


On PostgreSQL I have solved it with just one migration on top:

DO $$   BEGIN     IF (EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'schema_version')         AND EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'flyway_schema_history'))     THEN         DROP TABLE schema_version;     END IF ;     IF (EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'schema_version')         AND NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'flyway_schema_history'))     THEN         CREATE TABLE flyway_schema_history AS TABLE schema_version;     END IF ;   END $$ ; 

It works actually in 2 stages:

  • On first reboot it copies history with migration recorded into 'old' history table.
  • On second reboot it drops old history table. Now migration goes into 'new' history and everything is finished.
like image 45
Roman Nikitchenko Avatar answered Sep 29 '22 22:09

Roman Nikitchenko