Question: Is it possible to create a new DB in a migration script and then connect to it? How?
My Scenario: I\'m trying to use flyw
Here is a workaround that worked for me (assuming the use of the Maven plugin):
Configure the plugin with two executions. The first execution creates the database. The second execution migrates an existing database.
org.flywaydb
flyway-maven-plugin
${flyway.version}
create-db
migrate
org.postgresql.Driver
jdbc:postgresql://database-server/
postgres
password
MyDatabase
com/foo/bar/database/create
migrate-db
migrate
org.postgresql.Driver
jdbc:postgresql://database-server/MyDatabase
postgres
password
com/foo/bar/database/migrate
org.postgresql
postgresql
${postgresql.version}
Then add V1__Created_database.sql to the com/foo/bar/database/create directory. This file contains:
CREATE DATABASE ${DATABASE.NAME}