From 04d2a20945629d3293eccafbc43b66716b3a7935 Mon Sep 17 00:00:00 2001 From: Roland Praml Date: Mon, 21 Mar 2022 13:48:48 +0100 Subject: [PATCH] Add testcase, that uses all kinds of reserved keywords --- .../dbmigration/DbMigrationTest.java | 34 ++++++- .../test/java/misc/migration/v1_0/ETable.java | 90 +++++++++++++++++++ .../test/java/misc/migration/v1_1/ETable.java | 49 ++++++++++ .../test/java/misc/migration/v1_2/ETable.java | 55 ++++++++++++ .../dbmigration/clickhouse/1.0__initial.sql | 8 ++ .../dbmigration/clickhouse/1.1.sql | 2 + .../clickhouse/idx_clickhouse.migrations | 4 +- .../dbmigration/cockroach/1.0__initial.sql | 15 ++++ .../dbmigration/cockroach/1.1.sql | 2 + .../cockroach/idx_cockroach.migrations | 4 +- .../dbmigration/db2fori/1.0__initial.sql | 22 +++++ .../migrationtest/dbmigration/db2fori/1.1.sql | 6 ++ .../migrationtest/dbmigration/db2fori/1.3.sql | 1 + .../dbmigration/db2fori/idx_db2.migrations | 6 +- .../dbmigration/db2legacy/1.0__initial.sql | 22 +++++ .../dbmigration/db2legacy/1.1.sql | 6 ++ .../dbmigration/db2legacy/1.3.sql | 1 + .../dbmigration/db2legacy/idx_db2.migrations | 6 +- .../dbmigration/db2luw/1.0__initial.sql | 22 +++++ .../migrationtest/dbmigration/db2luw/1.1.sql | 6 ++ .../migrationtest/dbmigration/db2luw/1.3.sql | 1 + .../dbmigration/db2luw/idx_db2.migrations | 6 +- .../dbmigration/db2zos/1.0__initial.sql | 22 +++++ .../migrationtest/dbmigration/db2zos/1.1.sql | 6 ++ .../migrationtest/dbmigration/db2zos/1.3.sql | 1 + .../dbmigration/db2zos/idx_db2.migrations | 6 +- .../dbmigration/generic/1.0__initial.sql | 16 ++++ .../migrationtest/dbmigration/generic/1.1.sql | 3 + .../migrationtest/dbmigration/generic/1.3.sql | 1 + .../generic/idx_generic.migrations | 6 +- .../dbmigration/h2/1.0__initial.sql | 30 +++++++ .../migrationtest/dbmigration/h2/1.1.sql | 8 ++ .../migrationtest/dbmigration/h2/1.3.sql | 1 + .../dbmigration/h2/idx_h2.migrations | 6 +- .../dbmigration/hana/1.0__initial.sql | 31 +++++++ .../migrationtest/dbmigration/hana/1.1.sql | 6 ++ .../migrationtest/dbmigration/hana/1.3.sql | 1 + .../dbmigration/hana/idx_hana.migrations | 6 +- .../dbmigration/hsqldb/1.0__initial.sql | 16 ++++ .../migrationtest/dbmigration/hsqldb/1.1.sql | 3 + .../migrationtest/dbmigration/hsqldb/1.3.sql | 1 + .../dbmigration/hsqldb/idx_hsqldb.migrations | 6 +- .../mariadb-noprocs/1.0__initial.sql | 16 ++++ .../dbmigration/mariadb-noprocs/1.1.sql | 2 + .../mariadb-noprocs/idx_mariadb.migrations | 4 +- .../dbmigration/mariadb/1.0__initial.sql | 16 ++++ .../migrationtest/dbmigration/mariadb/1.1.sql | 2 + .../mariadb/idx_mariadb.migrations | 4 +- .../dbmigration/model/1.0__initial.model.xml | 10 +++ .../dbmigration/model/1.1.model.xml | 5 ++ .../dbmigration/model/1.3.model.xml | 1 + .../dbmigration/mysql/1.0__initial.sql | 39 ++++++++ .../migrationtest/dbmigration/mysql/1.1.sql | 18 ++++ .../dbmigration/mysql/idx_mysql.migrations | 4 +- .../dbmigration/mysql55/1.0__initial.sql | 39 ++++++++ .../migrationtest/dbmigration/mysql55/1.1.sql | 18 ++++ .../dbmigration/mysql55/idx_mysql.migrations | 4 +- .../dbmigration/nuodb/1.0__initial.sql | 41 +++++++++ .../migrationtest/dbmigration/nuodb/1.1.sql | 20 +++++ .../dbmigration/nuodb/idx_nuodb.migrations | 4 +- .../dbmigration/oracle/1.0__initial.sql | 16 ++++ .../migrationtest/dbmigration/oracle/1.1.sql | 3 + .../migrationtest/dbmigration/oracle/1.3.sql | 1 + .../dbmigration/oracle/idx_oracle.migrations | 6 +- .../dbmigration/oracle11/1.0__initial.sql | 16 ++++ .../dbmigration/oracle11/1.1.sql | 3 + .../dbmigration/oracle11/1.3.sql | 1 + .../oracle11/idx_oracle.migrations | 6 +- .../dbmigration/postgres/1.0__initial.sql | 42 +++++++++ .../dbmigration/postgres/1.1.sql | 31 +++++++ .../dbmigration/postgres/1.3.sql | 1 + .../postgres/idx_postgres.migrations | 6 +- .../dbmigration/postgres9/1.0__initial.sql | 42 +++++++++ .../dbmigration/postgres9/1.1.sql | 31 +++++++ .../dbmigration/postgres9/1.3.sql | 1 + .../postgres9/idx_postgres.migrations | 6 +- .../dbmigration/sqlanywhere/1.0__initial.sql | 16 ++++ .../dbmigration/sqlanywhere/1.1.sql | 3 + .../dbmigration/sqlanywhere/1.3.sql | 1 + .../sqlanywhere/idx_sqlanywhere.migrations | 6 +- .../dbmigration/sqlite/1.0__initial.sql | 13 +++ .../migrationtest/dbmigration/sqlite/1.1.sql | 2 + .../dbmigration/sqlite/idx_sqlite.migrations | 4 +- .../dbmigration/sqlserver16/1.0__initial.sql | 20 +++++ .../dbmigration/sqlserver16/1.1.sql | 5 ++ .../sqlserver16/idx_sqlserver.migrations | 4 +- .../dbmigration/sqlserver17/1.0__initial.sql | 20 +++++ .../dbmigration/sqlserver17/1.1.sql | 5 ++ .../sqlserver17/idx_sqlserver.migrations | 4 +- .../dbmigration/yugabyte/1.0__initial.sql | 49 ++++++++++ .../dbmigration/yugabyte/1.1.sql | 31 +++++++ .../dbmigration/yugabyte/1.3.sql | 1 + .../yugabyte/idx_yugabyte.migrations | 6 +- 93 files changed, 1129 insertions(+), 64 deletions(-) create mode 100644 ebean-test/src/test/java/misc/migration/v1_0/ETable.java create mode 100644 ebean-test/src/test/java/misc/migration/v1_1/ETable.java create mode 100644 ebean-test/src/test/java/misc/migration/v1_2/ETable.java diff --git a/ebean-test/src/test/java/io/ebeaninternal/dbmigration/DbMigrationTest.java b/ebean-test/src/test/java/io/ebeaninternal/dbmigration/DbMigrationTest.java index df309a65a..a7461173e 100644 --- a/ebean-test/src/test/java/io/ebeaninternal/dbmigration/DbMigrationTest.java +++ b/ebean-test/src/test/java/io/ebeaninternal/dbmigration/DbMigrationTest.java @@ -6,6 +6,7 @@ import io.ebean.annotation.Platform; import io.ebean.config.DatabaseConfig; import io.ebean.config.dbplatform.DbHistorySupport; import io.ebean.datasource.pool.ConnectionPool; +import misc.migration.v1_0.ETable; import misc.migration.v1_1.EHistory; import misc.migration.v1_1.EHistory2; import org.junit.jupiter.api.Test; @@ -84,7 +85,10 @@ public class DbMigrationTest extends BaseTestCase { "migtest_mtm_c_migtest_mtm_m", "migtest_mtm_m_migtest_mtm_c", "migtest_oto_child", - "migtest_oto_master"); + "migtest_oto_master", + "table", + "\"table\"", + "`table`"); ((ConnectionPool)server().dataSource()).offline(); ((ConnectionPool)server().dataSource()).online(); @@ -113,7 +117,7 @@ public class DbMigrationTest extends BaseTestCase { assertThat(server().execute(update)).isEqualTo(2); } - + testReservedKeywords(); createHistoryEntities(); if (isOracle()) { // Oracle does not like to convert varchar to integer @@ -258,6 +262,32 @@ public class DbMigrationTest extends BaseTestCase { } } + // do some history tests with V1.1 models + private void testReservedKeywords() { + DatabaseConfig config = new DatabaseConfig(); + config.setName(server().name()); + config.loadFromProperties(server().pluginApi().config().getProperties()); + config.setDataSource(server().dataSource()); + config.setReadOnlyDataSource(server().dataSource()); + config.setDdlGenerate(false); + config.setDdlRun(false); + config.setRegister(false); + config.setPackages(Collections.singletonList("misc.migration.v1_0")); + + Database tmpServer = DatabaseFactory.create(config); + try { + ETable table = new misc.migration.v1_0.ETable(); + table.setFrom("foo"); + table.setTo("bar"); + table.setIndex("id"); + tmpServer.save(table); + table = tmpServer.find(ETable.class).where().eq("index", "id").findOne(); + assert table != null; + } finally { + tmpServer.shutdown(false, false); + } + } + private void createHistoryEntities() { SqlUpdate update = server().sqlUpdate("insert into migtest_e_history (id, test_string) values (1, '42')"); assertThat(server().execute(update)).isEqualTo(1); diff --git a/ebean-test/src/test/java/misc/migration/v1_0/ETable.java b/ebean-test/src/test/java/misc/migration/v1_0/ETable.java new file mode 100644 index 000000000..7dfd5948e --- /dev/null +++ b/ebean-test/src/test/java/misc/migration/v1_0/ETable.java @@ -0,0 +1,90 @@ +package misc.migration.v1_0; + +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +import io.ebean.annotation.DbComment; +import io.ebean.annotation.History; +import io.ebean.annotation.Index; + +@Table(name = "`table`") +@Entity +@History +public class ETable { + + @Column(name = "`index`") + @DbComment("this is a comment") + @Id + private String index; + + @Column(name = "`from`") + @Index + private String from; + + @Column(name = "`to`") + @Index(unique = true) + private String to; + + @Column(name = "`varchar`") + @Index(unique = true) + private String varchar; + + @ManyToOne + @JoinColumn(name = "`foreign`") + ETable foreign; + + @OneToMany(mappedBy = "foreign") + List foreigns; + + public String getIndex() { + return index; + } + + public void setIndex(String index) { + this.index = index; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getTo() { + return to; + } + + public void setTo(String to) { + this.to = to; + } + + public String getVarchar() { + return varchar; + } + + public void setVarchar(String varchar) { + this.varchar = varchar; + } + + public ETable getForeign() { + return foreign; + } + + public void setForeign(ETable foreign) { + this.foreign = foreign; + } + + public List getForeigns() { + return foreigns; + } + +} diff --git a/ebean-test/src/test/java/misc/migration/v1_1/ETable.java b/ebean-test/src/test/java/misc/migration/v1_1/ETable.java new file mode 100644 index 000000000..cbca4b4b2 --- /dev/null +++ b/ebean-test/src/test/java/misc/migration/v1_1/ETable.java @@ -0,0 +1,49 @@ +package misc.migration.v1_1; + +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +import io.ebean.annotation.DbComment; +import io.ebean.annotation.History; +import io.ebean.annotation.Index; + +@Table(name = "`table`") +@Entity +@History // FIXME: remove later +public class ETable { + + @Column(name = "`index`") + @DbComment("this is an other comment") + @Id + private String index; + + @Column(name = "`from`") + @Index + private String from; + + @Column(name = "`to`") + @Index(unique = true) + private String to; + + @Column(name = "`varchar`") + @Index(unique = true) + private String varchar; + + @Column(name = "`select`") + @Index(unique = true) + private String select; + + @ManyToOne + @JoinColumn(name = "`foreign`") + ETable foreign; + + @OneToMany(mappedBy = "foreign") + List foreigns; +} diff --git a/ebean-test/src/test/java/misc/migration/v1_2/ETable.java b/ebean-test/src/test/java/misc/migration/v1_2/ETable.java new file mode 100644 index 000000000..4fff00ce3 --- /dev/null +++ b/ebean-test/src/test/java/misc/migration/v1_2/ETable.java @@ -0,0 +1,55 @@ +package misc.migration.v1_2; + +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +import io.ebean.annotation.DbComment; +import io.ebean.annotation.History; +import io.ebean.annotation.Index; + +@Table(name = "`table`") +@Entity +@History +public class ETable { + + @Column(name = "`index`") + @DbComment("this is a comment") + @Id + private String index; + + @Column(name = "`from`") + @Index + private String from; + + @Column(name = "`to`") + @Index(unique = true) + private String to; + + @Column(name = "`varchar`") + @Index(unique = true) + private String varchar; + + // Note: This column should be removed, (as it is also not present in V1.0) + // There is a limitation in history generation, that you cannot enable history while you have pending drops + // History-table will be generyted in V1.3 - SQL without that column, while base table still contains that column + // When creating the "with_history" view, the DB complains, because the tables do not match. + // In V1.4 the column will be dropped in base table AND history table. + // This could be probably fixed, by generating history table also with dropped columns + @Column(name = "`select`") + @Index(unique = true) + private String select; + + @ManyToOne + @JoinColumn(name = "`foreign`") + ETable foreign; + + @OneToMany(mappedBy = "foreign") + List foreigns; +} diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/clickhouse/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/clickhouse/1.0__initial.sql index 399008e81..976eaa3cd 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/clickhouse/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/clickhouse/1.0__initial.sql @@ -115,6 +115,14 @@ create table migtest_e_softdelete ( test_string String ) ENGINE = Log(); +create table "table" ( + "index" String, + "from" String, + "to" String, + "varchar" String, + "foreign" String +) ENGINE = Log(); + create table migtest_mtm_c ( id UInt32, name String diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/clickhouse/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/clickhouse/1.1.sql index 8031d4b61..d2d1e7044 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/clickhouse/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/clickhouse/1.1.sql @@ -38,6 +38,7 @@ update migtest_e_history2 set test_string = 'unknown' where test_string is null; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; -- apply alter tables +alter table "table" add column "select" String; alter table migtest_ckey_detail add column one_key UInt32; alter table migtest_ckey_detail add column two_key String; alter table migtest_ckey_parent add column assoc_id UInt32; @@ -78,3 +79,4 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_status_indextest1 alter table migtest_e_basic add constraint uq_migtest_e_basic_name unique (name); alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique (indextest4); alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5); +alter table "table" add constraint uq_table_select unique ("select"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/clickhouse/idx_clickhouse.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/clickhouse/idx_clickhouse.migrations index e9f16f1b3..e6e04dafd 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/clickhouse/idx_clickhouse.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/clickhouse/idx_clickhouse.migrations @@ -1,5 +1,5 @@ --1091512932, 1.0__initial.sql -308282323, 1.1.sql +863321871, 1.0__initial.sql +1903846331, 1.1.sql 1279151426, 1.2__dropsFor_1.1.sql 1630693278, 1.3.sql 80209848, 1.4__dropsFor_1.3.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/1.0__initial.sql index 23cb015c1..faa10a8c2 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/1.0__initial.sql @@ -140,6 +140,17 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint uq_table_to unique ("to"), + constraint uq_table_varchar unique ("varchar"), + constraint pk_table primary key ("index") +); + create table migtest_mtm_c ( id integer generated by default as identity not null, name varchar(255), @@ -174,5 +185,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict; + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/1.1.sql index 01d009c38..785bcda3a 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/1.1.sql @@ -45,6 +45,7 @@ update migtest_e_history2 set test_string = 'unknown' where test_string is null; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -85,6 +86,7 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_status_indextest1 alter table migtest_e_basic add constraint uq_migtest_e_basic_name unique (name); alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique (indextest4); alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5); +alter table "table" add constraint uq_table_select unique ("select"); -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/idx_cockroach.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/idx_cockroach.migrations index 24af9d68d..69de34b1f 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/idx_cockroach.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/idx_cockroach.migrations @@ -1,5 +1,5 @@ -150261101, 1.0__initial.sql --968104039, 1.1.sql +1636200128, 1.0__initial.sql +356413151, 1.1.sql 240919209, 1.2__dropsFor_1.1.sql -430000356, 1.3.sql -820814009, 1.4__dropsFor_1.3.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.0__initial.sql index b20611369..a64383897 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.0__initial.sql @@ -137,6 +137,16 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create table migtest_mtm_c ( id integer generated by default as identity not null, name varchar(255), @@ -162,6 +172,10 @@ create table migtest_oto_master ( ); -- apply alter tables +alter table "table" add column sys_period_start timestamp(12) not null generated always as row begin; +alter table "table" add column sys_period_end timestamp(12) not null generated always as row end; +alter table "table" add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table "table" add period system_time (sys_period_start,sys_period_end); alter table migtest_e_history2 add column sys_period_start timestamp(12) not null generated always as row begin; alter table migtest_e_history2 add column sys_period_end timestamp(12) not null generated always as row end; alter table migtest_e_history2 add column sys_period_txn timestamp(12) generated always as transaction start id; @@ -196,6 +210,10 @@ alter table migtest_e_history5 add versioning use history table migtest_e_histor create table migtest_e_history6_history as (select * from migtest_e_history6) with no data; alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; alter table migtest_e_ref add constraint uq_migtest_e_ref_name unique (name); +create unique index uq_table_to on "table"("to") exclude null keys; +create unique index uq_table_varchar on "table"("varchar") exclude null keys; +create table table_history as (select * from "table") with no data; +alter table "table" add versioning use history table table_history; -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; @@ -206,5 +224,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict; + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.1.sql index cbe873d8b..1cc7b4b1d 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.1.sql @@ -118,7 +118,9 @@ alter table migtest_e_history5 drop versioning; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; alter table migtest_e_history6 drop versioning; +alter table "table" drop versioning; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -168,6 +170,7 @@ alter table migtest_e_history6_history alter column test_number2 drop not null; call sysproc.admin_cmd('reorg table migtest_e_history6_history'); alter table migtest_e_softdelete add column deleted smallint default 0 default false not null; alter table migtest_oto_child add column master_id bigint; +alter table table_history add column "select" varchar(255); -- apply post alter alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?')); create unique index uq_migtest_e_basic_description on migtest_e_basic(description) exclude null keys; @@ -188,6 +191,9 @@ alter table migtest_e_history3 add versioning use history table migtest_e_histor alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; +comment on column "table"."index" is 'this is an other comment'; +alter table "table" add versioning use history table table_history; +create unique index uq_table_select on "table"("select") exclude null keys; -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.3.sql index d8778ad59..2fcd77858 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/1.3.sql @@ -217,6 +217,7 @@ alter table migtest_e_history2 add versioning use history table migtest_e_histor alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/idx_db2.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/idx_db2.migrations index c4967d055..69a27f3a5 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/idx_db2.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/idx_db2.migrations @@ -1,7 +1,7 @@ -1907884988, 1.0__initial.sql --2103050574, 1.1.sql +-1073246286, 1.0__initial.sql +2043476851, 1.1.sql 364066694, 1.2__dropsFor_1.1.sql --144532085, 1.3.sql +1155358918, 1.3.sql -1199420632, 1.4__dropsFor_1.3.sql 561281075, R__order_views.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.0__initial.sql index 029e6b2b8..578d7cdff 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.0__initial.sql @@ -137,6 +137,16 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create table migtest_mtm_c ( id integer generated by default as identity not null, name varchar(255), @@ -162,6 +172,10 @@ create table migtest_oto_master ( ); -- apply alter tables +alter table "table" add column sys_period_start timestamp(12) not null generated always as row begin; +alter table "table" add column sys_period_end timestamp(12) not null generated always as row end; +alter table "table" add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table "table" add period system_time (sys_period_start,sys_period_end); alter table migtest_e_history2 add column sys_period_start timestamp(12) not null generated always as row begin; alter table migtest_e_history2 add column sys_period_end timestamp(12) not null generated always as row end; alter table migtest_e_history2 add column sys_period_txn timestamp(12) generated always as transaction start id; @@ -196,6 +210,10 @@ alter table migtest_e_history5 add versioning use history table migtest_e_histor create table migtest_e_history6_history as (select * from migtest_e_history6) with no data; alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; alter table migtest_e_ref add constraint uq_mgtst__rf_nm unique (name); +create unique index uq_table_to on "table"("to") exclude null keys; +create unique index uq_table_varchar on "table"("varchar") exclude null keys; +create table table_history as (select * from "table") with no data; +alter table "table" add versioning use history table table_history; -- foreign keys and indices create index ix_mgtst_fk_mok1xj on migtest_fk_cascade (one_id); alter table migtest_fk_cascade add constraint fk_mgtst_fk_65kf6l foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; @@ -206,5 +224,9 @@ alter table migtest_fk_set_null add constraint fk_mgtst_fk_wicx8x foreign key (o create index ix_mgtst__bsc_rf_d on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_mgtst__bsc_rf_d foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict; + create index ix_mgtst__b_eu8csq on migtest_e_basic (indextest1); create index ix_mgtst__b_eu8csu on migtest_e_basic (indextest5); +create index ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.1.sql index f173fb6cc..21013eea0 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.1.sql @@ -118,7 +118,9 @@ alter table migtest_e_history5 drop versioning; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; alter table migtest_e_history6 drop versioning; +alter table "table" drop versioning; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -168,6 +170,7 @@ alter table migtest_e_history6_history alter column test_number2 drop not null; call sysproc.admin_cmd('reorg table migtest_e_history6_history'); alter table migtest_e_softdelete add column deleted boolean default false not null; alter table migtest_oto_child add column master_id bigint; +alter table table_history add column "select" varchar(255); -- apply post alter alter table migtest_e_basic add constraint ck_mgtst__bsc_stts check ( status in ('N','A','I','?')); create unique index uq_mgtst__b_vs45xo on migtest_e_basic(description) exclude null keys; @@ -188,6 +191,9 @@ alter table migtest_e_history3 add versioning use history table migtest_e_histor alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; +comment on column "table"."index" is 'this is an other comment'; +alter table "table" add versioning use history table table_history; +create unique index uq_table_select on "table"("select") exclude null keys; -- foreign keys and indices create index ix_mgtst_mt_3ug4ok on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_mgtst_mt_93awga foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.3.sql index d69577404..358d219a8 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/1.3.sql @@ -217,6 +217,7 @@ alter table migtest_e_history2 add versioning use history table migtest_e_histor alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_mgtst_fk_65kf6l foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; alter table migtest_fk_set_null add constraint fk_mgtst_fk_wicx8x foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/idx_db2.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/idx_db2.migrations index b45072284..880eb4bf6 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/idx_db2.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/idx_db2.migrations @@ -1,7 +1,7 @@ --1510441716, 1.0__initial.sql --318724769, 1.1.sql +2054922533, 1.0__initial.sql +1256892738, 1.1.sql 364066694, 1.2__dropsFor_1.1.sql -1221811961, 1.3.sql +1760988648, 1.3.sql -1199420632, 1.4__dropsFor_1.3.sql 561281075, R__order_views.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.0__initial.sql index 8e2a6ff17..c2235d9c9 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.0__initial.sql @@ -137,6 +137,16 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create table migtest_mtm_c ( id integer generated by default as identity not null, name varchar(255), @@ -162,6 +172,10 @@ create table migtest_oto_master ( ); -- apply alter tables +alter table "table" add column sys_period_start timestamp(12) not null generated always as row begin; +alter table "table" add column sys_period_end timestamp(12) not null generated always as row end; +alter table "table" add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table "table" add period system_time (sys_period_start,sys_period_end); alter table migtest_e_history2 add column sys_period_start timestamp(12) not null generated always as row begin; alter table migtest_e_history2 add column sys_period_end timestamp(12) not null generated always as row end; alter table migtest_e_history2 add column sys_period_txn timestamp(12) generated always as transaction start id; @@ -196,6 +210,10 @@ alter table migtest_e_history5 add versioning use history table migtest_e_histor create table migtest_e_history6_history as (select * from migtest_e_history6) with no data; alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; alter table migtest_e_ref add constraint uq_migtest_e_ref_name unique (name); +create unique index uq_table_to on "table"("to") exclude null keys; +create unique index uq_table_varchar on "table"("varchar") exclude null keys; +create table table_history as (select * from "table") with no data; +alter table "table" add versioning use history table table_history; -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; @@ -206,5 +224,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict; + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.1.sql index a3967a721..2fb812410 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.1.sql @@ -118,7 +118,9 @@ alter table migtest_e_history5 drop versioning; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; alter table migtest_e_history6 drop versioning; +alter table "table" drop versioning; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -168,6 +170,7 @@ alter table migtest_e_history6_history alter column test_number2 drop not null; call sysproc.admin_cmd('reorg table migtest_e_history6_history'); alter table migtest_e_softdelete add column deleted boolean default false not null; alter table migtest_oto_child add column master_id bigint; +alter table table_history add column "select" varchar(255); -- apply post alter alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?')); create unique index uq_migtest_e_basic_description on migtest_e_basic(description) exclude null keys; @@ -188,6 +191,9 @@ alter table migtest_e_history3 add versioning use history table migtest_e_histor alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; +comment on column "table"."index" is 'this is an other comment'; +alter table "table" add versioning use history table table_history; +create unique index uq_table_select on "table"("select") exclude null keys; -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.3.sql index 5d90ff7af..9dbb719d6 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/1.3.sql @@ -217,6 +217,7 @@ alter table migtest_e_history2 add versioning use history table migtest_e_histor alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/idx_db2.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/idx_db2.migrations index 396c500c1..9d4b61aa7 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/idx_db2.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/idx_db2.migrations @@ -1,7 +1,7 @@ --1381050106, 1.0__initial.sql --960600780, 1.1.sql +-1519091511, 1.0__initial.sql +-370964456, 1.1.sql 364066694, 1.2__dropsFor_1.1.sql --688071658, 1.3.sql +591329540, 1.3.sql -1199420632, 1.4__dropsFor_1.3.sql 561281075, R__order_views.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.0__initial.sql index 8e2a6ff17..c2235d9c9 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.0__initial.sql @@ -137,6 +137,16 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create table migtest_mtm_c ( id integer generated by default as identity not null, name varchar(255), @@ -162,6 +172,10 @@ create table migtest_oto_master ( ); -- apply alter tables +alter table "table" add column sys_period_start timestamp(12) not null generated always as row begin; +alter table "table" add column sys_period_end timestamp(12) not null generated always as row end; +alter table "table" add column sys_period_txn timestamp(12) generated always as transaction start id; +alter table "table" add period system_time (sys_period_start,sys_period_end); alter table migtest_e_history2 add column sys_period_start timestamp(12) not null generated always as row begin; alter table migtest_e_history2 add column sys_period_end timestamp(12) not null generated always as row end; alter table migtest_e_history2 add column sys_period_txn timestamp(12) generated always as transaction start id; @@ -196,6 +210,10 @@ alter table migtest_e_history5 add versioning use history table migtest_e_histor create table migtest_e_history6_history as (select * from migtest_e_history6) with no data; alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; alter table migtest_e_ref add constraint uq_migtest_e_ref_name unique (name); +create unique index uq_table_to on "table"("to") exclude null keys; +create unique index uq_table_varchar on "table"("varchar") exclude null keys; +create table table_history as (select * from "table") with no data; +alter table "table" add versioning use history table table_history; -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; @@ -206,5 +224,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict; + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.1.sql index a3967a721..2fb812410 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.1.sql @@ -118,7 +118,9 @@ alter table migtest_e_history5 drop versioning; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; alter table migtest_e_history6 drop versioning; +alter table "table" drop versioning; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -168,6 +170,7 @@ alter table migtest_e_history6_history alter column test_number2 drop not null; call sysproc.admin_cmd('reorg table migtest_e_history6_history'); alter table migtest_e_softdelete add column deleted boolean default false not null; alter table migtest_oto_child add column master_id bigint; +alter table table_history add column "select" varchar(255); -- apply post alter alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?')); create unique index uq_migtest_e_basic_description on migtest_e_basic(description) exclude null keys; @@ -188,6 +191,9 @@ alter table migtest_e_history3 add versioning use history table migtest_e_histor alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; alter table migtest_e_history5 add versioning use history table migtest_e_history5_history; alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; +comment on column "table"."index" is 'this is an other comment'; +alter table "table" add versioning use history table table_history; +create unique index uq_table_select on "table"("select") exclude null keys; -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.3.sql index 5d90ff7af..9dbb719d6 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/1.3.sql @@ -217,6 +217,7 @@ alter table migtest_e_history2 add versioning use history table migtest_e_histor alter table migtest_e_history3 add versioning use history table migtest_e_history3_history; alter table migtest_e_history4 add versioning use history table migtest_e_history4_history; alter table migtest_e_history6 add versioning use history table migtest_e_history6_history; +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/idx_db2.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/idx_db2.migrations index 396c500c1..9d4b61aa7 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/idx_db2.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/idx_db2.migrations @@ -1,7 +1,7 @@ --1381050106, 1.0__initial.sql --960600780, 1.1.sql +-1519091511, 1.0__initial.sql +-370964456, 1.1.sql 364066694, 1.2__dropsFor_1.1.sql --688071658, 1.3.sql +591329540, 1.3.sql -1199420632, 1.4__dropsFor_1.3.sql 561281075, R__order_views.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/generic/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/generic/1.0__initial.sql index 262ebd5ff..0ac3d868a 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/generic/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/generic/1.0__initial.sql @@ -140,6 +140,18 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint uq_table_to unique ("to"), + constraint uq_table_varchar unique ("varchar"), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create table migtest_mtm_c ( id integer auto_increment not null, name varchar(255), @@ -174,5 +186,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict; + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/generic/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/generic/1.1.sql index 59709f02d..dc9bed0c0 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/generic/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/generic/1.1.sql @@ -45,6 +45,7 @@ update migtest_e_history2 set test_string = 'unknown' where test_string is null; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -87,6 +88,8 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5); comment on column migtest_e_history.test_string is 'Column altered to long now'; comment on table migtest_e_history is 'We have history now'; +comment on column "table"."index" is 'this is an other comment'; +alter table "table" add constraint uq_table_select unique ("select"); -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/generic/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/generic/1.3.sql index cb972294f..ec207d6a4 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/generic/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/generic/1.3.sql @@ -65,6 +65,7 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique alter table migtest_e_enum add constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')); comment on column migtest_e_history.test_string is ''; comment on table migtest_e_history is ''; +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/generic/idx_generic.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/generic/idx_generic.migrations index 24d932206..a6df69810 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/generic/idx_generic.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/generic/idx_generic.migrations @@ -1,6 +1,6 @@ -2034298647, 1.0__initial.sql -294462857, 1.1.sql +-1347475412, 1.0__initial.sql +2132717520, 1.1.sql 1279151426, 1.2__dropsFor_1.1.sql -465616489, 1.3.sql +-796269364, 1.3.sql 80209848, 1.4__dropsFor_1.3.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/h2/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/h2/1.0__initial.sql index 0bf405740..e3b222262 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/h2/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/h2/1.0__initial.sql @@ -140,6 +140,18 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint uq_table_to unique ("to"), + constraint uq_table_varchar unique ("varchar"), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create table migtest_mtm_c ( id integer generated by default as identity not null, name varchar(255), @@ -165,6 +177,8 @@ create table migtest_oto_master ( ); -- apply alter tables +alter table "table" add column sys_period_start timestamp default now(); +alter table "table" add column sys_period_end timestamp; alter table migtest_e_history2 add column sys_period_start timestamp default now(); alter table migtest_e_history2 add column sys_period_end timestamp; alter table migtest_e_history3 add column sys_period_start timestamp default now(); @@ -224,6 +238,18 @@ create table migtest_e_history6_history( create view migtest_e_history6_with_history as select * from migtest_e_history6 union all select * from migtest_e_history6_history; create trigger migtest_e_history6_history_upd before update,delete on migtest_e_history6 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger"; +create table table_history( + "index" varchar(255), + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + sys_period_start timestamp, + sys_period_end timestamp +); +create view table_with_history as select * from "table" union all select * from table_history; +create trigger table_history_upd before update,delete on "table" for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger"; + -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; @@ -234,5 +260,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict; + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/h2/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/h2/1.1.sql index 6b9679661..f34c6996f 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/h2/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/h2/1.1.sql @@ -54,7 +54,10 @@ drop view migtest_e_history5_with_history; update migtest_e_history6 set test_number1 = 42 where test_number1 is null; drop trigger migtest_e_history6_history_upd; drop view migtest_e_history6_with_history; +drop trigger table_history_upd; +drop view table_with_history; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -92,6 +95,7 @@ alter table migtest_e_history6 alter column test_number2 set null; alter table migtest_e_history6_history alter column test_number2 set null; alter table migtest_e_softdelete add column deleted boolean default false not null; alter table migtest_oto_child add column master_id bigint; +alter table table_history add column "select" varchar(255); -- apply post alter alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?')); alter table migtest_e_basic add constraint uq_migtest_e_basic_description unique (description); @@ -124,6 +128,10 @@ create view migtest_e_history5_with_history as select * from migtest_e_history5 create trigger migtest_e_history5_history_upd before update,delete on migtest_e_history5 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger"; create view migtest_e_history6_with_history as select * from migtest_e_history6 union all select * from migtest_e_history6_history; create trigger migtest_e_history6_history_upd before update,delete on migtest_e_history6 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger"; +comment on column "table"."index" is 'this is an other comment'; +create view table_with_history as select * from "table" union all select * from table_history; +create trigger table_history_upd before update,delete on "table" for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger"; +alter table "table" add constraint uq_table_select unique ("select"); -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/h2/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/h2/1.3.sql index e10ccf4e3..80d4f9aa0 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/h2/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/h2/1.3.sql @@ -86,6 +86,7 @@ create view migtest_e_history4_with_history as select * from migtest_e_history4 create trigger migtest_e_history4_history_upd before update,delete on migtest_e_history4 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger"; create view migtest_e_history6_with_history as select * from migtest_e_history6 union all select * from migtest_e_history6_history; create trigger migtest_e_history6_history_upd before update,delete on migtest_e_history6 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger"; +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/h2/idx_h2.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/h2/idx_h2.migrations index 9d9acbb8e..7a87fc386 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/h2/idx_h2.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/h2/idx_h2.migrations @@ -1,7 +1,7 @@ -2132375128, 1.0__initial.sql -393141788, 1.1.sql +-1179806373, 1.0__initial.sql +398205555, 1.1.sql -1366392410, 1.2__dropsFor_1.1.sql --1336073109, 1.3.sql +-523874424, 1.3.sql -1382108238, 1.4__dropsFor_1.3.sql 783227075, R__multi_comments.sql 561281075, R__order_views.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/hana/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/hana/1.0__initial.sql index 6c528f6ce..c0df03053 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/hana/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/hana/1.0__initial.sql @@ -140,6 +140,18 @@ create column table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create column table "table" ( + "index" nvarchar(255) not null, + "from" nvarchar(255), + "to" nvarchar(255), + "varchar" nvarchar(255), + "foreign" nvarchar(255), + constraint uq_table_to unique ("to"), + constraint uq_table_varchar unique ("varchar"), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create column table migtest_mtm_c ( id integer generated by default as identity not null, name nvarchar(255), @@ -229,6 +241,21 @@ alter table migtest_e_history6 add ( ); alter table migtest_e_history6 add period for system_time(sys_period_start,sys_period_end); alter table migtest_e_history6 add system versioning history table migtest_e_history6_history; +create column table table_history ( + "index" nvarchar(255), + "from" nvarchar(255), + "to" nvarchar(255), + "varchar" nvarchar(255), + "foreign" nvarchar(255), + sys_period_start timestamp, + sys_period_end timestamp +); +alter table "table" add ( + sys_period_start TIMESTAMP NOT NULL GENERATED ALWAYS AS ROW START, + sys_period_end TIMESTAMP NOT NULL GENERATED ALWAYS AS ROW END +); +alter table "table" add period for system_time(sys_period_start,sys_period_end); +alter table "table" add system versioning history table table_history; -- foreign keys and indices -- explicit index "ix_migtest_fk_cascade_one_id" for single column "one_id" of table "migtest_fk_cascade" is not necessary; alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; @@ -239,5 +266,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for -- explicit index "ix_migtest_e_basic_eref_id" for single column "eref_id" of table "migtest_e_basic" is not necessary; alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +-- explicit index "ix_table_foreign" for single column ""foreign"" of table ""table"" is not necessary; +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict; + -- explicit index "ix_migtest_e_basic_indextest1" for single column "indextest1" of table "migtest_e_basic" is not necessary; -- explicit index "ix_migtest_e_basic_indextest5" for single column "indextest5" of table "migtest_e_basic" is not necessary; +-- explicit index "ix_table_from" for single column ""from"" of table ""table"" is not necessary; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/hana/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/hana/1.1.sql index dd18de917..8de138abb 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/hana/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/hana/1.1.sql @@ -91,7 +91,9 @@ alter table migtest_e_history5 drop system versioning; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; alter table migtest_e_history6 drop system versioning; +alter table "table" drop system versioning; -- apply alter tables +alter table "table" add ("select" nvarchar(255)); alter table migtest_ckey_detail add (one_key integer, two_key nvarchar(127)); alter table migtest_ckey_parent add (assoc_id integer); @@ -121,6 +123,7 @@ alter table migtest_e_history6 alter (test_number1 integer default 42 not null, alter table migtest_e_history6_history alter (test_number2 integer); alter table migtest_e_softdelete add (deleted boolean default false not null); alter table migtest_oto_child add (master_id bigint); +alter table table_history add ("select" nvarchar(255)); -- apply post alter alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?')); -- cannot create unique index "uq_migtest_e_basic_description" on table "migtest_e_basic" with nullable columns; @@ -151,6 +154,9 @@ alter table migtest_e_history3 add system versioning history table migtest_e_his alter table migtest_e_history4 add system versioning history table migtest_e_history4_history not validated; alter table migtest_e_history5 add system versioning history table migtest_e_history5_history not validated; alter table migtest_e_history6 add system versioning history table migtest_e_history6_history not validated; +comment on column "table"."index" is 'this is an other comment'; +alter table "table" add system versioning history table table_history not validated; +-- cannot create unique index "uq_table_select" on table ""table"" with nullable columns; -- foreign keys and indices -- explicit index "ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c" for single column "migtest_mtm_c_id" of table "migtest_mtm_c_migtest_mtm_m" is not necessary; alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/hana/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/hana/1.3.sql index 43ea9ef1d..b44e90abe 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/hana/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/hana/1.3.sql @@ -132,6 +132,7 @@ alter table migtest_e_history2 add system versioning history table migtest_e_his alter table migtest_e_history3 add system versioning history table migtest_e_history3_history not validated; alter table migtest_e_history4 add system versioning history table migtest_e_history4_history not validated; alter table migtest_e_history6 add system versioning history table migtest_e_history6_history not validated; +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/hana/idx_hana.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/hana/idx_hana.migrations index 78e20a03f..b88d4fd3d 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/hana/idx_hana.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/hana/idx_hana.migrations @@ -1,8 +1,8 @@ -745347271, I__create_procs.sql --1191817607, 1.0__initial.sql -975653326, 1.1.sql +1934891896, 1.0__initial.sql +187688059, 1.1.sql 197547825, 1.2__dropsFor_1.1.sql --98538062, 1.3.sql +-1989736027, 1.3.sql 1812245353, 1.4__dropsFor_1.3.sql 1906063401, R__order_views_hana.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/1.0__initial.sql index e9edea850..47015f010 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/1.0__initial.sql @@ -140,6 +140,18 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint uq_table_to unique ("to"), + constraint uq_table_varchar unique ("varchar"), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create table migtest_mtm_c ( id integer generated by default as identity (start with 1) not null, name varchar(255), @@ -174,5 +186,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict; + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/1.1.sql index f5c26a888..04d1379e5 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/1.1.sql @@ -45,6 +45,7 @@ update migtest_e_history2 set test_string = 'unknown' where test_string is null; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -87,6 +88,8 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5); comment on column migtest_e_history.test_string is 'Column altered to long now'; comment on table migtest_e_history is 'We have history now'; +comment on column "table"."index" is 'this is an other comment'; +alter table "table" add constraint uq_table_select unique ("select"); -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/1.3.sql index a997ec73a..4658ed476 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/1.3.sql @@ -65,6 +65,7 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique alter table migtest_e_enum add constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')); comment on column migtest_e_history.test_string is ''; comment on table migtest_e_history is ''; +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/idx_hsqldb.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/idx_hsqldb.migrations index cb5d8ea27..8cd03776b 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/idx_hsqldb.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/hsqldb/idx_hsqldb.migrations @@ -1,7 +1,7 @@ -614593077, 1.0__initial.sql --788233032, 1.1.sql +-917796012, 1.0__initial.sql +-838725141, 1.1.sql -300925212, 1.2__dropsFor_1.1.sql -121126259, 1.3.sql +-1549893170, 1.3.sql -972999284, 1.4__dropsFor_1.3.sql 861001272, R__order_views_hsqldb.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb-noprocs/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb-noprocs/1.0__initial.sql index 9b0587dc3..871dfe2de 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb-noprocs/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb-noprocs/1.0__initial.sql @@ -137,6 +137,17 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table `table` ( + `index` varchar(255) not null comment 'this is a comment', + `from` varchar(255), + `to` varchar(255), + `varchar` varchar(255), + `foreign` varchar(255), + constraint uq_table_to unique (`to`), + constraint uq_table_varchar unique (`varchar`), + constraint pk_table primary key (`index`) +); + create table migtest_mtm_c ( id integer auto_increment not null, name varchar(255), @@ -162,6 +173,7 @@ create table migtest_oto_master ( ); -- apply alter tables +alter table `table` add system versioning; alter table migtest_e_history2 add system versioning; alter table migtest_e_history3 add system versioning; alter table migtest_e_history4 add system versioning; @@ -177,5 +189,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on `table` (`foreign`); +alter table `table` add constraint fk_table_foreign foreign key (`foreign`) references `table` (`index`) on delete restrict on update restrict; + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on `table` (`from`); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb-noprocs/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb-noprocs/1.1.sql index eb8551ab3..a47607fa6 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb-noprocs/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb-noprocs/1.1.sql @@ -43,6 +43,7 @@ SET @@system_versioning_alter_history = 1; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; -- apply alter tables +alter table `table` add column `select` varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -77,6 +78,7 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_name unique (name alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique (indextest4); alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5); alter table migtest_e_history comment = 'We have history now'; +alter table `table` add constraint uq_table_select unique (`select`); -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb-noprocs/idx_mariadb.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb-noprocs/idx_mariadb.migrations index 400a152ee..f94e6b123 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb-noprocs/idx_mariadb.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb-noprocs/idx_mariadb.migrations @@ -1,5 +1,5 @@ -1992643861, 1.0__initial.sql --1677772226, 1.1.sql +675320779, 1.0__initial.sql +840323734, 1.1.sql -828985759, 1.2__dropsFor_1.1.sql -1470028617, 1.3.sql -446860935, 1.4__dropsFor_1.3.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb/1.0__initial.sql index 9b0587dc3..871dfe2de 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb/1.0__initial.sql @@ -137,6 +137,17 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table `table` ( + `index` varchar(255) not null comment 'this is a comment', + `from` varchar(255), + `to` varchar(255), + `varchar` varchar(255), + `foreign` varchar(255), + constraint uq_table_to unique (`to`), + constraint uq_table_varchar unique (`varchar`), + constraint pk_table primary key (`index`) +); + create table migtest_mtm_c ( id integer auto_increment not null, name varchar(255), @@ -162,6 +173,7 @@ create table migtest_oto_master ( ); -- apply alter tables +alter table `table` add system versioning; alter table migtest_e_history2 add system versioning; alter table migtest_e_history3 add system versioning; alter table migtest_e_history4 add system versioning; @@ -177,5 +189,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on `table` (`foreign`); +alter table `table` add constraint fk_table_foreign foreign key (`foreign`) references `table` (`index`) on delete restrict on update restrict; + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on `table` (`from`); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb/1.1.sql index eb8551ab3..a47607fa6 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb/1.1.sql @@ -43,6 +43,7 @@ SET @@system_versioning_alter_history = 1; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; -- apply alter tables +alter table `table` add column `select` varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -77,6 +78,7 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_name unique (name alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique (indextest4); alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5); alter table migtest_e_history comment = 'We have history now'; +alter table `table` add constraint uq_table_select unique (`select`); -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb/idx_mariadb.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb/idx_mariadb.migrations index 1d88de14f..241588a15 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb/idx_mariadb.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mariadb/idx_mariadb.migrations @@ -1,6 +1,6 @@ 1835064798, I__create_procs.sql -1992643861, 1.0__initial.sql --1677772226, 1.1.sql +675320779, 1.0__initial.sql +840323734, 1.1.sql 2123392915, 1.2__dropsFor_1.1.sql -1470028617, 1.3.sql -692020559, 1.4__dropsFor_1.3.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.0__initial.model.xml b/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.0__initial.model.xml index 9ff836afb..001f3797f 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.0__initial.model.xml +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.0__initial.model.xml @@ -100,6 +100,15 @@ + + + + + + + + + @@ -118,6 +127,7 @@ + diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.1.model.xml b/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.1.model.xml index 157488bc3..410615793 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.1.model.xml +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.1.model.xml @@ -71,6 +71,11 @@ + + + + + diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.3.model.xml b/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.3.model.xml index 25c5fedb2..1c266ccae 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.3.model.xml +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/model/1.3.model.xml @@ -40,6 +40,7 @@ + diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.0__initial.sql index d7110e23e..1f9cffbb1 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.0__initial.sql @@ -137,6 +137,17 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table `table` ( + `index` varchar(255) not null comment 'this is a comment', + `from` varchar(255), + `to` varchar(255), + `varchar` varchar(255), + `foreign` varchar(255), + constraint uq_table_to unique (`to`), + constraint uq_table_varchar unique (`varchar`), + constraint pk_table primary key (`index`) +); + create table migtest_mtm_c ( id integer auto_increment not null, name varchar(255), @@ -162,6 +173,8 @@ create table migtest_oto_master ( ); -- apply alter tables +alter table `table` add column sys_period_start datetime(6) default now(6); +alter table `table` add column sys_period_end datetime(6); alter table migtest_e_history2 add column sys_period_start datetime(6) default now(6); alter table migtest_e_history2 add column sys_period_end datetime(6); alter table migtest_e_history3 add column sys_period_start datetime(6) default now(6); @@ -271,6 +284,28 @@ create trigger migtest_e_history6_history_del before delete on migtest_e_history end$$ unlock tables; +create table table_history( + "index" varchar(255), + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + sys_period_start datetime(6), + sys_period_end datetime(6) +); +create view table_with_history as select * from "table" union all select * from table_history; +lock tables "table" write; +delimiter $$ +create trigger table_history_upd before update on "table" for each row begin + insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "foreign") values (OLD.sys_period_start, now(6),OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign"); + set NEW.sys_period_start = now(6); +end$$ +delimiter $$ +create trigger table_history_del before delete on "table" for each row begin + insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "foreign") values (OLD.sys_period_start, now(6),OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign"); +end$$ +unlock tables; + -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; @@ -281,5 +316,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on `table` (`foreign`); +alter table `table` add constraint fk_table_foreign foreign key (`foreign`) references `table` (`index`) on delete restrict on update restrict; + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on `table` (`from`); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.1.sql index b006574e9..a310948ea 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.1.sql @@ -56,7 +56,11 @@ update migtest_e_history6 set test_number1 = 42 where test_number1 is null; drop trigger migtest_e_history6_history_upd; drop trigger migtest_e_history6_history_del; drop view migtest_e_history6_with_history; +drop trigger table_history_upd; +drop trigger table_history_del; +drop view table_with_history; -- apply alter tables +alter table `table` add column `select` varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -88,6 +92,7 @@ alter table migtest_e_history6 modify test_number2 integer; alter table migtest_e_history6_history modify test_number2 integer; alter table migtest_e_softdelete add column deleted tinyint(1) default 0 not null; alter table migtest_oto_child add column master_id bigint; +alter table table_history add column `select` varchar(255); -- apply post alter alter table migtest_e_basic add constraint uq_migtest_e_basic_description unique (description); -- NOTE: table has @History - special migration may be necessary @@ -177,6 +182,19 @@ create trigger migtest_e_history6_history_del before delete on migtest_e_history insert into migtest_e_history6_history (sys_period_start,sys_period_end,id, test_number1, test_number2) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_number1, OLD.test_number2); end$$ unlock tables; +create view table_with_history as select * from "table" union all select * from table_history; +lock tables "table" write; +delimiter $$ +create trigger table_history_upd before update on "table" for each row begin + insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "select", "foreign") values (OLD.sys_period_start, now(6),OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."select", OLD."foreign"); + set NEW.sys_period_start = now(6); +end$$ +delimiter $$ +create trigger table_history_del before delete on "table" for each row begin + insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "select", "foreign") values (OLD.sys_period_start, now(6),OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."select", OLD."foreign"); +end$$ +unlock tables; +alter table `table` add constraint uq_table_select unique (`select`); -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/idx_mysql.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/idx_mysql.migrations index 1cc1f5865..cd0db5cbe 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/idx_mysql.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/idx_mysql.migrations @@ -1,6 +1,6 @@ 1835064798, I__create_procs.sql -1531575623, 1.0__initial.sql -418413355, 1.1.sql +-2109016895, 1.0__initial.sql +-2062071756, 1.1.sql -1332434945, 1.2__dropsFor_1.1.sql -105506677, 1.3.sql 379252952, 1.4__dropsFor_1.3.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql55/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql55/1.0__initial.sql index f3da85ec0..6a76c8b5c 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql55/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql55/1.0__initial.sql @@ -137,6 +137,17 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table `table` ( + `index` varchar(255) not null comment 'this is a comment', + `from` varchar(255), + `to` varchar(255), + `varchar` varchar(255), + `foreign` varchar(255), + constraint uq_table_to unique (`to`), + constraint uq_table_varchar unique (`varchar`), + constraint pk_table primary key (`index`) +); + create table migtest_mtm_c ( id integer auto_increment not null, name varchar(255), @@ -162,6 +173,8 @@ create table migtest_oto_master ( ); -- apply alter tables +alter table `table` add column sys_period_start datetime(6) default now(6); +alter table `table` add column sys_period_end datetime(6); alter table migtest_e_history2 add column sys_period_start datetime(6) default now(6); alter table migtest_e_history2 add column sys_period_end datetime(6); alter table migtest_e_history3 add column sys_period_start datetime(6) default now(6); @@ -271,6 +284,28 @@ create trigger migtest_e_history6_history_del before delete on migtest_e_history end$$ unlock tables; +create table table_history( + "index" varchar(255), + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + sys_period_start datetime(6), + sys_period_end datetime(6) +); +create view table_with_history as select * from "table" union all select * from table_history; +lock tables "table" write; +delimiter $$ +create trigger table_history_upd before update on "table" for each row begin + insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "foreign") values (OLD.sys_period_start, now(6),OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign"); + set NEW.sys_period_start = now(6); +end$$ +delimiter $$ +create trigger table_history_del before delete on "table" for each row begin + insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "foreign") values (OLD.sys_period_start, now(6),OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign"); +end$$ +unlock tables; + -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; @@ -281,5 +316,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on `table` (`foreign`); +alter table `table` add constraint fk_table_foreign foreign key (`foreign`) references `table` (`index`) on delete restrict on update restrict; + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on `table` (`from`); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql55/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql55/1.1.sql index b006574e9..a310948ea 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql55/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql55/1.1.sql @@ -56,7 +56,11 @@ update migtest_e_history6 set test_number1 = 42 where test_number1 is null; drop trigger migtest_e_history6_history_upd; drop trigger migtest_e_history6_history_del; drop view migtest_e_history6_with_history; +drop trigger table_history_upd; +drop trigger table_history_del; +drop view table_with_history; -- apply alter tables +alter table `table` add column `select` varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -88,6 +92,7 @@ alter table migtest_e_history6 modify test_number2 integer; alter table migtest_e_history6_history modify test_number2 integer; alter table migtest_e_softdelete add column deleted tinyint(1) default 0 not null; alter table migtest_oto_child add column master_id bigint; +alter table table_history add column `select` varchar(255); -- apply post alter alter table migtest_e_basic add constraint uq_migtest_e_basic_description unique (description); -- NOTE: table has @History - special migration may be necessary @@ -177,6 +182,19 @@ create trigger migtest_e_history6_history_del before delete on migtest_e_history insert into migtest_e_history6_history (sys_period_start,sys_period_end,id, test_number1, test_number2) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_number1, OLD.test_number2); end$$ unlock tables; +create view table_with_history as select * from "table" union all select * from table_history; +lock tables "table" write; +delimiter $$ +create trigger table_history_upd before update on "table" for each row begin + insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "select", "foreign") values (OLD.sys_period_start, now(6),OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."select", OLD."foreign"); + set NEW.sys_period_start = now(6); +end$$ +delimiter $$ +create trigger table_history_del before delete on "table" for each row begin + insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "select", "foreign") values (OLD.sys_period_start, now(6),OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."select", OLD."foreign"); +end$$ +unlock tables; +alter table `table` add constraint uq_table_select unique (`select`); -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql55/idx_mysql.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql55/idx_mysql.migrations index 6c192bb8e..229084523 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql55/idx_mysql.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql55/idx_mysql.migrations @@ -1,6 +1,6 @@ 1835064798, I__create_procs.sql -1425786329, 1.0__initial.sql -418413355, 1.1.sql +-73920359, 1.0__initial.sql +-2062071756, 1.1.sql -1332434945, 1.2__dropsFor_1.1.sql -105506677, 1.3.sql 379252952, 1.4__dropsFor_1.3.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/nuodb/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/nuodb/1.0__initial.sql index 568e5bb21..b9c859753 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/nuodb/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/nuodb/1.0__initial.sql @@ -140,6 +140,17 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint uq_table_to unique ("to"), + constraint uq_table_varchar unique ("varchar"), + constraint pk_table primary key ("index") +); + create table migtest_mtm_c ( id integer generated by default as identity not null, name varchar(255), @@ -165,6 +176,8 @@ create table migtest_oto_master ( ); -- apply alter tables +alter table "table" add column sys_period_start datetime(6) default now(); +alter table "table" add column sys_period_end datetime(6); alter table migtest_e_history2 add column sys_period_start datetime(6) default now(); alter table migtest_e_history2 add column sys_period_end datetime(6); alter table migtest_e_history3 add column sys_period_start datetime(6) default now(); @@ -284,6 +297,30 @@ end_trigger; $$ +create table table_history( + "index" varchar(255), + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + sys_period_start datetime(6), + sys_period_end datetime(6) +); +create view table_with_history as select * from "table" union all select * from table_history; +delimiter $$ +create or replace trigger table_history_upd for "table" before update for each row as + NEW.sys_period_start = greatest(current_timestamp, date_add(OLD.sys_period_start, interval 1 microsecond)); + insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "foreign") values (OLD.sys_period_start, NEW.sys_period_start,OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign"); +end_trigger; +$$ + +delimiter $$ +create or replace trigger table_history_del for "table" before delete for each row as + insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "foreign") values (OLD.sys_period_start, NEW.sys_period_start,OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign"); +end_trigger; +$$ + + -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade; @@ -294,5 +331,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id); +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index"); + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/nuodb/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/nuodb/1.1.sql index b618a9587..7fff62c51 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/nuodb/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/nuodb/1.1.sql @@ -59,7 +59,11 @@ update migtest_e_history6 set test_number1 = 42 where test_number1 is null; drop trigger migtest_e_history6_history_upd; drop trigger migtest_e_history6_history_del; drop view migtest_e_history6_with_history; +drop trigger table_history_upd; +drop trigger table_history_del; +drop view table_with_history; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -97,6 +101,7 @@ alter table migtest_e_history6 alter column test_number2 set null; alter table migtest_e_history6_history alter column test_number2 set null; alter table migtest_e_softdelete add column deleted boolean default false not null; alter table migtest_oto_child add column master_id bigint; +alter table table_history add column "select" varchar(255); -- apply post alter alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?')); alter table migtest_e_basic add constraint uq_migtest_e_basic_description unique (description); @@ -199,6 +204,21 @@ create or replace trigger migtest_e_history6_history_del for migtest_e_history6 end_trigger; $$ +create view table_with_history as select * from "table" union all select * from table_history; +delimiter $$ +create or replace trigger table_history_upd for "table" before update for each row as + NEW.sys_period_start = greatest(current_timestamp, date_add(OLD.sys_period_start, interval 1 microsecond)); + insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "select", "foreign") values (OLD.sys_period_start, NEW.sys_period_start,OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."select", OLD."foreign"); +end_trigger; +$$ + +delimiter $$ +create or replace trigger table_history_del for "table" before delete for each row as + insert into table_history (sys_period_start,sys_period_end,"index", "from", "to", "varchar", "select", "foreign") values (OLD.sys_period_start, NEW.sys_period_start,OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."select", OLD."foreign"); +end_trigger; +$$ + +alter table "table" add constraint uq_table_select unique ("select"); -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/nuodb/idx_nuodb.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/nuodb/idx_nuodb.migrations index d3d0fd96b..51fdb15a3 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/nuodb/idx_nuodb.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/nuodb/idx_nuodb.migrations @@ -1,5 +1,5 @@ -1842042513, 1.0__initial.sql --1628340454, 1.1.sql +-357978944, 1.0__initial.sql +1244774121, 1.1.sql -424253630, 1.2__dropsFor_1.1.sql -1988156517, 1.3.sql -1189704269, 1.4__dropsFor_1.3.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/1.0__initial.sql index 528727be2..02c9883f7 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/1.0__initial.sql @@ -140,6 +140,18 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar2(255) not null, + "from" varchar2(255), + "to" varchar2(255), + "varchar" varchar2(255), + "foreign" varchar2(255), + constraint uq_table_to unique ("to"), + constraint uq_table_varchar unique ("varchar"), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create table migtest_mtm_c ( id number(10) generated by default as identity not null, name varchar2(255), @@ -174,5 +186,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id); +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index"); + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/1.1.sql index 662e1dd33..2dc2c5aff 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/1.1.sql @@ -90,6 +90,7 @@ update migtest_e_history2 set test_string = 'unknown' where test_string is null; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; -- apply alter tables +alter table "table" add "select" varchar2(255); alter table migtest_ckey_detail add one_key number(10); alter table migtest_ckey_detail add two_key varchar2(127); alter table migtest_ckey_parent add assoc_id number(10); @@ -132,6 +133,8 @@ alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( p -- NOT YET IMPLEMENTED: alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5); comment on column migtest_e_history.test_string is 'Column altered to long now'; comment on table migtest_e_history is 'We have history now'; +comment on column "table"."index" is 'this is an other comment'; +-- NOT YET IMPLEMENTED: alter table "table" add constraint uq_table_select unique ("select"); -- foreign keys and indices create index ix_mgtst_mtm_c_mgtst_mt_3ug4ok on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_mgtst_mtm_c_mgtst_mt_93awga foreign key (migtest_mtm_c_id) references migtest_mtm_c (id); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/1.3.sql index 38dad644b..e84773a9b 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/1.3.sql @@ -137,6 +137,7 @@ alter table migtest_e_basic add constraint ck_migtest_e_basic_status2 check ( st alter table migtest_e_enum add constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')); comment on column migtest_e_history.test_string is ''; comment on table migtest_e_history is ''; +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade; alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/idx_oracle.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/idx_oracle.migrations index 0176dd762..c00b2991b 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/idx_oracle.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle/idx_oracle.migrations @@ -1,7 +1,7 @@ -2058445079, 1.0__initial.sql --406177058, 1.1.sql +-2071028889, 1.0__initial.sql +-1556388339, 1.1.sql -582436324, 1.2__dropsFor_1.1.sql -245787021, 1.3.sql +-712179623, 1.3.sql 663051206, 1.4__dropsFor_1.3.sql 1357801733, R__oracle_only_views.sql 561281075, R__order_views.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/1.0__initial.sql index 4daef7bce..d978faf0e 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/1.0__initial.sql @@ -158,6 +158,18 @@ create table migtest_e_softdelete ( ); create sequence migtest_e_softdelete_seq; +create table "table" ( + "index" varchar2(255) not null, + "from" varchar2(255), + "to" varchar2(255), + "varchar" varchar2(255), + "foreign" varchar2(255), + constraint uq_table_to unique ("to"), + constraint uq_table_varchar unique ("varchar"), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create table migtest_mtm_c ( id number(10) not null, name varchar2(255), @@ -196,5 +208,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id); +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index"); + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/1.1.sql index d5c198c6b..ef694fac8 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/1.1.sql @@ -91,6 +91,7 @@ update migtest_e_history2 set test_string = 'unknown' where test_string is null; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; -- apply alter tables +alter table "table" add "select" varchar2(255); alter table migtest_ckey_detail add one_key number(10); alter table migtest_ckey_detail add two_key varchar2(127); alter table migtest_ckey_parent add assoc_id number(10); @@ -133,6 +134,8 @@ alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( p -- NOT YET IMPLEMENTED: alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5); comment on column migtest_e_history.test_string is 'Column altered to long now'; comment on table migtest_e_history is 'We have history now'; +comment on column "table"."index" is 'this is an other comment'; +-- NOT YET IMPLEMENTED: alter table "table" add constraint uq_table_select unique ("select"); -- foreign keys and indices create index ix_mgtst_mtm_c_mgtst_mt_3ug4ok on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_mgtst_mtm_c_mgtst_mt_93awga foreign key (migtest_mtm_c_id) references migtest_mtm_c (id); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/1.3.sql index f4ea1b1ee..5c7882368 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/1.3.sql @@ -138,6 +138,7 @@ alter table migtest_e_basic add constraint ck_migtest_e_basic_status2 check ( st alter table migtest_e_enum add constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')); comment on column migtest_e_history.test_string is ''; comment on table migtest_e_history is ''; +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade; alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/idx_oracle.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/idx_oracle.migrations index 163871480..09ea3293a 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/idx_oracle.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/oracle11/idx_oracle.migrations @@ -1,7 +1,7 @@ --1132728964, 1.0__initial.sql -1635736608, 1.1.sql +-1110489114, 1.0__initial.sql +1800537955, 1.1.sql -582436324, 1.2__dropsFor_1.1.sql -2103586605, 1.3.sql +-253819510, 1.3.sql 663051206, 1.4__dropsFor_1.3.sql 1357801733, R__oracle_only_views.sql 561281075, R__order_views.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/1.0__initial.sql index 9e0e21cbc..65e967ce4 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/1.0__initial.sql @@ -140,6 +140,18 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint uq_table_to unique ("to"), + constraint uq_table_varchar unique ("varchar"), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create table migtest_mtm_c ( id integer generated by default as identity not null, name varchar(255), @@ -165,6 +177,7 @@ create table migtest_oto_master ( ); -- apply alter tables +alter table "table" add column sys_period tstzrange not null default tstzrange(current_timestamp, null); alter table migtest_e_history2 add column sys_period tstzrange not null default tstzrange(current_timestamp, null); alter table migtest_e_history3 add column sys_period tstzrange not null default tstzrange(current_timestamp, null); alter table migtest_e_history4 add column sys_period tstzrange not null default tstzrange(current_timestamp, null); @@ -296,6 +309,31 @@ create trigger migtest_e_history6_history_upd for each row execute procedure migtest_e_history6_history_version(); +create table table_history(like "table"); +create view table_with_history as select * from "table" union all select * from table_history; +create or replace function table_history_version() returns trigger as $$ +declare + lowerTs timestamptz; + upperTs timestamptz; +begin + lowerTs = lower(OLD.sys_period); + upperTs = greatest(lowerTs + '1 microsecond',current_timestamp); + if (TG_OP = 'UPDATE') then + insert into table_history (sys_period,"index", "from", "to", "varchar", "foreign") values (tstzrange(lowerTs,upperTs), OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign"); + NEW.sys_period = tstzrange(upperTs,null); + return new; + elsif (TG_OP = 'DELETE') then + insert into table_history (sys_period,"index", "from", "to", "varchar", "foreign") values (tstzrange(lowerTs,upperTs), OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign"); + return old; + end if; +end; +$$ LANGUAGE plpgsql; + +create trigger table_history_upd + before update or delete on "table" + for each row execute procedure table_history_version(); + + -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; @@ -306,8 +344,12 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict; + create index if not exists ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index if not exists ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index if not exists ix_table_from on "table" ("from"); create index idxd_migtest_0 on migtest_oto_child using hash (upper(name)) where upper(name) = 'JIM'; create index concurrently if not exists ix_migtest_oto_child_lowername_id on migtest_oto_child (lower(name),id); create index if not exists ix_migtest_oto_child_lowername on migtest_oto_child (lower(name)); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/1.1.sql index 7d7940d6c..b513afc92 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/1.1.sql @@ -69,7 +69,12 @@ drop trigger if exists migtest_e_history6_history_upd on migtest_e_history6 casc drop function if exists migtest_e_history6_history_version(); drop view migtest_e_history6_with_history; +drop trigger if exists table_history_upd on "table" cascade; +drop function if exists table_history_version(); + +drop view table_with_history; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -106,6 +111,7 @@ alter table migtest_e_history6 alter column test_number2 drop not null; alter table migtest_e_history6_history alter column test_number2 drop not null; alter table migtest_e_softdelete add column deleted boolean default false not null; alter table migtest_oto_child add column master_id bigint; +alter table table_history add column "select" varchar(255); -- apply post alter alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?')); alter table migtest_e_basic add constraint uq_migtest_e_basic_description unique (description); @@ -259,6 +265,31 @@ create trigger migtest_e_history6_history_upd before update or delete on migtest_e_history6 for each row execute procedure migtest_e_history6_history_version(); +comment on column "table"."index" is 'this is an other comment'; +create view table_with_history as select * from "table" union all select * from table_history; +create or replace function table_history_version() returns trigger as $$ +declare + lowerTs timestamptz; + upperTs timestamptz; +begin + lowerTs = lower(OLD.sys_period); + upperTs = greatest(lowerTs + '1 microsecond',current_timestamp); + if (TG_OP = 'UPDATE') then + insert into table_history (sys_period,"index", "from", "to", "varchar", "select", "foreign") values (tstzrange(lowerTs,upperTs), OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."select", OLD."foreign"); + NEW.sys_period = tstzrange(upperTs,null); + return new; + elsif (TG_OP = 'DELETE') then + insert into table_history (sys_period,"index", "from", "to", "varchar", "select", "foreign") values (tstzrange(lowerTs,upperTs), OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."select", OLD."foreign"); + return old; + end if; +end; +$$ LANGUAGE plpgsql; + +create trigger table_history_upd + before update or delete on "table" + for each row execute procedure table_history_version(); + +alter table "table" add constraint uq_table_select unique ("select"); -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/1.3.sql index 40c43d938..7ce64dc07 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/1.3.sql @@ -178,6 +178,7 @@ create trigger migtest_e_history6_history_upd before update or delete on migtest_e_history6 for each row execute procedure migtest_e_history6_history_version(); +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/idx_postgres.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/idx_postgres.migrations index e62ed906f..c226913cb 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/idx_postgres.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres/idx_postgres.migrations @@ -1,7 +1,7 @@ --1277453273, 1.0__initial.sql --2141665406, 1.1.sql +-1738052304, 1.0__initial.sql +376807442, 1.1.sql -1098989118, 1.2__dropsFor_1.1.sql -199465792, 1.3.sql +691388965, 1.3.sql 1729345905, 1.4__dropsFor_1.3.sql 783227075, R__multi_comments.sql 561281075, R__order_views.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/1.0__initial.sql index e088febde..c07f369a7 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/1.0__initial.sql @@ -140,6 +140,18 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint uq_table_to unique ("to"), + constraint uq_table_varchar unique ("varchar"), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create table migtest_mtm_c ( id serial not null, name varchar(255), @@ -165,6 +177,7 @@ create table migtest_oto_master ( ); -- apply alter tables +alter table "table" add column sys_period tstzrange not null default tstzrange(current_timestamp, null); alter table migtest_e_history2 add column sys_period tstzrange not null default tstzrange(current_timestamp, null); alter table migtest_e_history3 add column sys_period tstzrange not null default tstzrange(current_timestamp, null); alter table migtest_e_history4 add column sys_period tstzrange not null default tstzrange(current_timestamp, null); @@ -296,6 +309,31 @@ create trigger migtest_e_history6_history_upd for each row execute procedure migtest_e_history6_history_version(); +create table table_history(like "table"); +create view table_with_history as select * from "table" union all select * from table_history; +create or replace function table_history_version() returns trigger as $$ +declare + lowerTs timestamptz; + upperTs timestamptz; +begin + lowerTs = lower(OLD.sys_period); + upperTs = greatest(lowerTs + '1 microsecond',current_timestamp); + if (TG_OP = 'UPDATE') then + insert into table_history (sys_period,"index", "from", "to", "varchar", "foreign") values (tstzrange(lowerTs,upperTs), OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign"); + NEW.sys_period = tstzrange(upperTs,null); + return new; + elsif (TG_OP = 'DELETE') then + insert into table_history (sys_period,"index", "from", "to", "varchar", "foreign") values (tstzrange(lowerTs,upperTs), OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign"); + return old; + end if; +end; +$$ LANGUAGE plpgsql; + +create trigger table_history_upd + before update or delete on "table" + for each row execute procedure table_history_version(); + + -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; @@ -306,8 +344,12 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict; + create index if not exists ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index if not exists ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index if not exists ix_table_from on "table" ("from"); create index idxd_migtest_0 on migtest_oto_child using hash (upper(name)) where upper(name) = 'JIM'; create index concurrently if not exists ix_migtest_oto_child_lowername_id on migtest_oto_child (lower(name),id); create index if not exists ix_migtest_oto_child_lowername on migtest_oto_child (lower(name)); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/1.1.sql index 6622865e2..506c0fd73 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/1.1.sql @@ -69,7 +69,12 @@ drop trigger if exists migtest_e_history6_history_upd on migtest_e_history6 casc drop function if exists migtest_e_history6_history_version(); drop view migtest_e_history6_with_history; +drop trigger if exists table_history_upd on "table" cascade; +drop function if exists table_history_version(); + +drop view table_with_history; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -106,6 +111,7 @@ alter table migtest_e_history6 alter column test_number2 drop not null; alter table migtest_e_history6_history alter column test_number2 drop not null; alter table migtest_e_softdelete add column deleted boolean default false not null; alter table migtest_oto_child add column master_id bigint; +alter table table_history add column "select" varchar(255); -- apply post alter alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?')); alter table migtest_e_basic add constraint uq_migtest_e_basic_description unique (description); @@ -259,6 +265,31 @@ create trigger migtest_e_history6_history_upd before update or delete on migtest_e_history6 for each row execute procedure migtest_e_history6_history_version(); +comment on column "table"."index" is 'this is an other comment'; +create view table_with_history as select * from "table" union all select * from table_history; +create or replace function table_history_version() returns trigger as $$ +declare + lowerTs timestamptz; + upperTs timestamptz; +begin + lowerTs = lower(OLD.sys_period); + upperTs = greatest(lowerTs + '1 microsecond',current_timestamp); + if (TG_OP = 'UPDATE') then + insert into table_history (sys_period,"index", "from", "to", "varchar", "select", "foreign") values (tstzrange(lowerTs,upperTs), OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."select", OLD."foreign"); + NEW.sys_period = tstzrange(upperTs,null); + return new; + elsif (TG_OP = 'DELETE') then + insert into table_history (sys_period,"index", "from", "to", "varchar", "select", "foreign") values (tstzrange(lowerTs,upperTs), OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."select", OLD."foreign"); + return old; + end if; +end; +$$ LANGUAGE plpgsql; + +create trigger table_history_upd + before update or delete on "table" + for each row execute procedure table_history_version(); + +alter table "table" add constraint uq_table_select unique ("select"); -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/1.3.sql index aa87d0936..96a61e00a 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/1.3.sql @@ -178,6 +178,7 @@ create trigger migtest_e_history6_history_upd before update or delete on migtest_e_history6 for each row execute procedure migtest_e_history6_history_version(); +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/idx_postgres.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/idx_postgres.migrations index 753ebe59c..d3179797a 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/idx_postgres.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/postgres9/idx_postgres.migrations @@ -1,7 +1,7 @@ -1678831678, 1.0__initial.sql --1261465039, 1.1.sql +1809459793, 1.0__initial.sql +-533983703, 1.1.sql -1098989118, 1.2__dropsFor_1.1.sql -39355920, 1.3.sql +376154634, 1.3.sql 1729345905, 1.4__dropsFor_1.3.sql 783227075, R__multi_comments.sql 561281075, R__order_views.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/1.0__initial.sql index 4b0911a54..40060b094 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/1.0__initial.sql @@ -140,6 +140,18 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint uq_table_to unique ("to"), + constraint uq_table_varchar unique ("varchar"), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create table migtest_mtm_c ( id integer auto_increment not null, name varchar(255), @@ -174,5 +186,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict; + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/1.1.sql index 41b8f5b80..2541938d3 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/1.1.sql @@ -45,6 +45,7 @@ update migtest_e_history2 set test_string = 'unknown' where test_string is null; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -87,6 +88,8 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5); comment on column migtest_e_history.test_string is 'Column altered to long now'; comment on table migtest_e_history is 'We have history now'; +comment on column "table"."index" is 'this is an other comment'; +alter table "table" add constraint uq_table_select unique ("select"); -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/1.3.sql index db54a5526..384260c79 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/1.3.sql @@ -65,6 +65,7 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique alter table migtest_e_enum add constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')); comment on column migtest_e_history.test_string is ''; comment on table migtest_e_history is ''; +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/idx_sqlanywhere.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/idx_sqlanywhere.migrations index 2b9baab48..ea4b69483 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/idx_sqlanywhere.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlanywhere/idx_sqlanywhere.migrations @@ -1,6 +1,6 @@ -874272908, 1.0__initial.sql -1253219479, 1.1.sql +322064344, 1.0__initial.sql +1152745318, 1.1.sql 1279151426, 1.2__dropsFor_1.1.sql --894462776, 1.3.sql +-1467142599, 1.3.sql 80209848, 1.4__dropsFor_1.3.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlite/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlite/1.0__initial.sql index 0f53a01bf..446fda37e 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlite/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlite/1.0__initial.sql @@ -143,6 +143,18 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint uq_table_to unique ("to"), + constraint uq_table_varchar unique ("varchar"), + constraint pk_table primary key ("index"), + foreign key ("foreign") references "table" ("index") on delete restrict on update restrict +); + create table migtest_mtm_c ( id integer not null, name varchar(255), @@ -170,3 +182,4 @@ create table migtest_oto_master ( -- foreign keys and indices create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlite/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlite/1.1.sql index 873ee0334..1b1d797e6 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlite/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlite/1.1.sql @@ -50,6 +50,7 @@ update migtest_e_history2 set test_string = 'unknown' where test_string is null; -- NOTE: table has @History - special migration may be necessary update migtest_e_history6 set test_number1 = 42 where test_number1 is null; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -89,6 +90,7 @@ update migtest_e_basic set new_boolean_field = old_boolean; -- not supported: alter table migtest_e_basic add constraint uq_migtest_e_basic_name unique (name); -- not supported: alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique (indextest4); -- not supported: alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5); +-- not supported: alter table "table" add constraint uq_table_select unique ("select"); -- foreign keys and indices -- not supported: alter table migtest_ckey_detail add constraint fk_migtest_ckey_detail_parent foreign key (one_key,two_key) references migtest_ckey_parent (one_key,two_key) on delete restrict on update restrict; create index ix_migtest_ckey_parent_assoc_id on migtest_ckey_parent (assoc_id); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlite/idx_sqlite.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlite/idx_sqlite.migrations index 24bda4a35..75273e48d 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlite/idx_sqlite.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlite/idx_sqlite.migrations @@ -1,5 +1,5 @@ --280067147, 1.0__initial.sql -1471316137, 1.1.sql +587945719, 1.0__initial.sql +-752421071, 1.1.sql 1279151426, 1.2__dropsFor_1.1.sql 18475685, 1.3.sql 80209848, 1.4__dropsFor_1.3.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver16/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver16/1.0__initial.sql index aca71555c..0ceba76cc 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver16/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver16/1.0__initial.sql @@ -137,6 +137,15 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table [table] ( + [index] varchar(255) not null, + [from] varchar(255), + [to] varchar(255), + [varchar] varchar(255), + [foreign] varchar(255), + constraint pk_table primary key ([index]) +); + create table migtest_mtm_c ( id integer identity(1,1) not null, name varchar(255), @@ -190,6 +199,13 @@ alter table migtest_e_history6 period for system_time (sys_periodFrom, sys_periodTo); alter table migtest_e_history6 set (system_versioning = on (history_table=dbo.migtest_e_history6_history)); alter table migtest_e_ref add constraint uq_migtest_e_ref_name unique (name); +create unique nonclustered index uq_table_to on "table"("to") where "to" is not null; +create unique nonclustered index uq_table_varchar on "table"("varchar") where "varchar" is not null; +alter table [table] + add sys_periodFrom datetime2 GENERATED ALWAYS AS ROW START NOT NULL DEFAULT SYSUTCDATETIME(), + sys_periodTo datetime2 GENERATED ALWAYS AS ROW END NOT NULL DEFAULT '9999-12-31T23:59:59.9999999', +period for system_time (sys_periodFrom, sys_periodTo); +alter table "table" set (system_versioning = on (history_table=dbo.table_history)); -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade; @@ -200,5 +216,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id); +create index ix_table_foreign on [table] ([foreign]); +alter table [table] add constraint fk_table_foreign foreign key ([foreign]) references [table] ([index]); + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on [table] ([from]); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver16/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver16/1.1.sql index b731e5830..7552a3c6b 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver16/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver16/1.1.sql @@ -61,7 +61,11 @@ update migtest_e_history6 set test_number1 = 42 where test_number1 is null; -- alter table migtest_e_history6 set (system_versioning = off (history_table=dbo.migtest_e_history6_history)); -- history migration goes here -- alter table migtest_e_history6 set (system_versioning = on (history_table=dbo.migtest_e_history6_history)); +-- alter table [table] set (system_versioning = off (history_table=dbo.table_history)); +-- history migration goes here +-- alter table [table] set (system_versioning = on (history_table=dbo.table_history)); -- apply alter tables +alter table [table] add [select] varchar(255); alter table migtest_ckey_detail add one_key integer; alter table migtest_ckey_detail add two_key varchar(127); alter table migtest_ckey_parent add assoc_id integer; @@ -109,6 +113,7 @@ alter table migtest_e_history sys_periodTo datetime2 GENERATED ALWAYS AS ROW END NOT NULL DEFAULT '9999-12-31T23:59:59.9999999', period for system_time (sys_periodFrom, sys_periodTo); alter table migtest_e_history set (system_versioning = on (history_table=dbo.migtest_e_history_history)); +create unique nonclustered index uq_table_select on "table"("select") where "select" is not null; -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver16/idx_sqlserver.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver16/idx_sqlserver.migrations index a8f498f63..0e3158837 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver16/idx_sqlserver.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver16/idx_sqlserver.migrations @@ -1,6 +1,6 @@ -2122378240, I__create_procs.sql -1442928133, 1.0__initial.sql -168980248, 1.1.sql +-177269726, 1.0__initial.sql +708685501, 1.1.sql -1687762822, 1.2__dropsFor_1.1.sql 155669224, 1.3.sql -410961452, 1.4__dropsFor_1.3.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver17/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver17/1.0__initial.sql index df4dfb099..df8c1c702 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver17/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver17/1.0__initial.sql @@ -155,6 +155,15 @@ create table migtest_e_softdelete ( ); create sequence migtest_e_softdelete_seq as bigint start with 1; +create table [table] ( + [index] nvarchar(255) not null, + [from] nvarchar(255), + [to] nvarchar(255), + [varchar] nvarchar(255), + [foreign] nvarchar(255), + constraint pk_table primary key ([index]) +); + create table migtest_mtm_c ( id integer not null, name nvarchar(255), @@ -212,6 +221,13 @@ alter table migtest_e_history6 period for system_time (sys_periodFrom, sys_periodTo); alter table migtest_e_history6 set (system_versioning = on (history_table=dbo.migtest_e_history6_history)); alter table migtest_e_ref add constraint uq_migtest_e_ref_name unique (name); +create unique nonclustered index uq_table_to on "table"("to") where "to" is not null; +create unique nonclustered index uq_table_varchar on "table"("varchar") where "varchar" is not null; +alter table [table] + add sys_periodFrom datetime2 GENERATED ALWAYS AS ROW START NOT NULL DEFAULT SYSUTCDATETIME(), + sys_periodTo datetime2 GENERATED ALWAYS AS ROW END NOT NULL DEFAULT '9999-12-31T23:59:59.9999999', +period for system_time (sys_periodFrom, sys_periodTo); +alter table "table" set (system_versioning = on (history_table=dbo.table_history)); -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade; @@ -222,5 +238,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id); +create index ix_table_foreign on [table] ([foreign]); +alter table [table] add constraint fk_table_foreign foreign key ([foreign]) references [table] ([index]); + create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index ix_table_from on [table] ([from]); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver17/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver17/1.1.sql index ae85f459d..91fdef093 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver17/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver17/1.1.sql @@ -62,7 +62,11 @@ update migtest_e_history6 set test_number1 = 42 where test_number1 is null; -- alter table migtest_e_history6 set (system_versioning = off (history_table=dbo.migtest_e_history6_history)); -- history migration goes here -- alter table migtest_e_history6 set (system_versioning = on (history_table=dbo.migtest_e_history6_history)); +-- alter table [table] set (system_versioning = off (history_table=dbo.table_history)); +-- history migration goes here +-- alter table [table] set (system_versioning = on (history_table=dbo.table_history)); -- apply alter tables +alter table [table] add [select] nvarchar(255); alter table migtest_ckey_detail add one_key integer; alter table migtest_ckey_detail add two_key nvarchar(127); alter table migtest_ckey_parent add assoc_id integer; @@ -110,6 +114,7 @@ alter table migtest_e_history sys_periodTo datetime2 GENERATED ALWAYS AS ROW END NOT NULL DEFAULT '9999-12-31T23:59:59.9999999', period for system_time (sys_periodFrom, sys_periodTo); alter table migtest_e_history set (system_versioning = on (history_table=dbo.migtest_e_history_history)); +create unique nonclustered index uq_table_select on "table"("select") where "select" is not null; -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver17/idx_sqlserver.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver17/idx_sqlserver.migrations index eaaded292..0da8bb066 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver17/idx_sqlserver.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/sqlserver17/idx_sqlserver.migrations @@ -1,6 +1,6 @@ -2122378240, I__create_procs.sql --199159570, 1.0__initial.sql -2140869743, 1.1.sql +1239366592, 1.0__initial.sql +1829437030, 1.1.sql -1687762822, 1.2__dropsFor_1.1.sql -476460378, 1.3.sql -410961452, 1.4__dropsFor_1.3.sql diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/1.0__initial.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/1.0__initial.sql index 159a176d6..8cdb3c45a 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/1.0__initial.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/1.0__initial.sql @@ -140,6 +140,18 @@ create table migtest_e_softdelete ( constraint pk_migtest_e_softdelete primary key (id) ); +create table "table" ( + "index" varchar(255) not null, + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + constraint uq_table_to unique ("to"), + constraint uq_table_varchar unique ("varchar"), + constraint pk_table primary key ("index") +); +comment on column "table"."index" is 'this is a comment'; + create table migtest_mtm_c ( id integer generated by default as identity not null, name varchar(255), @@ -165,6 +177,7 @@ create table migtest_oto_master ( ); -- apply alter tables +alter table "table" add column sys_period tstzrange not null default tstzrange(current_timestamp, null); alter table migtest_e_history2 add column sys_period tstzrange not null default tstzrange(current_timestamp, null); alter table migtest_e_history3 add column sys_period tstzrange not null default tstzrange(current_timestamp, null); alter table migtest_e_history4 add column sys_period tstzrange not null default tstzrange(current_timestamp, null); @@ -319,6 +332,38 @@ create trigger migtest_e_history6_history_upd for each row execute procedure migtest_e_history6_history_version(); +create table table_history( + "index" varchar(255), + "from" varchar(255), + "to" varchar(255), + "varchar" varchar(255), + "foreign" varchar(255), + sys_period tstzrange +); +create view table_with_history as select * from "table" union all select * from table_history; +create or replace function table_history_version() returns trigger as $$ +declare + lowerTs timestamptz; + upperTs timestamptz; +begin + lowerTs = lower(OLD.sys_period); + upperTs = greatest(lowerTs + '1 microsecond',current_timestamp); + if (TG_OP = 'UPDATE') then + insert into table_history (sys_period,"index", "from", "to", "varchar", "foreign") values (tstzrange(lowerTs,upperTs), OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign"); + NEW.sys_period = tstzrange(upperTs,null); + return new; + elsif (TG_OP = 'DELETE') then + insert into table_history (sys_period,"index", "from", "to", "varchar", "foreign") values (tstzrange(lowerTs,upperTs), OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."foreign"); + return old; + end if; +end; +$$ LANGUAGE plpgsql; + +create trigger table_history_upd + before update or delete on "table" + for each row execute procedure table_history_version(); + + -- foreign keys and indices create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id); alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; @@ -329,5 +374,9 @@ alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id for create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id); alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict; +create index ix_table_foreign on "table" ("foreign"); +alter table "table" add constraint fk_table_foreign foreign key ("foreign") references "table" ("index") on delete restrict on update restrict; + create index if not exists ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1); create index if not exists ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5); +create index if not exists ix_table_from on "table" ("from"); diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/1.1.sql index 55a97ccb3..d9fa995a0 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/1.1.sql @@ -64,7 +64,12 @@ drop trigger if exists migtest_e_history6_history_upd on migtest_e_history6 casc drop function if exists migtest_e_history6_history_version(); drop view migtest_e_history6_with_history; +drop trigger if exists table_history_upd on "table" cascade; +drop function if exists table_history_version(); + +drop view table_with_history; -- apply alter tables +alter table "table" add column "select" varchar(255); alter table migtest_ckey_detail add column one_key integer; alter table migtest_ckey_detail add column two_key varchar(127); alter table migtest_ckey_parent add column assoc_id integer; @@ -101,6 +106,7 @@ alter table migtest_e_history6 alter column test_number2 drop not null; alter table migtest_e_history6_history alter column test_number2 drop not null; alter table migtest_e_softdelete add column deleted boolean default false not null; alter table migtest_oto_child add column master_id bigint; +alter table table_history add column "select" varchar(255); -- apply post alter alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?')); alter table migtest_e_basic add constraint uq_migtest_e_basic_description unique (description); @@ -258,6 +264,31 @@ create trigger migtest_e_history6_history_upd before update or delete on migtest_e_history6 for each row execute procedure migtest_e_history6_history_version(); +comment on column "table"."index" is 'this is an other comment'; +create view table_with_history as select * from "table" union all select * from table_history; +create or replace function table_history_version() returns trigger as $$ +declare + lowerTs timestamptz; + upperTs timestamptz; +begin + lowerTs = lower(OLD.sys_period); + upperTs = greatest(lowerTs + '1 microsecond',current_timestamp); + if (TG_OP = 'UPDATE') then + insert into table_history (sys_period,"index", "from", "to", "varchar", "select", "foreign") values (tstzrange(lowerTs,upperTs), OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."select", OLD."foreign"); + NEW.sys_period = tstzrange(upperTs,null); + return new; + elsif (TG_OP = 'DELETE') then + insert into table_history (sys_period,"index", "from", "to", "varchar", "select", "foreign") values (tstzrange(lowerTs,upperTs), OLD."index", OLD."from", OLD."to", OLD."varchar", OLD."select", OLD."foreign"); + return old; + end if; +end; +$$ LANGUAGE plpgsql; + +create trigger table_history_upd + before update or delete on "table" + for each row execute procedure table_history_version(); + +alter table "table" add constraint uq_table_select unique ("select"); -- foreign keys and indices create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id); alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/1.3.sql index 997d95033..29fb9e62b 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/1.3.sql @@ -178,6 +178,7 @@ create trigger migtest_e_history6_history_upd before update or delete on migtest_e_history6 for each row execute procedure migtest_e_history6_history_version(); +comment on column "table"."index" is 'this is a comment'; -- foreign keys and indices alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict; alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/idx_yugabyte.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/idx_yugabyte.migrations index df428d942..05f50b829 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/idx_yugabyte.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/yugabyte/idx_yugabyte.migrations @@ -1,7 +1,7 @@ -1817007763, 1.0__initial.sql --2145787580, 1.1.sql +-967136529, 1.0__initial.sql +-1547662237, 1.1.sql -1098989118, 1.2__dropsFor_1.1.sql -30606484, 1.3.sql +1877712595, 1.3.sql 1729345905, 1.4__dropsFor_1.3.sql 561281075, R__order_views.sql