1

What will happen when we did not add precondition in a changeset and run it twice? Will it be marked ran by default? For example, this is changeset:

<changeSet id="xxx" author="kurkesh">

    <createProcedure>DO $$ BEGIN
        CREATE TYPE enum_mobile AS ENUM('ANDROID', 'IOS', 'WINDOWS');
        EXCEPTION
        WHEN duplicate_object THEN null;
        END $$;
    </createProcedure>
</changeset>
veljkost
  • 1,748
  • 21
  • 25

1 Answers1

1

Yes, your changeSet will be marked as EXECUTED, and will not be executed again.


When you execute your changeSet for the first time, Liquibase makes a note in the databasechangelog table that changeSet with id "xxx" has run successfully.

When you try to execute this exact changeSet for the second time, Liquibase will check the databasechangelog table. And if there's a record about changeSet "xxx" (that it was executed successfully) then this changeSet will be ignored, and it won't be executed the second time.

But it's not a good idea to ignore preConditions. Someday, someone will write another changeSet that will do basically the same, and you app will fail, because you can't create the same enum twice.

For more information about how Liquibase stores the data about already executed changeSets check out this question.

htshame
  • 6,599
  • 5
  • 36
  • 56