2

I am working on a project with multiple schema in postgresql. When i run mvn flyway:clean, it cleans only the public schema and not other schema.

I came across another solution where we have to listing the schema by ourself in mvn flyway plugin configurations. Even after listing, it doesn't drop the schema, it drops only the table.

Is it another way to do it? I don't like declaring the schema in the configuration.

Saravanan
  • 515
  • 3
  • 14
  • 1
    You don't _declare_ the schemas in the plugin configuration - you only _list_ the schemas that you want to clean. – mystarrocks Jan 05 '15 at 16:55
  • Yea, i only listing in the plugin configuration. – Saravanan Jan 05 '15 at 16:56
  • There's no other way - the [clean](http://flywaydb.org/documentation/maven/clean.html) goal requires you to specify the schemas that you want to clean. If you don't mention the list yourself, it will only pick the default schema of the connection. – mystarrocks Jan 05 '15 at 17:04
  • And when dealing with multiple schemas, you have to prefix the object names accordingly. Only the first one in the list is set as the default one for the connection. See the answer [here](http://stackoverflow.com/a/14282362/934307) to see if it helps. – mystarrocks Jan 05 '15 at 17:06
  • Even in that case, it don't drop the schema. it drops only the table. when i run the migration again, it fails saying "xxx schema already exits" – Saravanan Jan 05 '15 at 17:07

2 Answers2

1

Had the same issue and resolved little bit in a different way - made migration with schema creation idempotent.

How do I query if a database schema exists

Hope this will help.

kikaxa
  • 89
  • 6
1

As said in the comments, flyway never do a DROP on a schema. The clean only wipes out what is IN the schemas

How to avoid the "xxx schema already exists" ?

You simply need to write CREATE SCHEMA IF NOT EXISTS xxx; in your migration SQL file (IF NOT EXISTS being the key) in order to create the schemas you need without issues

John
  • 376
  • 2
  • 9