Skip to content
Advertisement

Liquibase bidirectional relationships changelog order

I’ve faced a problem when implementing liquibase in an existing project. So we have two entities:

Company:

JavaScript

Stock:

JavaScript

And my liquibase changelogs.

Company:

JavaScript

Stock:

JavaScript

And master:

JavaScript

I have this exception:

JavaScript

I understand that liquibase trying to create stock and then add company_id as foreign key although there is no company table yet. I have a bunch of bidirectional relationships and this one is only part of them.

Question: How can I organize liquibase changeLogs to create all tables and relationships between them in one build? Should I create something like “db.changelogs.relations” where I will set up foreign keys?

UPD: Closed. Generate your changeLogs with maven plugin for liquibase

Advertisement

Answer

Creating Answer out of my Comments on the Question:

It looks you are writing your change log xml manually. If you arrange your change log to put table creation at first and the FKs then it would be fine.

  • Create Table1, Table2, Table3
  • Setup relation between Table1 and Table2, Table2 an Table3

Better option is to use liquibase plugin (for your maven/gradle) to generate such change logs. Liquibase would generate the change logs for tables first and then the FKs so that you don’t need to worry about this.

See these as an reference:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement