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 fo
It is possible to migrate from schema_version to flyway_schema_history by mapping a table over the other and copying the relevant records:
DROP TABLE IF EXISTS `flyway_schema_history`;
SET character_set_client = utf8mb4 ;
CREATE TABLE `flyway_schema_history` (
`installed_rank` int(11) NOT NULL,
`version` varchar(50) DEFAULT NULL,
`description` varchar(200) NOT NULL,
`type` varchar(20) NOT NULL,
`script` varchar(1000) NOT NULL,
`checksum` int(11) DEFAULT NULL,
`installed_by` varchar(100) NOT NULL,
`installed_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`execution_time` int(11) NOT NULL,
`success` tinyint(1) NOT NULL,
PRIMARY KEY (`installed_rank`),
KEY `flyway_schema_history_s_idx` (`success`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
insert into flyway_schema_history (installed_rank, version, description, type, script, checksum, installed_by, installed_on, execution_time, success)
select installed_rank, version, description, type, script, checksum, installed_by, installed_on, execution_time, success
from schema_version;
This is the schema version of flyway_schema_history as of flyway 5.2.2. I recommend, to use this script safely, to migrate before to this version and then move forward.
Please, understand that this script must be executed as it is in your db console. This script is for MySQL only. You have to craft your own for other databases.
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.
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: