Replacing a table with a table from a different application

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

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

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)

    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:

    (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.