mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 01:44:38 +00:00
Migration enum drop check constraints (#1435)
* Fix: apply drop checkConstraints properly which were not applied for Enum to String * Use IF EXISTS to drop constraints * added TODO and comment about MariaDB supporting CHECK constraints from version 10.2.1 forward compared to MySQL 5.7/8.0 parsing but ignoring CHECK constraints * updated reference scripts for dropping constraints on enums
This commit is contained in:
committed by
Rob Bygrave
parent
48b05eb358
commit
cf2d9df256
@@ -840,12 +840,15 @@ public class BaseTableDdl implements TableDdl {
|
||||
if (hasValue(alterColumn.getComment())) {
|
||||
alterColumnComment(writer, alterColumn);
|
||||
}
|
||||
if (hasValue(alterColumn.getDropCheckConstraint())) {
|
||||
dropCheckConstraint(writer, alterColumn, alterColumn.getDropCheckConstraint());
|
||||
}
|
||||
|
||||
boolean alterCheckConstraint = hasValue(alterColumn.getCheckConstraint());
|
||||
|
||||
if (alterCheckConstraint) {
|
||||
// drop constraint before altering type etc
|
||||
dropCheckConstraint(writer, alterColumn);
|
||||
dropCheckConstraint(writer, alterColumn, alterColumn.getCheckConstraintName());
|
||||
}
|
||||
boolean alterBaseAttributes = false;
|
||||
if (hasValue(alterColumn.getType())) {
|
||||
@@ -922,9 +925,9 @@ public class BaseTableDdl implements TableDdl {
|
||||
}
|
||||
}
|
||||
|
||||
protected void dropCheckConstraint(DdlWrite writer, AlterColumn alter) throws IOException {
|
||||
protected void dropCheckConstraint(DdlWrite writer, AlterColumn alter, String constraintName) throws IOException {
|
||||
|
||||
String ddl = platformDdl.alterTableDropConstraint(alter.getTableName(), alter.getCheckConstraintName());
|
||||
String ddl = platformDdl.alterTableDropConstraint(alter.getTableName(), constraintName);
|
||||
if (hasValue(ddl)) {
|
||||
writer.apply().append(ddl).endOfStatement();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ public class MySqlDdl extends PlatformDdl {
|
||||
|
||||
@Override
|
||||
public String alterTableDropConstraint(String tableName, String constraintName) {
|
||||
// drop constraint not supported
|
||||
// drop constraint not supported in MySQL 5.7 and 8.0 but starting with MariaDB 10.2.1 CHECK is evaluated
|
||||
// TODO: Implement for MariaDB >= 10.2.1
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,8 +79,6 @@ public class PlatformDdl {
|
||||
|
||||
protected String alterColumn = "alter column";
|
||||
|
||||
protected String dropConstraint = "drop constraint";
|
||||
|
||||
protected String dropUniqueConstraint = "drop constraint";
|
||||
|
||||
protected String addConstraint = "add constraint";
|
||||
@@ -420,7 +418,7 @@ public class PlatformDdl {
|
||||
* Drop a unique constraint from the table.
|
||||
*/
|
||||
public String alterTableDropConstraint(String tableName, String constraintName) {
|
||||
return "alter table " + tableName + " " + dropConstraint + " " + maxConstraintName(constraintName);
|
||||
return "alter table " + tableName + " " + dropConstraintIfExists + " " + maxConstraintName(constraintName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,6 +61,7 @@ public class DbMigrationTest extends BaseTestCase {
|
||||
"migtest_ckey_detail",
|
||||
"migtest_ckey_parent",
|
||||
"migtest_e_basic",
|
||||
"migtest_e_enum",
|
||||
"migtest_e_history",
|
||||
"migtest_e_history2",
|
||||
"migtest_e_history3",
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class BaseTableDdlTest {
|
||||
ddlGen.generate(write, alterColumn);
|
||||
|
||||
String ddl = write.apply().getBuffer();
|
||||
assertThat(ddl).contains("alter table mytab drop constraint ck_mytab_acol");
|
||||
assertThat(ddl).contains("alter table mytab drop constraint if exists ck_mytab_acol");
|
||||
assertThat(ddl).contains("alter table mytab add constraint ck_mytab_acol check (acol in ('A','B'))");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package misc.migration.v1_0;
|
||||
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import io.ebean.annotation.EnumValue;
|
||||
|
||||
@Entity
|
||||
@Table(name = "migtest_e_enum")
|
||||
public class EEnum {
|
||||
|
||||
public enum Status {
|
||||
@EnumValue("N")
|
||||
NEW,
|
||||
|
||||
@EnumValue("A")
|
||||
ACTIVE,
|
||||
|
||||
@EnumValue("I")
|
||||
INACTIVE,
|
||||
}
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
Status testStatus;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package misc.migration.v1_1;
|
||||
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@Entity
|
||||
@Table(name = "migtest_e_enum")
|
||||
public class EEnum {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
@Size (max = 1)
|
||||
String testStatus; // change to String from Enum Status
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package misc.migration.v1_2;
|
||||
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import io.ebean.annotation.EnumValue;
|
||||
|
||||
@Entity
|
||||
@Table(name = "migtest_e_enum")
|
||||
public class EEnum {
|
||||
|
||||
public enum Status {
|
||||
@EnumValue("N")
|
||||
NEW,
|
||||
|
||||
@EnumValue("A")
|
||||
ACTIVE,
|
||||
|
||||
@EnumValue("I")
|
||||
INACTIVE,
|
||||
}
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
Status testStatus;
|
||||
}
|
||||
@@ -76,6 +76,13 @@ create table migtest_e_basic (
|
||||
-- NOT SUPPORTED alter table migtest_e_basic add constraint uq_mgtst__b_4aybzy unique (indextest2);
|
||||
-- NOT SUPPORTED alter table migtest_e_basic add constraint uq_mgtst__b_4ayc02 unique (indextest6);
|
||||
|
||||
create table migtest_e_enum (
|
||||
id integer generated by default as identity not null,
|
||||
test_status varchar(1),
|
||||
constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')),
|
||||
constraint pk_migtest_e_enum primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history (
|
||||
id integer generated by default as identity not null,
|
||||
test_string varchar(255),
|
||||
|
||||
@@ -61,6 +61,7 @@ alter table migtest_e_basic drop constraint uq_mgtst__b_4ayc02;
|
||||
-- NOT SUPPORTED alter table migtest_e_basic add constraint uq_mgtst__bsc_nm unique (name);
|
||||
-- NOT SUPPORTED alter table migtest_e_basic add constraint uq_mgtst__b_4ayc00 unique (indextest4);
|
||||
-- NOT SUPPORTED alter table migtest_e_basic add constraint uq_mgtst__b_4ayc01 unique (indextest5);
|
||||
alter table migtest_e_enum drop constraint ck_mgtst__n_773sok;
|
||||
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';
|
||||
|
||||
@@ -36,6 +36,8 @@ alter table migtest_e_basic drop constraint uq_mgtst__b_4ayc00;
|
||||
alter table migtest_e_basic drop constraint uq_mgtst__b_4ayc01;
|
||||
-- NOT SUPPORTED alter table migtest_e_basic add constraint uq_mgtst__b_4aybzy unique (indextest2);
|
||||
-- NOT SUPPORTED alter table migtest_e_basic add constraint uq_mgtst__b_4ayc02 unique (indextest6);
|
||||
alter table migtest_e_enum drop constraint ck_mgtst__n_773sok;
|
||||
alter table migtest_e_enum add constraint ck_mgtst__n_773sok check ( test_status in ('N','A','I'));
|
||||
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;
|
||||
|
||||
@@ -76,6 +76,13 @@ create table migtest_e_basic (
|
||||
constraint pk_migtest_e_basic primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_enum (
|
||||
id integer auto_increment not null,
|
||||
test_status varchar(1),
|
||||
constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')),
|
||||
constraint pk_migtest_e_enum primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history (
|
||||
id integer auto_increment not null,
|
||||
test_string varchar(255),
|
||||
|
||||
@@ -37,7 +37,7 @@ alter table migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null
|
||||
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 restrict on update restrict;
|
||||
|
||||
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 drop constraint if exists ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic alter column status set default 'A';
|
||||
alter table migtest_e_basic alter column status set not null;
|
||||
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?'));
|
||||
@@ -67,6 +67,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 migtest_e_enum drop constraint if exists ck_migtest_e_enum_test_status;
|
||||
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';
|
||||
|
||||
@@ -19,7 +19,7 @@ alter table migtest_fk_none drop constraint if exists fk_migtest_fk_none_one_id;
|
||||
alter table migtest_fk_none_via_join drop constraint if exists fk_migtest_fk_none_via_join_one_id;
|
||||
alter table migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
|
||||
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 set null;
|
||||
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic drop constraint if exists ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic alter column status drop default;
|
||||
alter table migtest_e_basic alter column status set null;
|
||||
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I'));
|
||||
@@ -41,6 +41,8 @@ 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_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
|
||||
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
|
||||
alter table migtest_e_enum drop constraint if exists ck_migtest_e_enum_test_status;
|
||||
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 '';
|
||||
alter table migtest_e_history2 alter column test_string drop default;
|
||||
|
||||
@@ -76,6 +76,13 @@ create table migtest_e_basic (
|
||||
constraint pk_migtest_e_basic primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_enum (
|
||||
id integer generated by default as identity (start with 1) not null,
|
||||
test_status varchar(1),
|
||||
constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')),
|
||||
constraint pk_migtest_e_enum primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history (
|
||||
id integer generated by default as identity (start with 1) not null,
|
||||
test_string varchar(255),
|
||||
|
||||
@@ -31,7 +31,7 @@ alter table migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null
|
||||
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 restrict on update restrict;
|
||||
|
||||
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 drop constraint if exists ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic alter column status set default 'A';
|
||||
alter table migtest_e_basic alter column status set not null;
|
||||
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?'));
|
||||
@@ -61,6 +61,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 migtest_e_enum drop constraint if exists ck_migtest_e_enum_test_status;
|
||||
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';
|
||||
|
||||
@@ -14,7 +14,7 @@ alter table migtest_fk_none drop constraint if exists fk_migtest_fk_none_one_id;
|
||||
alter table migtest_fk_none_via_join drop constraint if exists fk_migtest_fk_none_via_join_one_id;
|
||||
alter table migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
|
||||
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 set null;
|
||||
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic drop constraint if exists ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic alter column status drop default;
|
||||
alter table migtest_e_basic alter column status set null;
|
||||
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I'));
|
||||
@@ -36,6 +36,8 @@ 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_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
|
||||
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
|
||||
alter table migtest_e_enum drop constraint if exists ck_migtest_e_enum_test_status;
|
||||
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 '';
|
||||
alter table migtest_e_history2 alter column test_string drop default;
|
||||
|
||||
@@ -56,6 +56,10 @@
|
||||
<uniqueConstraint name="uq_migtest_e_basic_indextest2" columnNames="indextest2" oneToOne="false" nullableColumns="indextest2"/>
|
||||
<uniqueConstraint name="uq_migtest_e_basic_indextest6" columnNames="indextest6" oneToOne="false" nullableColumns="indextest6"/>
|
||||
</createTable>
|
||||
<createTable name="migtest_e_enum" pkName="pk_migtest_e_enum">
|
||||
<column name="id" type="integer" primaryKey="true"/>
|
||||
<column name="test_status" type="varchar(1)" checkConstraint="check ( test_status in ('N','A','I'))" checkConstraintName="ck_migtest_e_enum_test_status"/>
|
||||
</createTable>
|
||||
<createTable name="migtest_e_history" pkName="pk_migtest_e_history">
|
||||
<column name="id" type="integer" primaryKey="true"/>
|
||||
<column name="test_string" type="varchar"/>
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
<addUniqueConstraint constraintName="uq_migtest_e_basic_name" tableName="migtest_e_basic" columnNames="name" nullableColumns="name" oneToOne="false"/>
|
||||
<addUniqueConstraint constraintName="uq_migtest_e_basic_indextest4" tableName="migtest_e_basic" columnNames="indextest4" nullableColumns="indextest4" oneToOne="false"/>
|
||||
<addUniqueConstraint constraintName="uq_migtest_e_basic_indextest5" tableName="migtest_e_basic" columnNames="indextest5" nullableColumns="indextest5" oneToOne="false"/>
|
||||
<alterColumn columnName="test_status" tableName="migtest_e_enum" dropCheckConstraint="ck_migtest_e_enum_test_status"/>
|
||||
<addHistoryTable baseTable="migtest_e_history"/>
|
||||
<alterColumn columnName="test_string" tableName="migtest_e_history" type="bigint" currentType="varchar" currentNotnull="false" comment="Column altered to long now">
|
||||
<before platforms="postgres">alter table ${table} alter column ${column} TYPE bigint USING (${column}::integer)</before>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<addUniqueConstraint constraintName="uq_migtest_e_basic_indextest5" tableName="migtest_e_basic" columnNames="DROP CONSTRAINT" nullableColumns="indextest5"/>
|
||||
<addUniqueConstraint constraintName="uq_migtest_e_basic_indextest2" tableName="migtest_e_basic" columnNames="indextest2" nullableColumns="indextest2" oneToOne="false"/>
|
||||
<addUniqueConstraint constraintName="uq_migtest_e_basic_indextest6" tableName="migtest_e_basic" columnNames="indextest6" nullableColumns="indextest6" oneToOne="false"/>
|
||||
<alterColumn columnName="test_status" tableName="migtest_e_enum" checkConstraint="check ( test_status in ('N','A','I'))" checkConstraintName="ck_migtest_e_enum_test_status"/>
|
||||
<alterColumn columnName="test_string" tableName="migtest_e_history" withHistory="true" comment="DROP COMMENT"/>
|
||||
<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"/>
|
||||
|
||||
@@ -76,6 +76,13 @@ create table migtest_e_basic (
|
||||
constraint pk_migtest_e_basic primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_enum (
|
||||
id integer auto_increment not null,
|
||||
test_status varchar(1),
|
||||
constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')),
|
||||
constraint pk_migtest_e_enum primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history (
|
||||
id integer auto_increment not null,
|
||||
test_string varchar(255),
|
||||
|
||||
@@ -38,6 +38,7 @@ alter table migtest_e_basic drop index uq_migtest_e_basic_indextest4;
|
||||
alter table migtest_e_basic drop index uq_migtest_e_basic_indextest5;
|
||||
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
|
||||
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
|
||||
alter table migtest_e_enum add constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I'));
|
||||
alter table migtest_e_history comment = '';
|
||||
alter table migtest_e_history2 alter test_string drop default;
|
||||
alter table migtest_e_history2 add column obsolete_string1 varchar(255);
|
||||
|
||||
@@ -85,6 +85,14 @@ create table migtest_e_basic (
|
||||
);
|
||||
create sequence migtest_e_basic_seq;
|
||||
|
||||
create table migtest_e_enum (
|
||||
id number(10) not null,
|
||||
test_status varchar2(1),
|
||||
constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')),
|
||||
constraint pk_migtest_e_enum primary key (id)
|
||||
);
|
||||
create sequence migtest_e_enum_seq;
|
||||
|
||||
create table migtest_e_history (
|
||||
id number(10) not null,
|
||||
test_string varchar2(255),
|
||||
|
||||
@@ -62,6 +62,7 @@ alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest6;
|
||||
-- NOT YET IMPLEMENTED: alter table migtest_e_basic add constraint uq_migtest_e_basic_name unique (name);
|
||||
-- NOT YET IMPLEMENTED: alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique (indextest4);
|
||||
-- NOT YET IMPLEMENTED: alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5);
|
||||
alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status;
|
||||
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';
|
||||
|
||||
@@ -37,6 +37,8 @@ alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4;
|
||||
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5;
|
||||
-- NOT YET IMPLEMENTED: alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
|
||||
-- NOT YET IMPLEMENTED: alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
|
||||
alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status;
|
||||
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 '';
|
||||
alter table migtest_e_history2 modify test_string drop default;
|
||||
|
||||
@@ -76,6 +76,13 @@ create table migtest_e_basic (
|
||||
constraint pk_migtest_e_basic primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_enum (
|
||||
id serial not null,
|
||||
test_status varchar(1),
|
||||
constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')),
|
||||
constraint pk_migtest_e_enum primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history (
|
||||
id serial not null,
|
||||
test_string varchar(255),
|
||||
|
||||
@@ -37,7 +37,7 @@ alter table if exists migtest_fk_set_null drop constraint if exists fk_migtest_f
|
||||
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 restrict on update restrict;
|
||||
|
||||
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 drop constraint if exists ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic alter column status set default 'A';
|
||||
alter table migtest_e_basic alter column status set not null;
|
||||
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?'));
|
||||
@@ -67,6 +67,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 migtest_e_enum drop constraint if exists ck_migtest_e_enum_test_status;
|
||||
|
||||
alter table migtest_e_history alter column test_string TYPE bigint USING (test_string::integer);
|
||||
comment on column migtest_e_history.test_string is 'Column altered to long now';
|
||||
|
||||
@@ -19,7 +19,7 @@ alter table if exists migtest_fk_none drop constraint if exists fk_migtest_fk_no
|
||||
alter table if exists migtest_fk_none_via_join drop constraint if exists fk_migtest_fk_none_via_join_one_id;
|
||||
alter table if exists migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
|
||||
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 set null;
|
||||
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic drop constraint if exists ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic alter column status drop default;
|
||||
alter table migtest_e_basic alter column status drop not null;
|
||||
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I'));
|
||||
@@ -41,6 +41,8 @@ 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_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
|
||||
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
|
||||
alter table migtest_e_enum drop constraint if exists ck_migtest_e_enum_test_status;
|
||||
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 '';
|
||||
alter table migtest_e_history2 alter column test_string drop default;
|
||||
|
||||
@@ -79,6 +79,13 @@ create table migtest_e_basic (
|
||||
foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict
|
||||
);
|
||||
|
||||
create table migtest_e_enum (
|
||||
id integer not null,
|
||||
test_status varchar(1),
|
||||
constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')),
|
||||
constraint pk_migtest_e_enum primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history (
|
||||
id integer not null,
|
||||
test_string varchar(255),
|
||||
|
||||
@@ -30,7 +30,7 @@ alter table migtest_fk_cascade drop constraint if exists fk_migtest_fk_cascade_o
|
||||
alter table migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
|
||||
|
||||
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 drop constraint if exists ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic alter column status set default 'A';
|
||||
alter table migtest_e_basic alter column status set not null;
|
||||
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I','?'));
|
||||
@@ -59,6 +59,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 migtest_e_enum drop constraint if exists ck_migtest_e_enum_test_status;
|
||||
alter table migtest_e_history alter column test_string integer;
|
||||
|
||||
-- NOTE: table has @History - special migration may be necessary
|
||||
|
||||
@@ -12,7 +12,7 @@ alter table migtest_fk_cascade drop constraint if exists fk_migtest_fk_cascade_o
|
||||
alter table migtest_fk_none drop constraint if exists fk_migtest_fk_none_one_id;
|
||||
alter table migtest_fk_none_via_join drop constraint if exists fk_migtest_fk_none_via_join_one_id;
|
||||
alter table migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
|
||||
alter table migtest_e_basic drop constraint ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic drop constraint if exists ck_migtest_e_basic_status;
|
||||
alter table migtest_e_basic alter column status drop default;
|
||||
alter table migtest_e_basic alter column status set null;
|
||||
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I'));
|
||||
@@ -34,6 +34,8 @@ 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_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
|
||||
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
|
||||
alter table migtest_e_enum drop constraint if exists ck_migtest_e_enum_test_status;
|
||||
alter table migtest_e_enum add constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I'));
|
||||
alter table migtest_e_history2 alter column test_string drop default;
|
||||
alter table migtest_e_history2 alter column test_string set null;
|
||||
alter table migtest_e_history2 add column obsolete_string1 varchar(255);
|
||||
|
||||
@@ -85,6 +85,14 @@ create unique nonclustered index uq_migtest_e_basic_indextest2 on migtest_e_basi
|
||||
create unique nonclustered index uq_migtest_e_basic_indextest6 on migtest_e_basic(indextest6) where indextest6 is not null;
|
||||
create sequence migtest_e_basic_seq as bigint start with 1 ;
|
||||
|
||||
create table migtest_e_enum (
|
||||
id integer not null,
|
||||
test_status nvarchar(1),
|
||||
constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I')),
|
||||
constraint pk_migtest_e_enum primary key (id)
|
||||
);
|
||||
create sequence migtest_e_enum_seq as bigint start with 1 ;
|
||||
|
||||
create table migtest_e_history (
|
||||
id integer not null,
|
||||
test_string nvarchar(255),
|
||||
|
||||
@@ -64,6 +64,7 @@ create unique nonclustered index uq_migtest_e_basic_status_indextest1 on migtest
|
||||
create unique nonclustered index uq_migtest_e_basic_name on migtest_e_basic(name) where name is not null;
|
||||
create unique nonclustered index uq_migtest_e_basic_indextest4 on migtest_e_basic(indextest4) where indextest4 is not null;
|
||||
create unique nonclustered index uq_migtest_e_basic_indextest5 on migtest_e_basic(indextest5) where indextest5 is not null;
|
||||
IF (OBJECT_ID('ck_migtest_e_enum_test_status', 'C') IS NOT NULL) alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status;
|
||||
alter table migtest_e_history alter column test_string numeric(19);
|
||||
|
||||
-- NOTE: table has @History - special migration may be necessary
|
||||
|
||||
@@ -48,6 +48,8 @@ IF (OBJECT_ID('uq_migtest_e_basic_indextest5', 'UQ') IS NOT NULL) alter table mi
|
||||
IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('migtest_e_basic','U') AND name = 'uq_migtest_e_basic_indextest5') drop index uq_migtest_e_basic_indextest5 ON migtest_e_basic;
|
||||
create unique nonclustered index uq_migtest_e_basic_indextest2 on migtest_e_basic(indextest2) where indextest2 is not null;
|
||||
create unique nonclustered index uq_migtest_e_basic_indextest6 on migtest_e_basic(indextest6) where indextest6 is not null;
|
||||
IF (OBJECT_ID('ck_migtest_e_enum_test_status', 'C') IS NOT NULL) alter table migtest_e_enum drop constraint ck_migtest_e_enum_test_status;
|
||||
alter table migtest_e_enum add constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I'));
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user