From 7e93d2f9e38945c171c92c3e7e81d87d1994ca87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Kobyli=C5=84ski?= Date: Tue, 19 May 2026 17:05:00 +0200 Subject: [PATCH 1/3] refactor(postgres): consolidate Liquibase migrations into single changeset --- ...utbox_table.sql => 001__create_okapi_outbox_table.sql} | 5 +++++ .../okapi/db/postgres/002__add_delivery_type_column.sql | 8 -------- .../okapi/db/postgres/003__add_purger_index.sql | 4 ---- .../okapi/db/postgres/004__add_claim_index.sql | 4 ---- .../com/softwaremill/okapi/db/postgres/changelog.xml | 5 +---- 5 files changed, 6 insertions(+), 20 deletions(-) rename okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/{001__create_outbox_table.sql => 001__create_okapi_outbox_table.sql} (70%) delete mode 100644 okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/002__add_delivery_type_column.sql delete mode 100644 okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/003__add_purger_index.sql delete mode 100644 okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/004__add_claim_index.sql diff --git a/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/001__create_outbox_table.sql b/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/001__create_okapi_outbox_table.sql similarity index 70% rename from okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/001__create_outbox_table.sql rename to okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/001__create_okapi_outbox_table.sql index 466e065..58fc1bc 100644 --- a/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/001__create_outbox_table.sql +++ b/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/001__create_okapi_outbox_table.sql @@ -6,6 +6,7 @@ CREATE TABLE IF NOT EXISTS okapi_outbox id UUID NOT NULL PRIMARY KEY, message_type VARCHAR(255) NOT NULL, payload TEXT NOT NULL, + delivery_type VARCHAR(50) NOT NULL, status VARCHAR(50) NOT NULL DEFAULT 'PENDING', created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, @@ -14,3 +15,7 @@ CREATE TABLE IF NOT EXISTS okapi_outbox last_error TEXT, delivery_metadata JSONB NOT NULL ); + +CREATE INDEX IF NOT EXISTS idx_okapi_outbox_status_last_attempt ON okapi_outbox (status, last_attempt); + +CREATE INDEX IF NOT EXISTS idx_okapi_outbox_status_created_at ON okapi_outbox (status, created_at); diff --git a/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/002__add_delivery_type_column.sql b/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/002__add_delivery_type_column.sql deleted file mode 100644 index e75c2e1..0000000 --- a/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/002__add_delivery_type_column.sql +++ /dev/null @@ -1,8 +0,0 @@ ---liquibase formatted sql ---changeset outbox:002 - -ALTER TABLE okapi_outbox ADD COLUMN IF NOT EXISTS delivery_type VARCHAR(50); - -UPDATE okapi_outbox SET delivery_type = delivery_metadata->>'type' WHERE delivery_type IS NULL; - -ALTER TABLE okapi_outbox ALTER COLUMN delivery_type SET NOT NULL; diff --git a/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/003__add_purger_index.sql b/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/003__add_purger_index.sql deleted file mode 100644 index 2fe114a..0000000 --- a/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/003__add_purger_index.sql +++ /dev/null @@ -1,4 +0,0 @@ ---liquibase formatted sql ---changeset outbox:003 - -CREATE INDEX idx_okapi_outbox_status_last_attempt ON okapi_outbox(status, last_attempt); diff --git a/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/004__add_claim_index.sql b/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/004__add_claim_index.sql deleted file mode 100644 index 154e846..0000000 --- a/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/004__add_claim_index.sql +++ /dev/null @@ -1,4 +0,0 @@ ---liquibase formatted sql ---changeset outbox:004 - -CREATE INDEX IF NOT EXISTS idx_okapi_outbox_status_created_at ON okapi_outbox (status, created_at); diff --git a/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/changelog.xml b/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/changelog.xml index 4ccc4e9..390f883 100644 --- a/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/changelog.xml +++ b/okapi-postgres/src/main/resources/com/softwaremill/okapi/db/postgres/changelog.xml @@ -3,8 +3,5 @@ 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-latest.xsd"> - - - - + From ebb4d4387069f75c8db8c944c18e60255e7cd795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Kobyli=C5=84ski?= Date: Tue, 19 May 2026 17:08:59 +0200 Subject: [PATCH 2/3] refactor(mysql): consolidate Liquibase migrations into single changeset --- ...te_outbox_table.sql => 001__create_okapi_outbox_table.sql} | 4 ++++ .../com/softwaremill/okapi/db/mysql/002__add_purger_index.sql | 4 ---- .../com/softwaremill/okapi/db/mysql/003__add_claim_index.sql | 4 ---- .../resources/com/softwaremill/okapi/db/mysql/changelog.xml | 4 +--- 4 files changed, 5 insertions(+), 11 deletions(-) rename okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/{001__create_outbox_table.sql => 001__create_okapi_outbox_table.sql} (78%) delete mode 100644 okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/002__add_purger_index.sql delete mode 100644 okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/003__add_claim_index.sql diff --git a/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/001__create_outbox_table.sql b/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/001__create_okapi_outbox_table.sql similarity index 78% rename from okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/001__create_outbox_table.sql rename to okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/001__create_okapi_outbox_table.sql index b54bf2d..9b132e8 100644 --- a/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/001__create_outbox_table.sql +++ b/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/001__create_okapi_outbox_table.sql @@ -15,3 +15,7 @@ CREATE TABLE IF NOT EXISTS okapi_outbox last_error TEXT, delivery_metadata JSON NOT NULL ); + +CREATE INDEX idx_okapi_outbox_status_last_attempt ON okapi_outbox (status, last_attempt); + +CREATE INDEX idx_okapi_outbox_status_created_at ON okapi_outbox (status, created_at); diff --git a/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/002__add_purger_index.sql b/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/002__add_purger_index.sql deleted file mode 100644 index b53bf16..0000000 --- a/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/002__add_purger_index.sql +++ /dev/null @@ -1,4 +0,0 @@ ---liquibase formatted sql ---changeset outbox:002 - -CREATE INDEX idx_okapi_outbox_status_last_attempt ON okapi_outbox(status, last_attempt); diff --git a/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/003__add_claim_index.sql b/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/003__add_claim_index.sql deleted file mode 100644 index 4cffaea..0000000 --- a/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/003__add_claim_index.sql +++ /dev/null @@ -1,4 +0,0 @@ ---liquibase formatted sql ---changeset outbox:003 - -CREATE INDEX idx_okapi_outbox_status_created_at ON okapi_outbox (status, created_at); diff --git a/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/changelog.xml b/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/changelog.xml index 126d56b..390f883 100644 --- a/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/changelog.xml +++ b/okapi-mysql/src/main/resources/com/softwaremill/okapi/db/mysql/changelog.xml @@ -3,7 +3,5 @@ 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-latest.xsd"> - - - + From 4be3f1a2a2771382c914c43cec37bad97b3be6ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Kobyli=C5=84ski?= Date: Tue, 19 May 2026 17:12:07 +0200 Subject: [PATCH 3/3] docs: changelog for Liquibase migration consolidation --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a927bf2..93ef533 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,12 @@ Until `1.0.0`, breaking changes may appear in any release and are flagged with * default `databasechangelog` / `databasechangeloglock`. Override the new defaults via configuration to keep the shared-table layout (see Added below). ([#37](https://github.com/softwaremill/okapi/issues/37)) +- **okapi's Liquibase migrations consolidated into a single + `001__create_okapi_outbox_table.sql` per database.** New installations create the + full schema (table + indexes) from one changeset instead of replaying the change + history; the resulting schema is unchanged. Existing installations from an earlier + release: the `outbox:001` changeset checksum changed — they must start on a fresh + okapi schema, or clear okapi's rows from `okapi_databasechangelog`, before upgrading. ### Added