Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flyway:init doesn't create schema database

I'm using flyway to manage a multi-schema database in mysql and I've configured flyway using Maven. I have listed a database called 'metadata' as the first in the <schemas> tag so flyway will put the schema_version table here. When I run mvn flyway:migrate I'm expecting this table and the metadata database to be created. Flyway 2.1.1 tries to create the table, but does not create the database first so it fails.

[DEBUG] Schemas: metadata,temp,OTHER_DBS_REDACTED
[DEBUG] Schema `temp` already exists. Skipping schema creation.
[DEBUG] Database: MySQL 5.6  
[ERROR] com.googlecode.flyway.core.api.FlywayException: Error setting current sc
hema to `metadata`
[ERROR] Caused by com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unk
nown database 'metadata'

I thought mvn flyway:init might create the schemas, but that fails with a different but obviously related error.

[INFO] --- flyway-maven-plugin:2.1.1:init (default-cli) @ database ---
[INFO] Creating Metadata table: `metadata`.`schema_version`
[ERROR] com.googlecode.flyway.core.api.FlywayException: Error executing statement at line 17: CREATE TABLE `metadata`.`schema_version` (
    `version_rank` INT NOT NULL,
    `installed_rank` INT NOT NULL,
    `version` VARCHAR(50) NOT NULL,
    `description` VARCHAR(200) NOT NULL,
    `type` VARCHAR(20) NOT NULL,
    `script` VARCHAR(1000) NOT NULL,
    `checksum` INT,
    `installed_by` VARCHAR(100) NOT NULL,
    `installed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `execution_time` INT NOT NULL,
    `success` BOOL NOT NULL
) ENGINE=InnoDB
[ERROR] Caused by com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'metadata'

If I create database metadata then things proceed smoothly. I'm quite enjoying flyway in fact. Short of running some sql manually, is there a way to make flyway create this database? Is this simply a bug?

TIA

like image 431
user2300902 Avatar asked Oct 05 '22 08:10

user2300902


1 Answers

Right now the create schema support is an all or nothing thing. If all schemas are missing, they all will be created, otherwise none will be created.

like image 123
Axel Fontaine Avatar answered Oct 13 '22 11:10

Axel Fontaine