Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Leftover schema definitions in Postgres after Liquibase migration #5

Open
romasch opened this issue Oct 15, 2018 · 2 comments
Open

Comments

@romasch
Copy link

romasch commented Oct 15, 2018

When running migrations with Liquibase, Postgres and multiple schemas, the database is not properly cleaned up after each run.

Reproduction steps:

  1. Set up example project with the following Liquibase databaseChangeLog.yml:
databaseChangeLog:
    - changeSet:
        id: 1
        author: test
        changes: [sql: {sql: "create schema test"}]
#    - changeSet:
#        id: 2
#        author: test
#        changes: [empty: {}]
  1. Run liquibase migration.
  2. Uncomment the second changeset and run again.
    => Change Set scripts/databaseChangeLog.yml::1::test failed. Error: ERROR: schema "test" already exists [Failed SQL: create schema test]

The problem is the statement liquibase.dropAll(), which only deletes the default (public) schema.

There are multiple solutions to this:

  1. Never reuse a container, instead create a new one every time (and delete it afterwards).
  2. Add plugin configuration options for schemas to be deleted in Liquibase.
  3. Never delete the database in an existing container, but instead add a task to delete the container from Gradle.

Personally I think the first solution is the easiest with least risk of future headache. There might be a slight performance impact, but since the plugin only runs when there are actual changes to the changelog this might not be such an issue.

@ayedo
Copy link
Owner

ayedo commented Oct 16, 2018

Thanks for you feedback, and your suggestions!

I will take some time, and try to incorporate support for schemas. If it proves too difficult, option nr. 1 seems the way to go.

@ayedo
Copy link
Owner

ayedo commented Oct 17, 2018

Follow up: I spent some time trying to implement the schema migrations. It seems to be trickier that just passing along another parameter to the Flyway, and Liquibase instances.. (see here.
I think I will implement forced container recreation as soon as I find the time to do so.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants