fix(migrations): add version column for JPA optimistic locking

DictionaryDefinition and DictionaryRecord entities have @Version (BIGINT)
fields for optimistic locking, but the initial migrations did not create
the column. App fails with 'column dd1_0.version does not exist' on first
query.

Add 0007-add-version-columns.xml with idempotent addColumn changesets
(preConditions guard against re-add).
This commit is contained in:
Александр Зимин
2026-05-03 20:38:43 +03:00
parent 1c4e8e5be2
commit 0cabd81abf
2 changed files with 37 additions and 0 deletions
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd">
<changeSet id="0007-1-add-version-to-dictionary-definitions" author="ordinis">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="dictionary_definitions" columnName="version"/>
</not>
</preConditions>
<comment>Add @Version column for JPA optimistic locking on dictionary_definitions</comment>
<addColumn tableName="dictionary_definitions">
<column name="version" type="BIGINT" defaultValueNumeric="0">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
<changeSet id="0007-2-add-version-to-dictionary-records" author="ordinis">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="dictionary_records" columnName="version"/>
</not>
</preConditions>
<comment>Add @Version column for JPA optimistic locking on dictionary_records</comment>
<addColumn tableName="dictionary_records">
<column name="version" type="BIGINT" defaultValueNumeric="0">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>
@@ -11,5 +11,6 @@
<include file="changes/0004-audit-log.xml"/>
<include file="changes/0005-outbox-events.xml"/>
<include file="changes/0006-idempotency-keys.xml"/>
<include file="changes/0007-add-version-columns.xml"/>
</databaseChangeLog>