From bf4ccefc7560659c1b68faeee5ef593f1311ab2c Mon Sep 17 00:00:00 2001 From: Roland Praml Date: Mon, 7 Feb 2022 09:08:39 +0100 Subject: [PATCH] Fixes for Mutli-Platform test --- .../tests/rawsql/TestRawSqlNamedParams.java | 8 +++- .../src/test/resources/ebean.properties | 1 + .../dbmigration/mysql/1.2__dropsFor_1.1.sql | 14 +++--- .../dbmigration/mysql/1.4__dropsFor_1.3.sql | 40 ++++++++-------- .../dbmigration/mysql/I__create_procs.sql | 48 +++++++++++++++++++ .../dbmigration/mysql/idx_mysql.migrations | 5 +- 6 files changed, 85 insertions(+), 31 deletions(-) create mode 100644 ebean-test/src/test/resources/migrationtest/dbmigration/mysql/I__create_procs.sql diff --git a/ebean-test/src/test/java/org/tests/rawsql/TestRawSqlNamedParams.java b/ebean-test/src/test/java/org/tests/rawsql/TestRawSqlNamedParams.java index e40fe30bd..319469cf7 100644 --- a/ebean-test/src/test/java/org/tests/rawsql/TestRawSqlNamedParams.java +++ b/ebean-test/src/test/java/org/tests/rawsql/TestRawSqlNamedParams.java @@ -13,6 +13,7 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; public class TestRawSqlNamedParams extends BaseTestCase { @@ -43,9 +44,12 @@ public class TestRawSqlNamedParams extends BaseTestCase { Transaction transaction = DB.beginTransaction(); + System.out.println(transaction.connection().getMetaData().getDriverName()); try { - if ("MariaDB connector/J".equals(transaction.connection().getMetaData().getDriverName())) { - return; // MariaDb only supports callable statements in the form "? = call function x(?)" + if ("MariaDB Connector/J".equals(transaction.connection().getMetaData().getDriverName())) { + // CHECKME: Should we report/fail if we are running mysql-tests with mariadb driver + // BTW: This happens with java 8 - the drivers in drivermanager are in different order + return; // MariaDB Connector/J only supports callable statements in the form "? = call function x(?)" } CallableSql callableSql = DB.createCallableSql("set @total = 0"); DB.getDefault().execute(callableSql); diff --git a/ebean-test/src/test/resources/ebean.properties b/ebean-test/src/test/resources/ebean.properties index 907ceda44..39b376be6 100644 --- a/ebean-test/src/test/resources/ebean.properties +++ b/ebean-test/src/test/resources/ebean.properties @@ -218,6 +218,7 @@ ebean.migrationtest.migration.platforms=db2luw,h2,hsqldb,mysql,mysql55,mariadb,p #migration.migrationtest.db2luw.prefix=db2 #migration.migrationtest.sqlserver17.prefix=sqlserver dbmigration.platform.mariadb.useMigrationStoredProcedures=true +dbmigration.platform.mysql.useMigrationStoredProcedures=true # need to generate unique statements to prevent them from being filtered out as duplicates by the DdlRunner diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.2__dropsFor_1.1.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.2__dropsFor_1.1.sql index b3317f701..a22adf90b 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.2__dropsFor_1.1.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.2__dropsFor_1.1.sql @@ -3,17 +3,17 @@ drop view if exists migtest_e_history2_with_history; -- apply changes -alter table migtest_e_basic drop column old_boolean; +CALL usp_ebean_drop_column('migtest_e_basic', 'old_boolean'); -alter table migtest_e_basic drop column old_boolean2; +CALL usp_ebean_drop_column('migtest_e_basic', 'old_boolean2'); -alter table migtest_e_basic drop column eref_id; +CALL usp_ebean_drop_column('migtest_e_basic', 'eref_id'); -alter table migtest_e_history2 drop column obsolete_string1; -alter table migtest_e_history2_history drop column obsolete_string1; +CALL usp_ebean_drop_column('migtest_e_history2', 'obsolete_string1'); +CALL usp_ebean_drop_column('migtest_e_history2_history', 'obsolete_string1'); -alter table migtest_e_history2 drop column obsolete_string2; -alter table migtest_e_history2_history drop column obsolete_string2; +CALL usp_ebean_drop_column('migtest_e_history2', 'obsolete_string2'); +CALL usp_ebean_drop_column('migtest_e_history2_history', 'obsolete_string2'); drop table if exists migtest_e_ref; create view migtest_e_history2_with_history as select * from migtest_e_history2 union all select * from migtest_e_history2_history; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.4__dropsFor_1.3.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.4__dropsFor_1.3.sql index a560bd320..ff2e34d44 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.4__dropsFor_1.3.sql +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/1.4__dropsFor_1.3.sql @@ -3,45 +3,45 @@ drop trigger migtest_e_history_history_upd; drop trigger migtest_e_history_history_del; drop view migtest_e_history_with_history; -alter table migtest_e_history drop column sys_period_start; -alter table migtest_e_history drop column sys_period_end; +CALL usp_ebean_drop_column('migtest_e_history', 'sys_period_start'); +CALL usp_ebean_drop_column('migtest_e_history', 'sys_period_end'); drop table migtest_e_history_history; drop view if exists migtest_e_history2_with_history; drop view if exists migtest_e_history5_with_history; -- apply changes -alter table migtest_ckey_detail drop column one_key; +CALL usp_ebean_drop_column('migtest_ckey_detail', 'one_key'); -alter table migtest_ckey_detail drop column two_key; +CALL usp_ebean_drop_column('migtest_ckey_detail', 'two_key'); -alter table migtest_ckey_parent drop column assoc_id; +CALL usp_ebean_drop_column('migtest_ckey_parent', 'assoc_id'); -alter table migtest_e_basic drop column new_string_field; +CALL usp_ebean_drop_column('migtest_e_basic', 'new_string_field'); -alter table migtest_e_basic drop column new_boolean_field; +CALL usp_ebean_drop_column('migtest_e_basic', 'new_boolean_field'); -alter table migtest_e_basic drop column new_boolean_field2; +CALL usp_ebean_drop_column('migtest_e_basic', 'new_boolean_field2'); -alter table migtest_e_basic drop column progress; +CALL usp_ebean_drop_column('migtest_e_basic', 'progress'); -alter table migtest_e_basic drop column new_integer; +CALL usp_ebean_drop_column('migtest_e_basic', 'new_integer'); -alter table migtest_e_history2 drop column test_string2; -alter table migtest_e_history2_history drop column test_string2; +CALL usp_ebean_drop_column('migtest_e_history2', 'test_string2'); +CALL usp_ebean_drop_column('migtest_e_history2_history', 'test_string2'); -alter table migtest_e_history2 drop column test_string3; -alter table migtest_e_history2_history drop column test_string3; +CALL usp_ebean_drop_column('migtest_e_history2', 'test_string3'); +CALL usp_ebean_drop_column('migtest_e_history2_history', 'test_string3'); -alter table migtest_e_history2 drop column new_column; -alter table migtest_e_history2_history drop column new_column; +CALL usp_ebean_drop_column('migtest_e_history2', 'new_column'); +CALL usp_ebean_drop_column('migtest_e_history2_history', 'new_column'); -alter table migtest_e_history5 drop column test_boolean; -alter table migtest_e_history5_history drop column test_boolean; +CALL usp_ebean_drop_column('migtest_e_history5', 'test_boolean'); +CALL usp_ebean_drop_column('migtest_e_history5_history', 'test_boolean'); -alter table migtest_e_softdelete drop column deleted; +CALL usp_ebean_drop_column('migtest_e_softdelete', 'deleted'); -alter table migtest_oto_child drop column master_id; +CALL usp_ebean_drop_column('migtest_oto_child', 'master_id'); drop table if exists migtest_e_user; drop table if exists migtest_mtm_c_migtest_mtm_m; diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/I__create_procs.sql b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/I__create_procs.sql new file mode 100644 index 000000000..d13ec2708 --- /dev/null +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/I__create_procs.sql @@ -0,0 +1,48 @@ +-- 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 +$$ diff --git a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/idx_mysql.migrations b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/idx_mysql.migrations index 082bbefb7..4bb99f9cb 100644 --- a/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/idx_mysql.migrations +++ b/ebean-test/src/test/resources/migrationtest/dbmigration/mysql/idx_mysql.migrations @@ -1,7 +1,8 @@ +1835064798, I__create_procs.sql 1075178692, 1.0__initial.sql -1627573867, 1.1.sql -1029390755, 1.2__dropsFor_1.1.sql +1922991807, 1.2__dropsFor_1.1.sql -380371830, 1.3.sql --724776884, 1.4__dropsFor_1.3.sql +-1373040825, 1.4__dropsFor_1.3.sql 561281075, R__order_views.sql