From f32e51159491f7648329dd5ad5a4f7673b0e5236 Mon Sep 17 00:00:00 2001 From: AndyChen Date: Sat, 2 Sep 2023 00:12:57 +0800 Subject: [PATCH] fix MigratorSpec #710 --- .../test/resources/schema/h2/h2-create-schema.sql | 10 ++++++---- .../resources/schema/mysql/mysql-create-schema.sql | 12 +++++++----- .../resources/schema/oracle/oracle-create-schema.sql | 8 +++++--- .../schema/postgres/postgres-create-schema.sql | 8 +++++--- .../schema/sqlserver/sqlserver-create-schema.sql | 8 +++++--- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/migrator/src/test/resources/schema/h2/h2-create-schema.sql b/migrator/src/test/resources/schema/h2/h2-create-schema.sql index ca44e8762..53af94e9e 100644 --- a/migrator/src/test/resources/schema/h2/h2-create-schema.sql +++ b/migrator/src/test/resources/schema/h2/h2-create-schema.sql @@ -18,12 +18,14 @@ CREATE TABLE IF NOT EXISTS "event_journal" ( CREATE UNIQUE INDEX "event_journal_ordering_idx" on "event_journal" ("ordering"); CREATE TABLE IF NOT EXISTS "event_tag" ( - "event_id" BIGINT NOT NULL, + "event_id" BIGINT, + "persistence_id" VARCHAR(255), + "sequence_number" BIGINT, "tag" VARCHAR NOT NULL, - PRIMARY KEY("event_id", "tag"), + PRIMARY KEY("persistence_id", "sequence_number", "tag"), CONSTRAINT fk_event_journal - FOREIGN KEY("event_id") - REFERENCES "event_journal"("ordering") + FOREIGN KEY("persistence_id", "sequence_number") + REFERENCES "event_journal"("persistence_id", "sequence_number") ON DELETE CASCADE ); diff --git a/migrator/src/test/resources/schema/mysql/mysql-create-schema.sql b/migrator/src/test/resources/schema/mysql/mysql-create-schema.sql index 5c57be277..b8d07fe75 100644 --- a/migrator/src/test/resources/schema/mysql/mysql-create-schema.sql +++ b/migrator/src/test/resources/schema/mysql/mysql-create-schema.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS event_journal( +CREATE TABLE IF NOT EXISTS event_journal ( ordering SERIAL, deleted BOOLEAN DEFAULT false NOT NULL, persistence_id VARCHAR(255) NOT NULL, @@ -17,11 +17,13 @@ CREATE TABLE IF NOT EXISTS event_journal( CREATE UNIQUE INDEX event_journal_ordering_idx ON event_journal(ordering); CREATE TABLE IF NOT EXISTS event_tag ( - event_id BIGINT UNSIGNED NOT NULL, + event_id BIGINT UNSIGNED, + persistence_id VARCHAR(255), + sequence_number BIGINT, tag VARCHAR(255) NOT NULL, - PRIMARY KEY(event_id, tag), - FOREIGN KEY (event_id) - REFERENCES event_journal(ordering) + PRIMARY KEY(persistence_id, sequence_number, tag), + FOREIGN KEY (persistence_id, sequence_number) + REFERENCES event_journal(persistence_id, sequence_number) ON DELETE CASCADE ); diff --git a/migrator/src/test/resources/schema/oracle/oracle-create-schema.sql b/migrator/src/test/resources/schema/oracle/oracle-create-schema.sql index dde92755f..4fde76632 100644 --- a/migrator/src/test/resources/schema/oracle/oracle-create-schema.sql +++ b/migrator/src/test/resources/schema/oracle/oracle-create-schema.sql @@ -23,10 +23,12 @@ CREATE OR REPLACE TRIGGER EVENT_JOURNAL__ORDERING_TRG before insert on EVENT_JOU / CREATE TABLE EVENT_TAG ( - EVENT_ID NUMERIC NOT NULL, + EVENT_ID NUMERIC, + PERSISTENCE_ID VARCHAR(255), + SEQUENCE_NUMBER NUMERIC, TAG VARCHAR(255) NOT NULL, - PRIMARY KEY(EVENT_ID, TAG), - FOREIGN KEY(EVENT_ID) REFERENCES EVENT_JOURNAL(ORDERING) + PRIMARY KEY(PERSISTENCE_ID, SEQUENCE_NUMBER, TAG), + FOREIGN KEY(PERSISTENCE_ID, SEQUENCE_NUMBER) REFERENCES EVENT_JOURNAL(PERSISTENCE_ID, SEQUENCE_NUMBER) ON DELETE CASCADE ) / diff --git a/migrator/src/test/resources/schema/postgres/postgres-create-schema.sql b/migrator/src/test/resources/schema/postgres/postgres-create-schema.sql index 7ae7e0999..190dc9668 100644 --- a/migrator/src/test/resources/schema/postgres/postgres-create-schema.sql +++ b/migrator/src/test/resources/schema/postgres/postgres-create-schema.sql @@ -23,11 +23,13 @@ CREATE UNIQUE INDEX event_journal_ordering_idx ON public.event_journal(ordering) CREATE TABLE IF NOT EXISTS public.event_tag( event_id BIGINT, + persistence_id VARCHAR(255), + sequence_number BIGINT, tag VARCHAR(256), - PRIMARY KEY(event_id, tag), + PRIMARY KEY(persistence_id, sequence_number, tag), CONSTRAINT fk_event_journal - FOREIGN KEY(event_id) - REFERENCES event_journal(ordering) + FOREIGN KEY(persistence_id, sequence_number) + REFERENCES event_journal(persistence_id, sequence_number) ON DELETE CASCADE ); diff --git a/migrator/src/test/resources/schema/sqlserver/sqlserver-create-schema.sql b/migrator/src/test/resources/schema/sqlserver/sqlserver-create-schema.sql index f4cf59f18..65f9f883c 100644 --- a/migrator/src/test/resources/schema/sqlserver/sqlserver-create-schema.sql +++ b/migrator/src/test/resources/schema/sqlserver/sqlserver-create-schema.sql @@ -18,9 +18,11 @@ CREATE TABLE event_journal( CREATE UNIQUE INDEX event_journal_ordering_idx ON event_journal(ordering); CREATE TABLE event_tag ( - "event_id" BIGINT NOT NULL, - "tag" VARCHAR(255) NOT NULL - PRIMARY KEY ("event_id","tag") + "event_id" BIGINT, + "persistence_id" VARCHAR(255), + "sequence_number" NUMERIC(10,0), + "tag" VARCHAR(255) NOT NULL, + PRIMARY KEY ("event_id", "tag"), constraint "fk_event_journal" foreign key("event_id") references "dbo"."event_journal"("ordering")