Skip to content

Commit eb0e4c3

Browse files
authored
refactor: consolidate Liquibase migrations into a single changeset per database (#50)
## Summary - Collapse okapi's incremental Liquibase changelogs into one `001__create_okapi_outbox_table.sql` per database — PostgreSQL 4 changesets → 1, MySQL 3 → 1. Each `changelog.xml` now includes only the consolidated file; the per-step migration files are removed. - Net schema for a **new** installation is unchanged (same table, columns, both indexes); new users get the full schema from a single changeset instead of replaying the change history. - CHANGELOG documents the consolidation and that the `outbox:001` checksum changes — existing installations must start on a fresh okapi schema, or clear okapi's rows from `okapi_databasechangelog`, before upgrading. ## Test Plan - [x] `LiquibaseE2ETest` (PostgreSQL + MySQL Spring Boot autoconfig, real Liquibase on Testcontainers) — 8/8 passing - [x] Concurrency claim/purge integration tests (exercise the consolidated schema + indexes via real INSERT/claim) — 4/4 passing - [x] Full `./gradlew ktlintCheck` clean
1 parent d9aa3be commit eb0e4c3

10 files changed

Lines changed: 17 additions & 31 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ Until `1.0.0`, breaking changes may appear in any release and are flagged with *
1919
default `databasechangelog` / `databasechangeloglock`. Override the new defaults
2020
via configuration to keep the shared-table layout (see Added below).
2121
([#37](https://github.com/softwaremill/okapi/issues/37))
22+
- **okapi's Liquibase migrations consolidated into a single
23+
`001__create_okapi_outbox_table.sql` per database.** New installations create the
24+
full schema (table + indexes) from one changeset instead of replaying the change
25+
history; the resulting schema is unchanged. Existing installations from an earlier
26+
release: the `outbox:001` changeset checksum changed — they must start on a fresh
27+
okapi schema, or clear okapi's rows from `okapi_databasechangelog`, before upgrading.
2228

2329
### Added
2430

okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/001__create_outbox_table.sql renamed to okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/001__create_okapi_outbox_table.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ CREATE TABLE IF NOT EXISTS okapi_outbox
1515
last_error TEXT,
1616
delivery_metadata JSON NOT NULL
1717
);
18+
19+
CREATE INDEX idx_okapi_outbox_status_last_attempt ON okapi_outbox (status, last_attempt);
20+
21+
CREATE INDEX idx_okapi_outbox_status_created_at ON okapi_outbox (status, created_at);

‎okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/002__add_purger_index.sql‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/003__add_claim_index.sql‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/changelog.xml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
55
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
6-
<include file="001__create_outbox_table.sql" relativeToChangelogFile="true"/>
7-
<include file="002__add_purger_index.sql" relativeToChangelogFile="true"/>
8-
<include file="003__add_claim_index.sql" relativeToChangelogFile="true"/>
6+
<include file="001__create_okapi_outbox_table.sql" relativeToChangelogFile="true"/>
97
</databaseChangeLog>

okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/001__create_outbox_table.sql renamed to okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/001__create_okapi_outbox_table.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CREATE TABLE IF NOT EXISTS okapi_outbox
66
id UUID NOT NULL PRIMARY KEY,
77
message_type VARCHAR(255) NOT NULL,
88
payload TEXT NOT NULL,
9+
delivery_type VARCHAR(50) NOT NULL,
910
status VARCHAR(50) NOT NULL DEFAULT 'PENDING',
1011
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
1112
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -14,3 +15,7 @@ CREATE TABLE IF NOT EXISTS okapi_outbox
1415
last_error TEXT,
1516
delivery_metadata JSONB NOT NULL
1617
);
18+
19+
CREATE INDEX IF NOT EXISTS idx_okapi_outbox_status_last_attempt ON okapi_outbox (status, last_attempt);
20+
21+
CREATE INDEX IF NOT EXISTS idx_okapi_outbox_status_created_at ON okapi_outbox (status, created_at);

‎okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/002__add_delivery_type_column.sql‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/003__add_purger_index.sql‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/004__add_claim_index.sql‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/changelog.xml‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
55
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
6-
<include file="001__create_outbox_table.sql" relativeToChangelogFile="true"/>
7-
<include file="002__add_delivery_type_column.sql" relativeToChangelogFile="true"/>
8-
<include file="003__add_purger_index.sql" relativeToChangelogFile="true"/>
9-
<include file="004__add_claim_index.sql" relativeToChangelogFile="true"/>
6+
<include file="001__create_okapi_outbox_table.sql" relativeToChangelogFile="true"/>
107
</databaseChangeLog>

0 commit comments

Comments
 (0)