Featur/dbmigration 3 (#1118)

* ADD: more test classes for Softdelete and History

* update reference models after adding test classes

* DbMigration:Improved History generation for sqlserver

* FIX: When DB supports Sql2011 platform, we must not alter the history-table (as this is handled by DB itself)

* DbMigration: When dropping a table, drop the sequence also.

* DbMigration: dropColumn is handled by platformDdl now, as SqlServerDdl needs to delete dependent objects (default constraints...) first

* FIX: DbMigration is not executed on history table

* DbMigration: can drop comment now.

* No effective code change: completed ObjectFactory / fixed imports

* FIX: drop table comment

* Committed the reference models
This commit is contained in:
Roland Praml authored and Rob Bygrave committed 2017-09-10 15:26:01 +12:00
1 parent 84d3578e33
commit 9a7646195c
60 files changed
+922 -45

No files matched your search

@@ -27,11 +27,23 @@ create table migtest_e_history (
constraint pk_migtest_e_history primary key (id)
);
create table migtest_e_history2 (
id integer generated by default as identity not null,
test_string varchar(255),
constraint pk_migtest_e_history2 primary key (id)
);
create table migtest_e_ref (
id integer generated by default as identity not null,
constraint pk_migtest_e_ref primary key (id)
);
create table migtest_e_softdelete (
id integer generated by default as identity not null,
test_string varchar(255),
constraint pk_migtest_e_softdelete primary key (id)
);
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
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;
@@ -33,6 +33,17 @@ alter table migtest_e_basic add column new_integer integer not null default 42;
comment on column migtest_e_history.test_string is 'Column altered to long now';
alter table migtest_e_history alter column test_string bigint;
comment on table migtest_e_history is 'We have history now';
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
alter table migtest_e_history2 alter column test_string set default 'unknown';
alter table migtest_e_history2 alter column test_string set not null;
alter table migtest_e_history2 add column test_string2 varchar(255);
alter table migtest_e_history2 add column test_string3 varchar(255) not null default 'unknown';
alter table migtest_e_history2_history add column test_string2 varchar(255);
alter table migtest_e_history2_history add column test_string3 varchar(255);
alter table migtest_e_softdelete add column deleted boolean not null default false;
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
drop index ix_migtest_e_basic_indextest1;
@@ -6,3 +6,4 @@ alter table migtest_e_basic drop column old_boolean2;
alter table migtest_e_basic drop column eref_id;
drop table migtest_e_ref;
drop sequence migtest_e_ref_seq;
@@ -20,7 +20,10 @@ alter table migtest_e_basic add column old_boolean boolean not null default fals
alter table migtest_e_basic add column old_boolean2 boolean;
alter table migtest_e_basic add column eref_id integer;
comment on column migtest_e_history.test_string is 'DROP COMMENT';
comment on column migtest_e_history.test_string is '';
comment on table migtest_e_history is '';
alter table migtest_e_history2 alter column test_string drop default;
alter table migtest_e_history2 alter column test_string set null;
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
drop index ix_migtest_e_basic_indextest3;
@@ -9,4 +9,13 @@ alter table migtest_e_basic drop column progress;
alter table migtest_e_basic drop column new_integer;
alter table migtest_e_history2 drop column test_string2;
alter table migtest_e_history2_history drop column test_string2;
alter table migtest_e_history2 drop column test_string3;
alter table migtest_e_history2_history drop column test_string3;
alter table migtest_e_softdelete drop column deleted;
drop table migtest_e_user;
drop sequence migtest_e_user_seq;
@@ -27,13 +27,36 @@ create table migtest_e_history (
constraint pk_migtest_e_history primary key (id)
);
create table migtest_e_history2 (
id integer auto_increment not null,
test_string varchar(255),
constraint pk_migtest_e_history2 primary key (id)
);
create table migtest_e_ref (
id integer auto_increment not null,
constraint pk_migtest_e_ref primary key (id)
);
create table migtest_e_softdelete (
id integer auto_increment not null,
test_string varchar(255),
constraint pk_migtest_e_softdelete primary key (id)
);
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
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_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
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);
create table migtest_e_history2_history(
id integer,
test_string varchar(255),
sys_period_start datetime(6),
sys_period_end datetime(6)
);
create view migtest_e_history2_with_history as select * from migtest_e_history2 union all select * from migtest_e_history2_history;
create trigger migtest_e_history2_history_upd before update,delete on migtest_e_history2 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
@@ -33,6 +33,17 @@ alter table migtest_e_basic add column new_integer integer not null default 42;
comment on column migtest_e_history.test_string is 'Column altered to long now';
alter table migtest_e_history alter column test_string bigint;
comment on table migtest_e_history is 'We have history now';
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
alter table migtest_e_history2 alter column test_string set default 'unknown';
alter table migtest_e_history2 alter column test_string set not null;
alter table migtest_e_history2 add column test_string2 varchar(255);
alter table migtest_e_history2 add column test_string3 varchar(255) not null default 'unknown';
alter table migtest_e_history2_history add column test_string2 varchar(255);
alter table migtest_e_history2_history add column test_string3 varchar(255);
alter table migtest_e_softdelete add column deleted boolean not null default false;
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
drop index if exists ix_migtest_e_basic_indextest1;
@@ -48,3 +59,6 @@ create table migtest_e_history_history(
create view migtest_e_history_with_history as select * from migtest_e_history union all select * from migtest_e_history_history;
create trigger migtest_e_history_history_upd before update,delete on migtest_e_history for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
-- changes: [add test_string2, add test_string3]
drop trigger migtest_e_history2_history_upd;
create trigger migtest_e_history2_history_upd before update,delete on migtest_e_history2 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
@@ -6,3 +6,4 @@ alter table migtest_e_basic drop column old_boolean2;
alter table migtest_e_basic drop column eref_id;
drop table if exists migtest_e_ref;
drop sequence if exists migtest_e_ref_seq;
@@ -20,7 +20,10 @@ alter table migtest_e_basic add column old_boolean boolean not null default fals
alter table migtest_e_basic add column old_boolean2 boolean;
alter table migtest_e_basic add column eref_id integer;
comment on column migtest_e_history.test_string is 'DROP COMMENT';
comment on column migtest_e_history.test_string is '';
comment on table migtest_e_history is '';
alter table migtest_e_history2 alter column test_string drop default;
alter table migtest_e_history2 alter column test_string set null;
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
drop index if exists ix_migtest_e_basic_indextest3;
@@ -17,4 +17,16 @@ alter table migtest_e_basic drop column progress;
alter table migtest_e_basic drop column new_integer;
alter table migtest_e_history2 drop column test_string2;
alter table migtest_e_history2_history drop column test_string2;
alter table migtest_e_history2 drop column test_string3;
alter table migtest_e_history2_history drop column test_string3;
alter table migtest_e_softdelete drop column deleted;
drop table if exists migtest_e_user;
drop sequence if exists migtest_e_user_seq;
-- changes: [drop test_string2, drop test_string3]
drop trigger migtest_e_history2_history_upd;
create trigger migtest_e_history2_history_upd before update,delete on migtest_e_history2 for each row call "io.ebean.config.dbplatform.h2.H2HistoryTrigger";
@@ -27,11 +27,23 @@ create table migtest_e_history (
constraint pk_migtest_e_history primary key (id)
);
create table migtest_e_history2 (
id integer generated by default as identity (start with 1) not null,
test_string varchar(255),
constraint pk_migtest_e_history2 primary key (id)
);
create table migtest_e_ref (
id integer generated by default as identity (start with 1) not null,
constraint pk_migtest_e_ref primary key (id)
);
create table migtest_e_softdelete (
id integer generated by default as identity (start with 1) not null,
test_string varchar(255),
constraint pk_migtest_e_softdelete primary key (id)
);
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
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;
@@ -33,6 +33,17 @@ alter table migtest_e_basic add column new_integer integer not null default 42;
comment on column migtest_e_history.test_string is 'Column altered to long now';
alter table migtest_e_history alter column test_string bigint;
comment on table migtest_e_history is 'We have history now';
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
alter table migtest_e_history2 alter column test_string set default 'unknown';
alter table migtest_e_history2 alter column test_string set not null;
alter table migtest_e_history2 add column test_string2 varchar(255);
alter table migtest_e_history2 add column test_string3 varchar(255) not null default 'unknown';
alter table migtest_e_history2_history add column test_string2 varchar(255);
alter table migtest_e_history2_history add column test_string3 varchar(255);
alter table migtest_e_softdelete add column deleted boolean not null default false;
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
drop index if exists ix_migtest_e_basic_indextest1;
@@ -6,3 +6,4 @@ alter table migtest_e_basic drop column old_boolean2;
alter table migtest_e_basic drop column eref_id;
drop table if exists migtest_e_ref;
drop sequence if exists migtest_e_ref_seq;
@@ -20,7 +20,10 @@ alter table migtest_e_basic add column old_boolean boolean not null default fals
alter table migtest_e_basic add column old_boolean2 boolean;
alter table migtest_e_basic add column eref_id integer;
comment on column migtest_e_history.test_string is 'DROP COMMENT';
comment on column migtest_e_history.test_string is '';
comment on table migtest_e_history is '';
alter table migtest_e_history2 alter column test_string drop default;
alter table migtest_e_history2 alter column test_string set null;
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
drop index if exists ix_migtest_e_basic_indextest3;
@@ -9,4 +9,13 @@ alter table migtest_e_basic drop column progress;
alter table migtest_e_basic drop column new_integer;
alter table migtest_e_history2 drop column test_string2;
alter table migtest_e_history2_history drop column test_string2;
alter table migtest_e_history2 drop column test_string3;
alter table migtest_e_history2_history drop column test_string3;
alter table migtest_e_softdelete drop column deleted;
drop table if exists migtest_e_user;
drop sequence if exists migtest_e_user_seq;
@@ -25,9 +25,17 @@
<column name="id" type="integer" primaryKey="true"/>
<column name="test_string" type="varchar"/>
</createTable>
<createTable name="migtest_e_history2" withHistory="true" pkName="pk_migtest_e_history2">
<column name="id" type="integer" primaryKey="true"/>
<column name="test_string" type="varchar"/>
</createTable>
<createTable name="migtest_e_ref" pkName="pk_migtest_e_ref">
<column name="id" type="integer" primaryKey="true"/>
</createTable>
<createTable name="migtest_e_softdelete" pkName="pk_migtest_e_softdelete">
<column name="id" type="integer" primaryKey="true"/>
<column name="test_string" type="varchar"/>
</createTable>
<createIndex indexName="ix_migtest_e_basic_indextest1" tableName="migtest_e_basic" columns="indextest1"/>
<createIndex indexName="ix_migtest_e_basic_indextest5" tableName="migtest_e_basic" columns="indextest5"/>
</changeSet>
@@ -24,6 +24,14 @@
<before platforms="postgres">alter table ${table} alter column ${column} TYPE bigint USING (${column}::integer)</before>
</alterColumn>
<addTableComment name="migtest_e_history" comment="We have history now"/>
<alterColumn columnName="test_string" tableName="migtest_e_history2" withHistory="true" currentType="varchar" defaultValue="'unknown'" notnull="true" currentNotnull="false"/>
<addColumn tableName="migtest_e_history2" withHistory="true">
<column name="test_string2" type="varchar"/>
<column name="test_string3" type="varchar" defaultValue="'unknown'" notnull="true"/>
</addColumn>
<addColumn tableName="migtest_e_softdelete">
<column name="deleted" type="boolean" defaultValue="false" notnull="true"/>
</addColumn>
<createTable name="migtest_e_user" pkName="pk_migtest_e_user">
<column name="id" type="integer" primaryKey="true"/>
</createTable>
@@ -36,6 +44,6 @@
<dropColumn columnName="old_boolean" tableName="migtest_e_basic"/>
<dropColumn columnName="old_boolean2" tableName="migtest_e_basic"/>
<dropColumn columnName="eref_id" tableName="migtest_e_basic"/>
<dropTable name="migtest_e_ref"/>
<dropTable name="migtest_e_ref" sequenceCol="id"/>
</changeSet>
</migration>
@@ -5,6 +5,6 @@
<dropColumn columnName="old_boolean" tableName="migtest_e_basic"/>
<dropColumn columnName="old_boolean2" tableName="migtest_e_basic"/>
<dropColumn columnName="eref_id" tableName="migtest_e_basic"/>
<dropTable name="migtest_e_ref"/>
<dropTable name="migtest_e_ref" sequenceCol="id"/>
</changeSet>
</migration>
@@ -12,7 +12,8 @@
<column name="eref_id" type="integer" references="migtest_e_ref.id" foreignKeyName="fk_migtest_e_basic_eref_id" foreignKeyIndex="ix_migtest_e_basic_eref_id"/>
</addColumn>
<alterColumn columnName="test_string" tableName="migtest_e_history" withHistory="true" comment="DROP COMMENT"/>
<addTableComment name="migtest_e_history"/>
<addTableComment name="migtest_e_history" comment="DROP COMMENT"/>
<alterColumn columnName="test_string" tableName="migtest_e_history2" withHistory="true" currentType="varchar" defaultValue="DROP DEFAULT" notnull="false" currentNotnull="true"/>
<createTable name="migtest_e_ref" pkName="pk_migtest_e_ref">
<column name="id" type="integer" primaryKey="true"/>
</createTable>
@@ -28,6 +29,9 @@
<dropColumn columnName="progress" tableName="migtest_e_basic"/>
<dropColumn columnName="new_integer" tableName="migtest_e_basic"/>
<dropHistoryTable baseTable="migtest_e_history"/>
<dropTable name="migtest_e_user"/>
<dropColumn columnName="test_string2" tableName="migtest_e_history2" withHistory="true"/>
<dropColumn columnName="test_string3" tableName="migtest_e_history2" withHistory="true"/>
<dropColumn columnName="deleted" tableName="migtest_e_softdelete"/>
<dropTable name="migtest_e_user" sequenceCol="id"/>
</changeSet>
</migration>
@@ -8,6 +8,9 @@
<dropColumn columnName="progress" tableName="migtest_e_basic"/>
<dropColumn columnName="new_integer" tableName="migtest_e_basic"/>
<dropHistoryTable baseTable="migtest_e_history"/>
<dropTable name="migtest_e_user"/>
<dropColumn columnName="test_string2" tableName="migtest_e_history2" withHistory="true"/>
<dropColumn columnName="test_string3" tableName="migtest_e_history2" withHistory="true"/>
<dropColumn columnName="deleted" tableName="migtest_e_softdelete"/>
<dropTable name="migtest_e_user" sequenceCol="id"/>
</changeSet>
</migration>
@@ -27,13 +27,44 @@ create table migtest_e_history (
constraint pk_migtest_e_history primary key (id)
);
create table migtest_e_history2 (
id integer auto_increment not null,
test_string varchar(255),
constraint pk_migtest_e_history2 primary key (id)
);
create table migtest_e_ref (
id integer auto_increment not null,
constraint pk_migtest_e_ref primary key (id)
);
create table migtest_e_softdelete (
id integer auto_increment not null,
test_string varchar(255),
constraint pk_migtest_e_softdelete primary key (id)
);
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
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_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
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);
create table migtest_e_history2_history(
id integer,
test_string varchar(255),
sys_period_start datetime(6),
sys_period_end datetime(6)
);
create view migtest_e_history2_with_history as select * from migtest_e_history2 union all select * from migtest_e_history2_history;
delimiter $$
create trigger migtest_e_history2_history_upd before update on migtest_e_history2 for each row begin
insert into migtest_e_history2_history (sys_period_start,sys_period_end,id, test_string) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string);
set NEW.sys_period_start = now(6);
end$$
delimiter $$
create trigger migtest_e_history2_history_del before delete on migtest_e_history2 for each row begin
insert into migtest_e_history2_history (sys_period_start,sys_period_end,id, test_string) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string);
end$$
@@ -32,6 +32,17 @@ alter table migtest_e_basic add column new_integer integer not null default 42;
comment on column migtest_e_history.test_string is 'Column altered to long now';
alter table migtest_e_history modify test_string bigint;
alter table migtest_e_history comment = 'We have history now';
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
alter table migtest_e_history2 alter test_string set default 'unknown';
alter table migtest_e_history2 modify test_string varchar(255) not null;
alter table migtest_e_history2 add column test_string2 varchar(255);
alter table migtest_e_history2 add column test_string3 varchar(255) not null default 'unknown';
alter table migtest_e_history2_history add column test_string2 varchar(255);
alter table migtest_e_history2_history add column test_string3 varchar(255);
alter table migtest_e_softdelete add column deleted tinyint(1) default 0 not null;
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
drop index ix_migtest_e_basic_indextest1 on migtest_e_basic;
@@ -55,3 +66,17 @@ delimiter $$
create trigger migtest_e_history_history_del before delete on migtest_e_history for each row begin
insert into migtest_e_history_history (sys_period_start,sys_period_end,id, test_string) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string);
end$$
-- changes: [add test_string2, add test_string3]
lock tables migtest_e_history2 write;
drop trigger migtest_e_history2_history_upd;
drop trigger migtest_e_history2_history_del;
delimiter $$
create trigger migtest_e_history2_history_upd before update on migtest_e_history2 for each row begin
insert into migtest_e_history2_history (sys_period_start,sys_period_end,id, test_string, test_string2, test_string3) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string, OLD.test_string2, OLD.test_string3);
set NEW.sys_period_start = now(6);
end$$
delimiter $$
create trigger migtest_e_history2_history_del before delete on migtest_e_history2 for each row begin
insert into migtest_e_history2_history (sys_period_start,sys_period_end,id, test_string, test_string2, test_string3) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string, OLD.test_string2, OLD.test_string3);
end$$
unlock tables;
@@ -17,7 +17,9 @@ alter table migtest_e_basic add column old_boolean tinyint(1) default 0 not null
alter table migtest_e_basic add column old_boolean2 tinyint(1) default 0;
alter table migtest_e_basic add column eref_id integer;
comment on column migtest_e_history.test_string is 'DROP COMMENT';
comment on column migtest_e_history.test_string is '';
alter table migtest_e_history comment = 'DROP COMMENT';
alter table migtest_e_history2 alter test_string drop default;
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
drop index ix_migtest_e_basic_indextest3 on migtest_e_basic;
@@ -18,4 +18,26 @@ alter table migtest_e_basic drop column progress;
alter table migtest_e_basic drop column new_integer;
alter table migtest_e_history2 drop column test_string2;
alter table migtest_e_history2_history drop column test_string2;
alter table migtest_e_history2 drop column test_string3;
alter table migtest_e_history2_history drop column test_string3;
alter table migtest_e_softdelete drop column deleted;
drop table if exists migtest_e_user;
-- changes: [drop test_string2, drop test_string3]
lock tables migtest_e_history2 write;
drop trigger migtest_e_history2_history_upd;
drop trigger migtest_e_history2_history_del;
delimiter $$
create trigger migtest_e_history2_history_upd before update on migtest_e_history2 for each row begin
insert into migtest_e_history2_history (sys_period_start,sys_period_end,id, test_string) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string);
set NEW.sys_period_start = now(6);
end$$
delimiter $$
create trigger migtest_e_history2_history_del before delete on migtest_e_history2 for each row begin
insert into migtest_e_history2_history (sys_period_start,sys_period_end,id, test_string) values (OLD.sys_period_start, now(6),OLD.id, OLD.test_string);
end$$
unlock tables;
@@ -29,12 +29,26 @@ create table migtest_e_history (
);
create sequence migtest_e_history_seq;
create table migtest_e_history2 (
id number(10) not null,
test_string varchar2(255),
constraint pk_migtest_e_history2 primary key (id)
);
create sequence migtest_e_history2_seq;
create table migtest_e_ref (
id number(10) not null,
constraint pk_migtest_e_ref primary key (id)
);
create sequence migtest_e_ref_seq;
create table migtest_e_softdelete (
id number(10) not null,
test_string varchar2(255),
constraint pk_migtest_e_softdelete primary key (id)
);
create sequence migtest_e_softdelete_seq;
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id);
@@ -34,6 +34,15 @@ alter table migtest_e_basic add column new_integer number(10) not null default 4
comment on column migtest_e_history.test_string is 'Column altered to long now';
alter table migtest_e_history modify test_string number(19);
comment on table migtest_e_history is 'We have history now';
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
alter table migtest_e_history2 modify test_string default 'unknown';
alter table migtest_e_history2 modify test_string not null;
alter table migtest_e_history2 add column test_string2 varchar2(255);
alter table migtest_e_history2 add column test_string3 varchar2(255) not null default 'unknown';
alter table migtest_e_softdelete add column deleted number(1) default 0 not null;
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
drop index ix_migtest_e_basic_indextest1;
@@ -6,3 +6,4 @@ alter table migtest_e_basic drop column old_boolean2;
alter table migtest_e_basic drop column eref_id;
drop table migtest_e_ref cascade constraints purge;
drop sequence migtest_e_ref_seq;
@@ -21,7 +21,10 @@ alter table migtest_e_basic add column old_boolean number(1) default 0 not null;
alter table migtest_e_basic add column old_boolean2 number(1) default 0;
alter table migtest_e_basic add column eref_id number(10);
comment on column migtest_e_history.test_string is 'DROP COMMENT';
comment on column migtest_e_history.test_string is '';
comment on table migtest_e_history is '';
alter table migtest_e_history2 modify test_string drop default;
alter table migtest_e_history2 modify test_string null;
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
drop index ix_migtest_e_basic_indextest3;
@@ -9,4 +9,11 @@ alter table migtest_e_basic drop column progress;
alter table migtest_e_basic drop column new_integer;
alter table migtest_e_history2 drop column test_string2;
alter table migtest_e_history2 drop column test_string3;
alter table migtest_e_softdelete drop column deleted;
drop table migtest_e_user cascade constraints purge;
drop sequence migtest_e_user_seq;
@@ -27,13 +27,46 @@ create table migtest_e_history (
constraint pk_migtest_e_history primary key (id)
);
create table migtest_e_history2 (
id serial not null,
test_string varchar(255),
constraint pk_migtest_e_history2 primary key (id)
);
create table migtest_e_ref (
id serial not null,
constraint pk_migtest_e_ref primary key (id)
);
create table migtest_e_softdelete (
id serial not null,
test_string varchar(255),
constraint pk_migtest_e_softdelete primary key (id)
);
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
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_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
alter table migtest_e_history2 add column sys_period tstzrange not null default tstzrange(current_timestamp, null);
create table migtest_e_history2_history(like migtest_e_history2);
create view migtest_e_history2_with_history as select * from migtest_e_history2 union all select * from migtest_e_history2_history;
create or replace function migtest_e_history2_history_version() returns trigger as $$
begin
if (TG_OP = 'UPDATE') then
insert into migtest_e_history2_history (sys_period,id, test_string) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string);
NEW.sys_period = tstzrange(current_timestamp,null);
return new;
elsif (TG_OP = 'DELETE') then
insert into migtest_e_history2_history (sys_period,id, test_string) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string);
return old;
end if;
end;
$$ LANGUAGE plpgsql;
create trigger migtest_e_history2_history_upd
before update or delete on migtest_e_history2
for each row execute procedure migtest_e_history2_history_version();
@@ -1,3 +1,6 @@
-- drop dependencies
drop view if exists migtest_e_history2_with_history;
-- apply changes
create table migtest_e_user (
id serial not null,
@@ -35,6 +38,17 @@ alter table migtest_e_history alter column test_string TYPE bigint USING (test_s
comment on column migtest_e_history.test_string is 'Column altered to long now';
alter table migtest_e_history alter column test_string type bigint;
comment on table migtest_e_history is 'We have history now';
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
alter table migtest_e_history2 alter column test_string set default 'unknown';
alter table migtest_e_history2 alter column test_string set not null;
alter table migtest_e_history2 add column test_string2 varchar(255);
alter table migtest_e_history2 add column test_string3 varchar(255) not null default 'unknown';
alter table migtest_e_history2_history add column test_string2 varchar(255);
alter table migtest_e_history2_history add column test_string3 varchar(255);
alter table migtest_e_softdelete add column deleted boolean not null default false;
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
drop index if exists ix_migtest_e_basic_indextest1;
@@ -60,3 +74,19 @@ create trigger migtest_e_history_history_upd
before update or delete on migtest_e_history
for each row execute procedure migtest_e_history_history_version();
-- changes: [add test_string2, add test_string3]
create or replace view migtest_e_history2_with_history as select id, test_string, test_string2, test_string3, sys_period from migtest_e_history2 union all select id, test_string, test_string2, test_string3, sys_period from migtest_e_history2_history;
create or replace function migtest_e_history2_history_version() returns trigger as $$
begin
if (TG_OP = 'UPDATE') then
insert into migtest_e_history2_history (sys_period,id, test_string, test_string2, test_string3) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string, OLD.test_string2, OLD.test_string3);
NEW.sys_period = tstzrange(current_timestamp,null);
return new;
elsif (TG_OP = 'DELETE') then
insert into migtest_e_history2_history (sys_period,id, test_string, test_string2, test_string3) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string, OLD.test_string2, OLD.test_string3);
return old;
end if;
end;
$$ LANGUAGE plpgsql;
@@ -6,3 +6,4 @@ alter table migtest_e_basic drop column old_boolean2;
alter table migtest_e_basic drop column eref_id;
drop table if exists migtest_e_ref cascade;
drop sequence if exists migtest_e_ref_seq;
@@ -20,7 +20,10 @@ alter table migtest_e_basic add column old_boolean boolean not null default fals
alter table migtest_e_basic add column old_boolean2 boolean;
alter table migtest_e_basic add column eref_id integer;
comment on column migtest_e_history.test_string is 'DROP COMMENT';
comment on column migtest_e_history.test_string is '';
comment on table migtest_e_history is '';
alter table migtest_e_history2 alter column test_string drop default;
alter table migtest_e_history2 alter column test_string drop not null;
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
drop index if exists ix_migtest_e_basic_indextest3;
@@ -6,6 +6,7 @@ drop view migtest_e_history_with_history;
alter table migtest_e_history drop column sys_period;
drop table migtest_e_history_history;
drop view if exists migtest_e_history2_with_history;
-- apply changes
alter table migtest_e_basic drop column new_string_field;
@@ -18,4 +19,29 @@ alter table migtest_e_basic drop column progress;
alter table migtest_e_basic drop column new_integer;
alter table migtest_e_history2 drop column test_string2;
alter table migtest_e_history2_history drop column test_string2;
alter table migtest_e_history2 drop column test_string3;
alter table migtest_e_history2_history drop column test_string3;
alter table migtest_e_softdelete drop column deleted;
drop table if exists migtest_e_user cascade;
drop sequence if exists migtest_e_user_seq;
-- changes: [drop test_string2, drop test_string3]
create or replace view migtest_e_history2_with_history as select id, test_string, sys_period from migtest_e_history2 union all select id, test_string, sys_period from migtest_e_history2_history;
create or replace function migtest_e_history2_history_version() returns trigger as $$
begin
if (TG_OP = 'UPDATE') then
insert into migtest_e_history2_history (sys_period,id, test_string) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string);
NEW.sys_period = tstzrange(current_timestamp,null);
return new;
elsif (TG_OP = 'DELETE') then
insert into migtest_e_history2_history (sys_period,id, test_string) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string);
return old;
end if;
end;
$$ LANGUAGE plpgsql;
@@ -28,10 +28,22 @@ create table migtest_e_history (
constraint pk_migtest_e_history primary key (id)
);
create table migtest_e_history2 (
id integer not null,
test_string varchar(255),
constraint pk_migtest_e_history2 primary key (id)
);
create table migtest_e_ref (
id integer not null,
constraint pk_migtest_e_ref primary key (id)
);
create table migtest_e_softdelete (
id integer not null,
test_string varchar(255),
constraint pk_migtest_e_softdelete primary key (id)
);
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
@@ -30,6 +30,17 @@ alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( p
alter table migtest_e_basic add column new_integer integer not null default 42;
alter table migtest_e_history alter column test_string integer;
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
alter table migtest_e_history2 alter column test_string set default 'unknown';
alter table migtest_e_history2 alter column test_string set not null;
alter table migtest_e_history2 add column test_string2 varchar(255);
alter table migtest_e_history2 add column test_string3 varchar(255) not null default 'unknown';
alter table migtest_e_history2_history add column test_string2 varchar(255);
alter table migtest_e_history2_history add column test_string3 varchar(255);
alter table migtest_e_softdelete add column deleted int default 0 not null;
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
drop index if exists ix_migtest_e_basic_indextest1;
@@ -20,6 +20,8 @@ alter table migtest_e_basic add column old_boolean int default 0 not null;
alter table migtest_e_basic add column old_boolean2 int default 0;
alter table migtest_e_basic add column eref_id integer;
alter table migtest_e_history2 alter column test_string drop default;
alter table migtest_e_history2 alter column test_string set null;
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
drop index if exists ix_migtest_e_basic_indextest3;
@@ -9,4 +9,12 @@ alter table migtest_e_basic drop column progress;
alter table migtest_e_basic drop column new_integer;
alter table migtest_e_history2 drop column test_string2;
alter table migtest_e_history2_history drop column test_string2;
alter table migtest_e_history2 drop column test_string3;
alter table migtest_e_history2_history drop column test_string3;
alter table migtest_e_softdelete drop column deleted;
drop table if exists migtest_e_user;
@@ -27,13 +27,30 @@ create table migtest_e_history (
constraint pk_migtest_e_history primary key (id)
);
create table migtest_e_history2 (
id integer identity(1,1) not null,
test_string varchar(255),
constraint pk_migtest_e_history2 primary key (id)
);
create table migtest_e_ref (
id integer identity(1,1) not null,
constraint pk_migtest_e_ref primary key (id)
);
create table migtest_e_softdelete (
id integer identity(1,1) not null,
test_string varchar(255),
constraint pk_migtest_e_softdelete primary key (id)
);
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
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_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
alter table migtest_e_history2
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 migtest_e_history2 set (system_versioning = on (history_table=dbo.migtest_e_history2_history));
@@ -6,8 +6,8 @@ create table migtest_e_user (
update migtest_e_basic set status = 'A' where status is null;
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
alter table migtest_e_basic add constraint df_migtest_e_basic_status default 'A' for status;
IF (OBJECT_ID('ck_migtest_e_basic_status', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
alter table migtest_e_basic add default 'A' for status;
alter table migtest_e_basic alter column status varchar(1) not null;
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?'));
@@ -15,7 +15,7 @@ alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( sta
create unique nonclustered index uq_migtest_e_basic_description on migtest_e_basic(description) where description is not null;
update migtest_e_basic set some_date = '2000-01-01T00:00:00' where some_date is null;
alter table migtest_e_basic add constraint df_migtest_e_basic_some_date default '2000-01-01T00:00:00' for some_date;
alter table migtest_e_basic add default '2000-01-01T00:00:00' for some_date;
alter table migtest_e_basic alter column some_date datetime2 not null;
insert into migtest_e_user (id) select distinct user_id from migtest_e_basic;
@@ -31,6 +31,15 @@ alter table migtest_e_basic add constraint ck_migtest_e_basic_progress check ( p
alter table migtest_e_basic add new_integer integer not null default 42;
alter table migtest_e_history alter column test_string numeric(19);
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
alter table migtest_e_history2 add default 'unknown' for test_string;
alter table migtest_e_history2 alter column test_string varchar(255) not null;
alter table migtest_e_history2 add test_string2 varchar(255);
alter table migtest_e_history2 add test_string3 varchar(255) not null default 'unknown';
alter table migtest_e_softdelete add deleted bit default 0 not null;
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_indextest1') drop index ix_migtest_e_basic_indextest1 ON migtest_e_basic;
@@ -1,8 +1,41 @@
-- apply changes
-- drop column migtest_e_basic.old_boolean;
IF (OBJECT_ID('uq_migtest_e_basic_old_boolean', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_old_boolean;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_old_boolean') drop index uq_migtest_e_basic_old_boolean ON migtest_e_basic;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'old_boolean';
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
IF (OBJECT_ID('ck_migtest_e_basic_old_boolean', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_old_boolean;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_old_boolean') drop index ix_migtest_e_basic_old_boolean ON migtest_e_basic;
IF OBJECT_ID('fk_migtest_e_basic_old_boolean', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_old_boolean;
alter table migtest_e_basic drop column old_boolean;
-- drop column migtest_e_basic.old_boolean2;
IF (OBJECT_ID('uq_migtest_e_basic_old_boolean2', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_old_boolean2;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_old_boolean2') drop index uq_migtest_e_basic_old_boolean2 ON migtest_e_basic;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'old_boolean2';
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
IF (OBJECT_ID('ck_migtest_e_basic_old_boolean2', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_old_boolean2;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_old_boolean2') drop index ix_migtest_e_basic_old_boolean2 ON migtest_e_basic;
IF OBJECT_ID('fk_migtest_e_basic_old_boolean2', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_old_boolean2;
alter table migtest_e_basic drop column old_boolean2;
-- drop column migtest_e_basic.eref_id;
IF (OBJECT_ID('uq_migtest_e_basic_eref_id', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_eref_id;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_eref_id') drop index uq_migtest_e_basic_eref_id ON migtest_e_basic;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'eref_id';
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
IF (OBJECT_ID('ck_migtest_e_basic_eref_id', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_eref_id;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_eref_id') drop index ix_migtest_e_basic_eref_id ON migtest_e_basic;
IF OBJECT_ID('fk_migtest_e_basic_eref_id', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_eref_id;
alter table migtest_e_basic drop column eref_id;
IF OBJECT_ID('migtest_e_ref', 'U') IS NOT NULL drop table migtest_e_ref;
@@ -4,20 +4,34 @@ create table migtest_e_ref (
constraint pk_migtest_e_ref primary key (id)
);
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
alter table migtest_e_basic drop constraint df_migtest_e_basic_status;
IF (OBJECT_ID('ck_migtest_e_basic_status', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'status';
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I'));
alter table migtest_e_basic drop constraint uq_migtest_e_basic_description;
alter table migtest_e_basic drop constraint df_migtest_e_basic_some_date;
IF (OBJECT_ID('uq_migtest_e_basic_description', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_description;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_description') drop index uq_migtest_e_basic_description ON migtest_e_basic;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'some_date';
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
update migtest_e_basic set user_id = 23 where user_id is null;
IF OBJECT_ID('fk_migtest_e_basic_user_id', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_user_id;
alter table migtest_e_basic add constraint df_migtest_e_basic_user_id default 23 for user_id;
alter table migtest_e_basic add default 23 for user_id;
alter table migtest_e_basic alter column user_id integer not null;
alter table migtest_e_basic add old_boolean bit default 0 not null;
alter table migtest_e_basic add old_boolean2 bit default 0;
alter table migtest_e_basic add eref_id integer;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_history2') and t2.name = 'test_string';
if @Tmp is not null EXEC('alter table migtest_e_history2 drop constraint ' + @Tmp)$$;
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_indextest3') drop index ix_migtest_e_basic_indextest3 ON migtest_e_basic;
@@ -1,15 +1,123 @@
-- apply changes
-- drop column migtest_e_basic.new_string_field;
IF (OBJECT_ID('uq_migtest_e_basic_new_string_field', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_new_string_field;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_new_string_field') drop index uq_migtest_e_basic_new_string_field ON migtest_e_basic;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'new_string_field';
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
IF (OBJECT_ID('ck_migtest_e_basic_new_string_field', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_new_string_field;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_new_string_field') drop index ix_migtest_e_basic_new_string_field ON migtest_e_basic;
IF OBJECT_ID('fk_migtest_e_basic_new_string_field', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_new_string_field;
alter table migtest_e_basic drop column new_string_field;
-- drop column migtest_e_basic.new_boolean_field;
IF (OBJECT_ID('uq_migtest_e_basic_new_boolean_field', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_new_boolean_field;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_new_boolean_field') drop index uq_migtest_e_basic_new_boolean_field ON migtest_e_basic;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'new_boolean_field';
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
IF (OBJECT_ID('ck_migtest_e_basic_new_boolean_field', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_new_boolean_field;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_new_boolean_field') drop index ix_migtest_e_basic_new_boolean_field ON migtest_e_basic;
IF OBJECT_ID('fk_migtest_e_basic_new_boolean_field', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_new_boolean_field;
alter table migtest_e_basic drop column new_boolean_field;
-- drop column migtest_e_basic.new_boolean_field2;
IF (OBJECT_ID('uq_migtest_e_basic_new_boolean_field2', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_new_boolean_field2;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_new_boolean_field2') drop index uq_migtest_e_basic_new_boolean_field2 ON migtest_e_basic;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'new_boolean_field2';
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
IF (OBJECT_ID('ck_migtest_e_basic_new_boolean_field2', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_new_boolean_field2;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_new_boolean_field2') drop index ix_migtest_e_basic_new_boolean_field2 ON migtest_e_basic;
IF OBJECT_ID('fk_migtest_e_basic_new_boolean_field2', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_new_boolean_field2;
alter table migtest_e_basic drop column new_boolean_field2;
-- drop column migtest_e_basic.progress;
IF (OBJECT_ID('uq_migtest_e_basic_progress', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_progress;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_progress') drop index uq_migtest_e_basic_progress ON migtest_e_basic;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'progress';
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
IF (OBJECT_ID('ck_migtest_e_basic_progress', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_progress;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_progress') drop index ix_migtest_e_basic_progress ON migtest_e_basic;
IF OBJECT_ID('fk_migtest_e_basic_progress', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_progress;
alter table migtest_e_basic drop column progress;
-- drop column migtest_e_basic.new_integer;
IF (OBJECT_ID('uq_migtest_e_basic_new_integer', 'UQ') IS NOT NULL) alter table migtest_e_basic drop constraint uq_migtest_e_basic_new_integer;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_new_integer') drop index uq_migtest_e_basic_new_integer ON migtest_e_basic;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_basic') and t2.name = 'new_integer';
if @Tmp is not null EXEC('alter table migtest_e_basic drop constraint ' + @Tmp)$$;
IF (OBJECT_ID('ck_migtest_e_basic_new_integer', 'C') IS NOT NULL) alter table migtest_e_basic drop constraint ck_migtest_e_basic_new_integer;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'ix_migtest_e_basic_new_integer') drop index ix_migtest_e_basic_new_integer ON migtest_e_basic;
IF OBJECT_ID('fk_migtest_e_basic_new_integer', 'F') IS NOT NULL alter table migtest_e_basic drop constraint fk_migtest_e_basic_new_integer;
alter table migtest_e_basic drop column new_integer;
-- drop column migtest_e_history2.test_string2;
IF (OBJECT_ID('uq_migtest_e_history2_test_string2', 'UQ') IS NOT NULL) alter table migtest_e_history2 drop constraint uq_migtest_e_history2_test_string2;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_history2','U') AND name = 'uq_migtest_e_history2_test_string2') drop index uq_migtest_e_history2_test_string2 ON migtest_e_history2;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_history2') and t2.name = 'test_string2';
if @Tmp is not null EXEC('alter table migtest_e_history2 drop constraint ' + @Tmp)$$;
IF (OBJECT_ID('ck_migtest_e_history2_test_string2', 'C') IS NOT NULL) alter table migtest_e_history2 drop constraint ck_migtest_e_history2_test_string2;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_history2','U') AND name = 'ix_migtest_e_history2_test_string2') drop index ix_migtest_e_history2_test_string2 ON migtest_e_history2;
IF OBJECT_ID('fk_migtest_e_history2_test_string2', 'F') IS NOT NULL alter table migtest_e_history2 drop constraint fk_migtest_e_history2_test_string2;
alter table migtest_e_history2 drop column test_string2;
-- drop column migtest_e_history2.test_string3;
IF (OBJECT_ID('uq_migtest_e_history2_test_string3', 'UQ') IS NOT NULL) alter table migtest_e_history2 drop constraint uq_migtest_e_history2_test_string3;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_history2','U') AND name = 'uq_migtest_e_history2_test_string3') drop index uq_migtest_e_history2_test_string3 ON migtest_e_history2;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_history2') and t2.name = 'test_string3';
if @Tmp is not null EXEC('alter table migtest_e_history2 drop constraint ' + @Tmp)$$;
IF (OBJECT_ID('ck_migtest_e_history2_test_string3', 'C') IS NOT NULL) alter table migtest_e_history2 drop constraint ck_migtest_e_history2_test_string3;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_history2','U') AND name = 'ix_migtest_e_history2_test_string3') drop index ix_migtest_e_history2_test_string3 ON migtest_e_history2;
IF OBJECT_ID('fk_migtest_e_history2_test_string3', 'F') IS NOT NULL alter table migtest_e_history2 drop constraint fk_migtest_e_history2_test_string3;
alter table migtest_e_history2 drop column test_string3;
-- drop column migtest_e_softdelete.deleted;
IF (OBJECT_ID('uq_migtest_e_softdelete_deleted', 'UQ') IS NOT NULL) alter table migtest_e_softdelete drop constraint uq_migtest_e_softdelete_deleted;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_softdelete','U') AND name = 'uq_migtest_e_softdelete_deleted') drop index uq_migtest_e_softdelete_deleted ON migtest_e_softdelete;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_softdelete') and t2.name = 'deleted';
if @Tmp is not null EXEC('alter table migtest_e_softdelete drop constraint ' + @Tmp)$$;
IF (OBJECT_ID('ck_migtest_e_softdelete_deleted', 'C') IS NOT NULL) alter table migtest_e_softdelete drop constraint ck_migtest_e_softdelete_deleted;
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_softdelete','U') AND name = 'ix_migtest_e_softdelete_deleted') drop index ix_migtest_e_softdelete_deleted ON migtest_e_softdelete;
IF OBJECT_ID('fk_migtest_e_softdelete_deleted', 'F') IS NOT NULL alter table migtest_e_softdelete drop constraint fk_migtest_e_softdelete_deleted;
alter table migtest_e_softdelete drop column deleted;
IF OBJECT_ID('migtest_e_user', 'U') IS NOT NULL drop table migtest_e_user;
-- dropping history support for migtest_e_history;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_history') and t2.name = 'sys_periodFrom';
if @Tmp is not null EXEC('alter table migtest_e_history drop constraint ' + @Tmp)$$;
delimiter $$
DECLARE @Tmp nvarchar(200);select @Tmp = t1.name from sys.default_constraints t1
join sys.columns t2 on t1.object_id = t2.default_object_id
where t1.parent_object_id = OBJECT_ID('migtest_e_history') and t2.name = 'sys_periodTo';
if @Tmp is not null EXEC('alter table migtest_e_history drop constraint ' + @Tmp)$$;
alter table migtest_e_history set (system_versioning = off);
alter table migtest_e_history drop period for system_time;
alter table migtest_e_history drop column sys_periodFrom;
alter table migtest_e_history drop column sys_periodTo;
IF OBJECT_ID('migtest_e_history_history', 'U') IS NOT NULL drop table migtest_e_history_history;