mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 15:55:55 +00:00
#374 - ms sql server ... alter column default values
This commit is contained in:
@@ -14,6 +14,7 @@ public class MsSqlServerDdl extends PlatformDdl {
|
||||
this.identitySuffix = " identity(1,1)";
|
||||
this.foreignKeyRestrict = "";
|
||||
this.inlineUniqueOneToOne = false;
|
||||
this.columnSetDefault = "add default";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,6 +50,17 @@ public class MsSqlServerDdl extends PlatformDdl {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String alterColumnDefaultValue(String tableName, String columnName, String defaultValue) {
|
||||
|
||||
if (isDropDefault(defaultValue)) {
|
||||
return "-- alter table " + tableName + " drop constraint <unknown> -- find the appropriate constraint for default value on column " + columnName;
|
||||
} else {
|
||||
return "alter table " + tableName + " add default " + defaultValue + " for " + columnName;
|
||||
}
|
||||
}
|
||||
|
||||
public String alterColumnBaseAttributes(AlterColumn alter) {
|
||||
|
||||
String tableName = alter.getTableName();
|
||||
|
||||
+10
-2
@@ -19,7 +19,6 @@ public class PlatformDdl_AlterColumnTest {
|
||||
PlatformDdl oraDdl = new Oracle10Platform().getPlatformDdl();
|
||||
PlatformDdl sqlServerDdl = new MsSqlServer2005Platform().getPlatformDdl();
|
||||
|
||||
|
||||
AlterColumn alterNotNull() {
|
||||
AlterColumn alterColumn = new AlterColumn();
|
||||
alterColumn.setTableName("mytab");
|
||||
@@ -57,7 +56,6 @@ public class PlatformDdl_AlterColumnTest {
|
||||
alterColumn.setCurrentNotnull(Boolean.TRUE);
|
||||
sql = mysqlDdl.alterColumnBaseAttributes(alterColumn);
|
||||
assertEquals("alter table mytab modify acol varchar(100) not null", sql);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,6 +91,9 @@ public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
sql = mysqlDdl.alterColumnNotnull("mytab", "acol", true);
|
||||
assertNull(sql);
|
||||
|
||||
sql = sqlServerDdl.alterColumnNotnull("mytab", "acol", true);
|
||||
assertNull(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,6 +110,9 @@ public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
sql = mysqlDdl.alterColumnNotnull("mytab", "acol", false);
|
||||
assertNull(sql);
|
||||
|
||||
sql = sqlServerDdl.alterColumnNotnull("mytab", "acol", false);
|
||||
assertNull(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,6 +130,8 @@ public class PlatformDdl_AlterColumnTest {
|
||||
sql = mysqlDdl.alterColumnDefaultValue("mytab", "acol", "'hi'");
|
||||
assertEquals("alter table mytab alter acol set default 'hi'", sql);
|
||||
|
||||
sql = sqlServerDdl.alterColumnDefaultValue("mytab", "acol", "'hi'");
|
||||
assertEquals("alter table mytab add default 'hi' for acol", sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -143,6 +149,8 @@ public class PlatformDdl_AlterColumnTest {
|
||||
sql = mysqlDdl.alterColumnDefaultValue("mytab", "acol", "DROP DEFAULT");
|
||||
assertEquals("alter table mytab alter acol drop default", sql);
|
||||
|
||||
sql = sqlServerDdl.alterColumnDefaultValue("mytab", "acol", "DROP DEFAULT");
|
||||
assertTrue(sql, sql.startsWith("-- alter"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user