Replacing a table with a table from a different application

I have a Java application that initializes a database with the following schema

 https://github.com/steinarb/ukelonn/blob/master/ukelonn.db.liquibase/src/main/resources/db-changelog/db-changelog-1.0.0.xml#L20

Now I would like to replace the users table in that database with a users table created by a different application:

 https://github.com/steinarb/authservice/blob/82fef95fbc132e4662283b3f981e0fbc218560f4/authservice.db.liquibase/src/main/resources/db-changelog/db-changelog-1.0.0.xml#L7

And now I’m pondering how do accomplish this:

  1. Remove the users table from the original changeset (the changeset setting up the schema for the ukelonn application)?
  • This will work for setting up a brand new ukelonn database
  • This will fail for existing ukelonn databases, because the changeset's checksum doesn't match the one in the changelog of the database
  • Have a conditional remove-if-exists for the users table (like I already have added to the start of the authservice changelog file)?
    • This works for existing ukelonn databases
    • This works for new ukelonn databases if the ukelonn changeset is run first (and I don't think I can arrange that)
    • This fails in a new database if the authservice database liquibase runs before the ukelonn database, because then ukelonn schema creation changeset will break because a users table already exists in the database (and making the users table creation conditional will change the changeset checksum and break existing ukelonn databases in the same way removing the table will)
    Thoughts?

    Lessons learned: 

    • don't make the initial schema creation a single big changeset
    • make all table creations conditional
    (Or maybe that's too much work for the rare edge case of replacing a table with a table belonging to a different application.... and in any case it's too late for this particular application...:-) )

     

    As for the lessons learned… I can’t do anything about the old schema, but at least I can do something about the new schema:

     https://github.com/steinarb/authservice/blob/21c790bcfb5dd10ac2b73960a786438c132060fd/authservice.db.liquibase/src/main/resources/db-changelog/db-changelog-1.0.0.xml#L6

    (and I have an idea for merging the old and new schemas. I’ll be back on this thread with more detail if it works out)

    Ouch. Yeah, it was a bit painful to read that first ‘lessons learned’ comment. Yes, changelogs should be very granular, with many changesets. We generally recommend that there is only one actual change per changeset. 

    Steve Donie
    Principal Software Engineer
    Datical, Inc. http://www.datical.com/