Skip to content

Commit

Permalink
Merge pull request #3104 from FOCONIS/dbmigration-fixes
Browse files Browse the repository at this point in the history
Fixed DbMigration classes (put them in the right place)
  • Loading branch information
rob-bygrave authored Jun 13, 2023
2 parents 462d30b + 3e2e84e commit e19cbdc
Show file tree
Hide file tree
Showing 130 changed files with 517 additions and 486 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@ public void testRunMigration() throws IOException, SQLException {
"`migtest_QuOtEd`",
"migtest_QuOtEd",
"\"migtest_QuOtEd\"",
"drop_main_drop_ref_many",
"drop_ref_many",
"drop_ref_one",
"drop_main",
"table",
"\"table\"",
"`table`");

((DataSourcePool)server().dataSource()).offline();
((DataSourcePool)server().dataSource()).online();

Expand Down
10 changes: 10 additions & 0 deletions ebean-test/src/test/java/misc/migration/NOTICE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
The migration dir contains 3 folders `v1_0`, `v1_1`, `v1_2`.

The general idea is, that we try to perform a migration (=`v1.0` -> `v1.1`) and also if it is revertable (= `v1.1` -> `v1.0`)

To achieve that, the directories `v1_0` and `v1_2` should be as equal as possible. Annomalies should be commented.

It is also important, if new models are added, that all table names (also for M2M) are added in the `DbMigrationTest`
cleanup routine.


Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package misc.migration.v1_0;
package misc.migration.v1_1;

import javax.persistence.*;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package misc.migration.v1_0;
package misc.migration.v1_1;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package misc.migration.v1_0;
package misc.migration.v1_1;

import javax.persistence.Entity;
import javax.persistence.Id;
Expand Down
6 changes: 5 additions & 1 deletion ebean-test/src/test/java/misc/migration/v1_2/EBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

@Entity
@Table(name = "migtest_e_basic")
// Note: tablespaces are currently only supported for DB2
// to be prepared for future (when we support sql server filegroups),
// we allow to specify the DB-platform here
@Tablespace(value = "db2;TSTABLES;", index = "db2;INDEXTS;")
public class EBasic {

public enum Status {
Expand Down Expand Up @@ -86,7 +90,7 @@ public enum Status {
String indextest6;

@NotNull
@DbDefault("23")
@DbDefault("23") // required for revert
int user_id;

public EBasic() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public class EHistory6 {
Integer testNumber1;

@NotNull
@DbDefault("7")
@DbDefault("7") // required for revert
Integer testNumber2;
}
9 changes: 9 additions & 0 deletions ebean-test/src/test/java/misc/migration/v1_2/ETable.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ public class ETable {

@OneToMany(mappedBy = "foreign")
List<ETable> foreigns;

// @NotNull
// @DbDefault("")
// private String textfield;
// FIXME: MariaDb produces an invalid quoted statement. We would need to fix quotes here.
// but using reserved names for tables is a bad idea IMHO
// actual: update "table" set textfield = '' where textfield is null;
// expected: update `table` set textfield = '' where textfield is null;

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,5 @@ alter table migtest_e_basic drop column eref_id;
alter table migtest_e_history2 drop column obsolete_string1;
alter table migtest_e_history2 drop column obsolete_string2;
-- apply post alter
drop table if exists drop_main;
drop table if exists drop_main_drop_ref_many;
drop table if exists drop_ref_many;
drop table if exists drop_ref_one;
drop table if exists "migtest_QuOtEd";
drop table if exists migtest_e_ref;
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ alter table migtest_e_history5 drop column test_boolean;
alter table migtest_e_softdelete drop column deleted;
alter table migtest_oto_child drop column master_id;
-- apply post alter
drop table if exists drop_main;
drop table if exists drop_main_drop_ref_many;
drop table if exists drop_ref_many;
drop table if exists drop_ref_one;
drop table if exists migtest_e_user;
drop table if exists migtest_mtm_c_migtest_mtm_m;
drop table if exists migtest_mtm_m_migtest_mtm_c;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1672735407, 1.0__initial.sql
540706946, 1.1.sql
-875723380, 1.2__dropsFor_1.1.sql
688811494, 1.2__dropsFor_1.1.sql
1015552567, 1.3.sql
255653518, 1.4__dropsFor_1.3.sql
677297367, 1.4__dropsFor_1.3.sql

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ alter table migtest_e_basic drop constraint if exists ck_migtest_e_basic_status2
drop index uq_migtest_e_basic_indextest2 cascade;
drop index uq_migtest_e_basic_indextest6 cascade;
alter table migtest_e_enum drop constraint if exists ck_migtest_e_enum_test_status;
alter table if exists drop_main_drop_ref_many drop constraint if exists fk_drop_main_drop_ref_many_drop_main;
alter table if exists drop_main_drop_ref_many drop constraint if exists fk_drop_main_drop_ref_many_drop_ref_many;
alter table if exists drop_ref_one drop constraint if exists fk_drop_ref_one_parent_id;
drop index if exists ix_migtest_e_basic_indextest1;
drop index if exists ix_migtest_e_basic_indextest5;
drop index if exists ix_migtest_quoted_status1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ alter table migtest_e_basic drop column eref_id;
alter table migtest_e_history2 drop column obsolete_string1;
alter table migtest_e_history2 drop column obsolete_string2;
-- apply post alter
drop table if exists drop_main cascade;
drop sequence if exists drop_main_seq;
drop table if exists drop_main_drop_ref_many cascade;
drop table if exists drop_ref_many cascade;
drop sequence if exists drop_ref_many_seq;
drop table if exists drop_ref_one cascade;
drop sequence if exists drop_ref_one_seq;
drop table if exists "migtest_QuOtEd" cascade;
drop table if exists migtest_e_ref cascade;
drop sequence if exists migtest_e_ref_seq;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ drop index uq_migtest_e_basic_name cascade;
drop index uq_migtest_e_basic_indextest4 cascade;
drop index uq_migtest_e_basic_indextest5 cascade;
alter table migtest_e_enum drop constraint if exists ck_migtest_e_enum_test_status;
alter table if exists drop_main_drop_ref_many drop constraint if exists fk_drop_main_drop_ref_many_drop_main;
alter table if exists drop_main_drop_ref_many drop constraint if exists fk_drop_main_drop_ref_many_drop_ref_many;
alter table if exists drop_ref_one drop constraint if exists fk_drop_ref_one_parent_id;
alter table if exists migtest_mtm_c_migtest_mtm_m drop constraint if exists fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c;
alter table if exists migtest_mtm_c_migtest_mtm_m drop constraint if exists fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_m;
alter table if exists migtest_mtm_m_migtest_mtm_c drop constraint if exists fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_m;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ alter table migtest_e_history5 drop column test_boolean;
alter table migtest_e_softdelete drop column deleted;
alter table migtest_oto_child drop column master_id;
-- apply post alter
drop table if exists drop_main cascade;
drop sequence if exists drop_main_seq;
drop table if exists drop_main_drop_ref_many cascade;
drop table if exists drop_ref_many cascade;
drop sequence if exists drop_ref_many_seq;
drop table if exists drop_ref_one cascade;
drop sequence if exists drop_ref_one_seq;
drop table if exists migtest_e_user cascade;
drop sequence if exists migtest_e_user_seq;
drop table if exists migtest_mtm_c_migtest_mtm_m cascade;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1867456246, 1.0__initial.sql
-412570267, 1.1.sql
395394572, 1.2__dropsFor_1.1.sql
-861259583, 1.3.sql
-971909974, 1.4__dropsFor_1.3.sql
1284257915, 1.1.sql
856096334, 1.2__dropsFor_1.1.sql
-279468991, 1.3.sql
2137365848, 1.4__dropsFor_1.3.sql
561281075, R__order_views.sql

Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,6 @@ end if;
end$$;
delimiter $$
begin
if exists (select constname from syscat.tabconst where tabschema = current_schema and ucase(constname) = 'FK_DROP_MAIN_DROP_REF_MANY_DROP_MAIN' and ucase(tabname) = 'DROP_MAIN_DROP_REF_MANY') then
prepare stmt from 'alter table drop_main_drop_ref_many drop constraint fk_drop_main_drop_ref_many_drop_main';
execute stmt;
end if;
end$$;
delimiter $$
begin
if exists (select constname from syscat.tabconst where tabschema = current_schema and ucase(constname) = 'FK_DROP_MAIN_DROP_REF_MANY_DROP_REF_MANY' and ucase(tabname) = 'DROP_MAIN_DROP_REF_MANY') then
prepare stmt from 'alter table drop_main_drop_ref_many drop constraint fk_drop_main_drop_ref_many_drop_ref_many';
execute stmt;
end if;
end$$;
delimiter $$
begin
if exists (select constname from syscat.tabconst where tabschema = current_schema and ucase(constname) = 'FK_DROP_REF_ONE_PARENT_ID' and ucase(tabname) = 'DROP_REF_ONE') then
prepare stmt from 'alter table drop_ref_one drop constraint fk_drop_ref_one_parent_id';
execute stmt;
end if;
end$$;
delimiter $$
begin
if exists (select indname from syscat.indexes where indschema = current_schema and ucase(indname) = 'IX_MIGTEST_E_BASIC_INDEXTEST1') then
prepare stmt from 'drop index ix_migtest_e_basic_indextest1';
execute stmt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,6 @@ alter table migtest_e_history2_history drop column obsolete_string2;
call sysproc.admin_cmd('reorg table migtest_e_history2_history');
-- apply post alter
alter table migtest_e_history2 add versioning use history table migtest_e_history2_history;
drop table drop_main;
delimiter $$
begin
if exists (select seqschema from syscat.sequences where seqschema = current_schema and ucase(seqname) = 'DROP_MAIN_SEQ') then
prepare stmt from 'drop sequence drop_main_seq';
execute stmt;
end if;
end$$;
drop table drop_main_drop_ref_many;
drop table drop_ref_many;
delimiter $$
begin
if exists (select seqschema from syscat.sequences where seqschema = current_schema and ucase(seqname) = 'DROP_REF_MANY_SEQ') then
prepare stmt from 'drop sequence drop_ref_many_seq';
execute stmt;
end if;
end$$;
drop table drop_ref_one;
delimiter $$
begin
if exists (select seqschema from syscat.sequences where seqschema = current_schema and ucase(seqname) = 'DROP_REF_ONE_SEQ') then
prepare stmt from 'drop sequence drop_ref_one_seq';
execute stmt;
end if;
end$$;
drop table "migtest_QuOtEd";
drop table migtest_e_ref;
delimiter $$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ end if;
end$$;
delimiter $$
begin
if exists (select constname from syscat.tabconst where tabschema = current_schema and ucase(constname) = 'FK_DROP_MAIN_DROP_REF_MANY_DROP_MAIN' and ucase(tabname) = 'DROP_MAIN_DROP_REF_MANY') then
prepare stmt from 'alter table drop_main_drop_ref_many drop constraint fk_drop_main_drop_ref_many_drop_main';
execute stmt;
end if;
end$$;
delimiter $$
begin
if exists (select constname from syscat.tabconst where tabschema = current_schema and ucase(constname) = 'FK_DROP_MAIN_DROP_REF_MANY_DROP_REF_MANY' and ucase(tabname) = 'DROP_MAIN_DROP_REF_MANY') then
prepare stmt from 'alter table drop_main_drop_ref_many drop constraint fk_drop_main_drop_ref_many_drop_ref_many';
execute stmt;
end if;
end$$;
delimiter $$
begin
if exists (select constname from syscat.tabconst where tabschema = current_schema and ucase(constname) = 'FK_DROP_REF_ONE_PARENT_ID' and ucase(tabname) = 'DROP_REF_ONE') then
prepare stmt from 'alter table drop_ref_one drop constraint fk_drop_ref_one_parent_id';
execute stmt;
end if;
end$$;
delimiter $$
begin
if exists (select constname from syscat.tabconst where tabschema = current_schema and ucase(constname) = 'FK_MIGTEST_MTM_C_MIGTEST_MTM_M_MIGTEST_MTM_C' and ucase(tabname) = 'MIGTEST_MTM_C_MIGTEST_MTM_M') then
prepare stmt from 'alter table migtest_mtm_c_migtest_mtm_m drop constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c';
execute stmt;
Expand Down Expand Up @@ -211,6 +232,7 @@ update migtest_e_basic set status2 = 'N' where status2 is null;
update migtest_e_basic set a_lob = 'X' where a_lob is null;

update migtest_e_basic set user_id = 23 where user_id is null;
CALL SYSPROC.ADMIN_MOVE_TABLE(CURRENT_SCHEMA,'MIGTEST_E_BASIC','TSTABLES','INDEXTS','TSTABLES','','','','','','MOVE');
alter table migtest_e_history2 drop versioning;
alter table migtest_e_history3 drop versioning;
alter table migtest_e_history4 drop versioning;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,31 @@ drop table migtest_e_history_history;
alter table migtest_e_history2 add versioning use history table migtest_e_history2_history;
alter table migtest_e_history5 add versioning use history table migtest_e_history5_history;
alter table "table" add versioning use history table table_history;
drop table drop_main;
delimiter $$
begin
if exists (select seqschema from syscat.sequences where seqschema = current_schema and ucase(seqname) = 'DROP_MAIN_SEQ') then
prepare stmt from 'drop sequence drop_main_seq';
execute stmt;
end if;
end$$;
drop table drop_main_drop_ref_many;
drop table drop_ref_many;
delimiter $$
begin
if exists (select seqschema from syscat.sequences where seqschema = current_schema and ucase(seqname) = 'DROP_REF_MANY_SEQ') then
prepare stmt from 'drop sequence drop_ref_many_seq';
execute stmt;
end if;
end$$;
drop table drop_ref_one;
delimiter $$
begin
if exists (select seqschema from syscat.sequences where seqschema = current_schema and ucase(seqname) = 'DROP_REF_ONE_SEQ') then
prepare stmt from 'drop sequence drop_ref_one_seq';
execute stmt;
end if;
end$$;
drop table migtest_e_user;
delimiter $$
begin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-283216660, 1.0__initial.sql
1120848440, 1.1.sql
135256939, 1.2__dropsFor_1.1.sql
-2139056187, 1.3.sql
946163478, 1.4__dropsFor_1.3.sql
-184000413, 1.1.sql
-1187336846, 1.2__dropsFor_1.1.sql
-1811865535, 1.3.sql
-1255430844, 1.4__dropsFor_1.3.sql
561281075, R__order_views.sql

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ alter table migtest_e_basic drop constraint if exists ck_migtest_e_basic_status2
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest2;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6;
alter table migtest_e_enum drop constraint if exists ck_migtest_e_enum_test_status;
alter table drop_main_drop_ref_many drop constraint if exists fk_drop_main_drop_ref_many_drop_main;
alter table drop_main_drop_ref_many drop constraint if exists fk_drop_main_drop_ref_many_drop_ref_many;
alter table drop_ref_one drop constraint if exists fk_drop_ref_one_parent_id;
drop index if exists ix_migtest_e_basic_indextest1;
drop index if exists ix_migtest_e_basic_indextest5;
drop index if exists ix_migtest_quoted_status1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,5 @@ alter table migtest_e_basic drop column eref_id;
alter table migtest_e_history2 drop column obsolete_string1;
alter table migtest_e_history2 drop column obsolete_string2;
-- apply post alter
drop table if exists drop_main;
drop table if exists drop_main_drop_ref_many;
drop table if exists drop_ref_many;
drop table if exists drop_ref_one;
drop table if exists "migtest_QuOtEd";
drop table if exists migtest_e_ref;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ alter table migtest_e_basic drop constraint uq_migtest_e_basic_name;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5;
alter table migtest_e_enum drop constraint if exists ck_migtest_e_enum_test_status;
alter table drop_main_drop_ref_many drop constraint if exists fk_drop_main_drop_ref_many_drop_main;
alter table drop_main_drop_ref_many drop constraint if exists fk_drop_main_drop_ref_many_drop_ref_many;
alter table drop_ref_one drop constraint if exists fk_drop_ref_one_parent_id;
alter table migtest_mtm_c_migtest_mtm_m drop constraint if exists fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c;
alter table migtest_mtm_c_migtest_mtm_m drop constraint if exists fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_m;
alter table migtest_mtm_m_migtest_mtm_c drop constraint if exists fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_m;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ alter table migtest_e_history5 drop column test_boolean;
alter table migtest_e_softdelete drop column deleted;
alter table migtest_oto_child drop column master_id;
-- apply post alter
drop table if exists drop_main;
drop table if exists drop_main_drop_ref_many;
drop table if exists drop_ref_many;
drop table if exists drop_ref_one;
drop table if exists migtest_e_user;
drop table if exists migtest_mtm_c_migtest_mtm_m;
drop table if exists migtest_mtm_m_migtest_mtm_c;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-528359263, 1.0__initial.sql
-1374084944, 1.1.sql
-875723380, 1.2__dropsFor_1.1.sql
-819139044, 1.3.sql
255653518, 1.4__dropsFor_1.3.sql
253988246, 1.1.sql
688811494, 1.2__dropsFor_1.1.sql
674925120, 1.3.sql
677297367, 1.4__dropsFor_1.3.sql

Loading

0 comments on commit e19cbdc

Please sign in to comment.