diff --git a/src/main/java/io/ebean/config/PlatformConfig.java b/src/main/java/io/ebean/config/PlatformConfig.java index f891b3d47..d06868d1b 100644 --- a/src/main/java/io/ebean/config/PlatformConfig.java +++ b/src/main/java/io/ebean/config/PlatformConfig.java @@ -54,8 +54,6 @@ public class PlatformConfig { private boolean caseSensitiveCollation = true; - private boolean useMigrationStoredProcedures; - /** * Modify the default mapping of standard types such as default precision for DECIMAL etc. */ @@ -78,7 +76,6 @@ public class PlatformConfig { this.idType = platformConfig.idType; this.geometrySRID = platformConfig.geometrySRID; this.dbUuid = platformConfig.dbUuid; - this.useMigrationStoredProcedures = platformConfig.useMigrationStoredProcedures; this.caseSensitiveCollation = platformConfig.caseSensitiveCollation; this.allQuotedIdentifiers = platformConfig.allQuotedIdentifiers; this.databaseInetAddressVarchar = platformConfig.databaseInetAddressVarchar; @@ -113,20 +110,6 @@ public class PlatformConfig { this.caseSensitiveCollation = caseSensitiveCollation; } - /** - * Return true if force use of helper stored procedures for migrations. - */ - public boolean isUseMigrationStoredProcedures() { - return useMigrationStoredProcedures; - } - - /** - * Set true to force use of helper stored procedures for migrations. - */ - public void setUseMigrationStoredProcedures(boolean useMigrationStoredProcedures) { - this.useMigrationStoredProcedures = useMigrationStoredProcedures; - } - /** * Return a value used to represent TRUE in the database. *

@@ -293,7 +276,6 @@ public class PlatformConfig { databaseBooleanFalse = p.get("databaseBooleanFalse", databaseBooleanFalse); databaseInetAddressVarchar = p.getBoolean("databaseInetAddressVarchar", databaseInetAddressVarchar); caseSensitiveCollation = p.getBoolean("caseSensitiveCollation", caseSensitiveCollation); - useMigrationStoredProcedures = p.getBoolean("useMigrationStoredProcedures", useMigrationStoredProcedures);; DbUuid dbUuid = p.getEnum(DbUuid.class, "dbuuid", null); if (dbUuid != null) { diff --git a/src/main/java/io/ebean/config/dbplatform/DatabasePlatform.java b/src/main/java/io/ebean/config/dbplatform/DatabasePlatform.java index c3d699f7a..43396fab9 100644 --- a/src/main/java/io/ebean/config/dbplatform/DatabasePlatform.java +++ b/src/main/java/io/ebean/config/dbplatform/DatabasePlatform.java @@ -53,8 +53,6 @@ public class DatabasePlatform { protected boolean supportsSavepointId = true; - protected boolean useMigrationStoredProcedures = true; - /** * The behaviour used when ending a read only transaction at read committed isolation level. */ @@ -235,9 +233,6 @@ public class DatabasePlatform { public void configure(PlatformConfig config) { this.sequenceBatchSize = config.getDatabaseSequenceBatchSize(); this.caseSensitiveCollation = config.isCaseSensitiveCollation(); - if (config.isUseMigrationStoredProcedures()) { - useMigrationStoredProcedures = true; - } configureIdType(config.getIdType()); configure(config, config.isAllQuotedIdentifiers()); } @@ -344,13 +339,6 @@ public class DatabasePlatform { return supportsSavepointId; } - /** - * Return true if migrations should use stored procedures. - */ - public boolean isUseMigrationStoredProcedures() { - return useMigrationStoredProcedures; - } - /** * Return the maximum table name length. *

diff --git a/src/main/java/io/ebean/config/dbplatform/mysql/MySqlPlatform.java b/src/main/java/io/ebean/config/dbplatform/mysql/MySqlPlatform.java index 761c9425a..83d509da4 100644 --- a/src/main/java/io/ebean/config/dbplatform/mysql/MySqlPlatform.java +++ b/src/main/java/io/ebean/config/dbplatform/mysql/MySqlPlatform.java @@ -28,7 +28,6 @@ public class MySqlPlatform extends DatabasePlatform { this.useExtraTransactionOnIterateSecondaryQueries = true; this.selectCountWithAlias = true; this.supportsSavepointId = false; - this.useMigrationStoredProcedures = false; this.dbEncrypt = new MySqlDbEncrypt(); this.historySupport = new MySqlHistorySupport(); this.columnAliasPrefix = null; diff --git a/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java b/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java index 01001d9d0..45282cd2d 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java +++ b/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java @@ -47,7 +47,6 @@ public class DdlGenerator { private final boolean ddlAutoCommit; private final String dbSchema; private final ScriptTransform scriptTransform; - private final boolean useMigrationStoredProcedures; private CurrentModel currentModel; private String dropAllContent; @@ -65,11 +64,9 @@ public class DdlGenerator { log.warn("DDL can't be run on startup with TenantMode " + serverConfig.getTenantMode()); this.runDdl = false; this.ddlAutoCommit = false; - this.useMigrationStoredProcedures = false; } else { this.runDdl = serverConfig.isDdlRun(); this.ddlAutoCommit = server.getDatabasePlatform().isDdlAutoCommit(); - this.useMigrationStoredProcedures = server.getDatabasePlatform().isUseMigrationStoredProcedures(); } this.scriptTransform = createScriptTransform(serverConfig.getMigrationConfig()); this.baseDir = initBaseDir(); @@ -182,7 +179,7 @@ public class DdlGenerator { protected void runDropSql(Connection connection) throws IOException { if (!createOnly) { - if (extraDdl && jaxbPresent && useMigrationStoredProcedures) { + if (extraDdl && jaxbPresent) { String extraApply = ExtraDdlXmlReader.buildExtra(server.getDatabasePlatform().getName(), true); if (extraApply != null) { runScript(connection, false, extraApply, "extra-ddl"); @@ -202,7 +199,7 @@ public class DdlGenerator { } runScript(connection, false, createAllContent, getCreateFileName()); - if (extraDdl && jaxbPresent && useMigrationStoredProcedures) { + if (extraDdl && jaxbPresent) { if (currentModel().isTablePartitioning()) { String extraPartitioning = ExtraDdlXmlReader.buildPartitioning(server.getDatabasePlatform().getName()); if (extraPartitioning != null && !extraPartitioning.isEmpty()) { diff --git a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/MySqlDdl.java b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/MySqlDdl.java index afb88c712..4db6d6bff 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/MySqlDdl.java +++ b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/MySqlDdl.java @@ -18,15 +18,12 @@ public class MySqlDdl extends PlatformDdl { // this flag is for compatibility. Use it with care. private static final boolean USE_CHECK_CONSTRAINT = Boolean.getBoolean("ebean.mysql.useCheckConstraint"); - private final boolean useMigrationStoredProcedures; - public MySqlDdl(DatabasePlatform platform) { super(platform); this.alterColumn = "modify"; this.dropUniqueConstraint = "drop index"; this.historyDdl = new MySqlHistoryDdl(); this.inlineComments = true; - this.useMigrationStoredProcedures = platform.isUseMigrationStoredProcedures(); } /** @@ -45,21 +42,6 @@ public class MySqlDdl extends PlatformDdl { return "alter table " + tableName + " drop foreign key " + maxConstraintName(fkName); } - /** - * It is rather complex to delete a column on MySql as there must not exist any foreign keys. - * That's why we call a user stored procedure here - */ - @Override - public void alterTableDropColumn(DdlBuffer buffer, String tableName, String columnName) throws IOException { - - if (useMigrationStoredProcedures) { - buffer.append("CALL usp_ebean_drop_column('").append(tableName).append("', '").append(columnName).append("')").endOfStatement(); - } else { - buffer.append("alter table ").append(tableName).append(" ").append(dropColumn).append(" ").append(columnName) - .append(dropColumnSuffix).endOfStatement(); - } - } - @Override public String createCheckConstraint(String ckName, String checkConstraint) { if (USE_CHECK_CONSTRAINT) { diff --git a/src/main/resources/io/ebeaninternal/dbmigration/builtin-extra-ddl.xml b/src/main/resources/io/ebeaninternal/dbmigration/builtin-extra-ddl.xml index 8002f6641..66d23b702 100644 --- a/src/main/resources/io/ebeaninternal/dbmigration/builtin-extra-ddl.xml +++ b/src/main/resources/io/ebeaninternal/dbmigration/builtin-extra-ddl.xml @@ -113,88 +113,4 @@ END GO --- Inital script to create stored procedures etc for mysql platform -DROP PROCEDURE IF EXISTS usp_ebean_drop_foreign_keys; - -delimiter $$ --- --- PROCEDURE: usp_ebean_drop_foreign_keys TABLE, COLUMN --- deletes all constraints and foreign keys referring to TABLE.COLUMN --- -CREATE PROCEDURE usp_ebean_drop_foreign_keys(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255)) -BEGIN - DECLARE done INT DEFAULT FALSE; - DECLARE c_fk_name CHAR(255); - DECLARE curs CURSOR FOR SELECT CONSTRAINT_NAME from information_schema.KEY_COLUMN_USAGE - WHERE TABLE_SCHEMA = DATABASE() and TABLE_NAME = p_table_name and COLUMN_NAME = p_column_name - AND REFERENCED_TABLE_NAME IS NOT NULL; - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - OPEN curs; - - read_loop: LOOP - FETCH curs INTO c_fk_name; - IF done THEN - LEAVE read_loop; - END IF; - SET @sql = CONCAT('ALTER TABLE ', p_table_name, ' DROP FOREIGN KEY ', c_fk_name); - PREPARE stmt FROM @sql; - EXECUTE stmt; - END LOOP; - - CLOSE curs; -END -$$ - -DROP PROCEDURE IF EXISTS usp_ebean_drop_column; - -delimiter $$ --- --- PROCEDURE: usp_ebean_drop_column TABLE, COLUMN --- deletes the column and ensures that all indices and constraints are dropped first --- -CREATE PROCEDURE usp_ebean_drop_column(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255)) -BEGIN - CALL usp_ebean_drop_foreign_keys(p_table_name, p_column_name); - SET @sql = CONCAT('ALTER TABLE ', p_table_name, ' DROP COLUMN ', p_column_name); - PREPARE stmt FROM @sql; - EXECUTE stmt; -END -$$ - - --- Inital script to create stored procedures etc for the hana platform -delimiter $$ --- --- PROCEDURE: usp_ebean_drop_foreign_keys TABLE, COLUMN --- deletes all constraints and foreign keys referring to TABLE.COLUMN --- -CREATE OR REPLACE PROCEDURE usp_ebean_drop_foreign_keys(IN table_name NVARCHAR(256), IN column_name NVARCHAR(256)) -AS -BEGIN - DECLARE foreign_key_names TABLE(CONSTRAINT_NAME NVARCHAR(256), TABLE_NAME NVARCHAR(256)); - DECLARE i INT; - - foreign_key_names = SELECT CONSTRAINT_NAME, TABLE_NAME FROM SYS.REFERENTIAL_CONSTRAINTS WHERE SCHEMA_NAME=CURRENT_SCHEMA AND TABLE_NAME=UPPER(:table_name) AND COLUMN_NAME=UPPER(:column_name); - - FOR I IN 1 .. RECORD_COUNT(:foreign_key_names) DO - EXEC 'ALTER TABLE "' || ESCAPE_DOUBLE_QUOTES(:foreign_key_names.TABLE_NAME[i]) || '" DROP CONSTRAINT "' || ESCAPE_DOUBLE_QUOTES(:foreign_key_names.CONSTRAINT_NAME[i]) || '"'; - END FOR; - -END; -$$ - -delimiter $$ --- --- PROCEDURE: usp_ebean_drop_column TABLE, COLUMN --- deletes the column and ensures that all indices and constraints are dropped first --- -CREATE OR REPLACE PROCEDURE usp_ebean_drop_column(IN table_name NVARCHAR(256), IN column_name NVARCHAR(256)) -AS -BEGIN - CALL usp_ebean_drop_foreign_keys(table_name, column_name); - EXEC 'ALTER TABLE "' || UPPER(ESCAPE_DOUBLE_QUOTES(table_name)) || '" DROP ("' || UPPER(ESCAPE_DOUBLE_QUOTES(column_name)) || '")'; -END; -$$ - diff --git a/src/test/resources/dbmigration/migrationtest/hana/I__create_procs.sql b/src/test/resources/dbmigration/migrationtest/hana/I__create_procs.sql deleted file mode 100644 index 32b8a9404..000000000 --- a/src/test/resources/dbmigration/migrationtest/hana/I__create_procs.sql +++ /dev/null @@ -1,33 +0,0 @@ --- Inital script to create stored procedures etc for the hana platform -delimiter $$ --- --- PROCEDURE: usp_ebean_drop_foreign_keys TABLE, COLUMN --- deletes all constraints and foreign keys referring to TABLE.COLUMN --- -CREATE OR REPLACE PROCEDURE usp_ebean_drop_foreign_keys(IN table_name NVARCHAR(256), IN column_name NVARCHAR(256)) -AS -BEGIN - DECLARE foreign_key_names TABLE(CONSTRAINT_NAME NVARCHAR(256), TABLE_NAME NVARCHAR(256)); - DECLARE i INT; - - foreign_key_names = SELECT CONSTRAINT_NAME, TABLE_NAME FROM SYS.REFERENTIAL_CONSTRAINTS WHERE SCHEMA_NAME=CURRENT_SCHEMA AND TABLE_NAME=UPPER(:table_name) AND COLUMN_NAME=UPPER(:column_name); - - FOR I IN 1 .. RECORD_COUNT(:foreign_key_names) DO - EXEC 'ALTER TABLE "' || ESCAPE_DOUBLE_QUOTES(:foreign_key_names.TABLE_NAME[i]) || '" DROP CONSTRAINT "' || ESCAPE_DOUBLE_QUOTES(:foreign_key_names.CONSTRAINT_NAME[i]) || '"'; - END FOR; - -END; -$$ - -delimiter $$ --- --- PROCEDURE: usp_ebean_drop_column TABLE, COLUMN --- deletes the column and ensures that all indices and constraints are dropped first --- -CREATE OR REPLACE PROCEDURE usp_ebean_drop_column(IN table_name NVARCHAR(256), IN column_name NVARCHAR(256)) -AS -BEGIN - CALL usp_ebean_drop_foreign_keys(table_name, column_name); - EXEC 'ALTER TABLE "' || UPPER(ESCAPE_DOUBLE_QUOTES(table_name)) || '" DROP ("' || UPPER(ESCAPE_DOUBLE_QUOTES(column_name)) || '")'; -END; -$$ diff --git a/src/test/resources/dbmigration/migrationtest/mysql/I__create_procs.sql b/src/test/resources/dbmigration/migrationtest/mysql/I__create_procs.sql deleted file mode 100644 index 55acf0bf3..000000000 --- a/src/test/resources/dbmigration/migrationtest/mysql/I__create_procs.sql +++ /dev/null @@ -1,48 +0,0 @@ --- Inital script to create stored procedures etc for mysql platform -DROP PROCEDURE IF EXISTS usp_ebean_drop_foreign_keys; - -delimiter $$ --- --- PROCEDURE: usp_ebean_drop_foreign_keys TABLE, COLUMN --- deletes all constraints and foreign keys referring to TABLE.COLUMN --- -CREATE PROCEDURE usp_ebean_drop_foreign_keys(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255)) -BEGIN - DECLARE done INT DEFAULT FALSE; - DECLARE c_fk_name CHAR(255); - DECLARE curs CURSOR FOR SELECT CONSTRAINT_NAME from information_schema.KEY_COLUMN_USAGE - WHERE TABLE_SCHEMA = DATABASE() and TABLE_NAME = p_table_name and COLUMN_NAME = p_column_name - AND REFERENCED_TABLE_NAME IS NOT NULL; - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - OPEN curs; - - read_loop: LOOP - FETCH curs INTO c_fk_name; - IF done THEN - LEAVE read_loop; - END IF; - SET @sql = CONCAT('ALTER TABLE ', p_table_name, ' DROP FOREIGN KEY ', c_fk_name); - PREPARE stmt FROM @sql; - EXECUTE stmt; - END LOOP; - - CLOSE curs; -END -$$ - -DROP PROCEDURE IF EXISTS usp_ebean_drop_column; - -delimiter $$ --- --- PROCEDURE: usp_ebean_drop_column TABLE, COLUMN --- deletes the column and ensures that all indices and constraints are dropped first --- -CREATE PROCEDURE usp_ebean_drop_column(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255)) -BEGIN - CALL usp_ebean_drop_foreign_keys(p_table_name, p_column_name); - SET @sql = CONCAT('ALTER TABLE ', p_table_name, ' DROP COLUMN ', p_column_name); - PREPARE stmt FROM @sql; - EXECUTE stmt; -END -$$