Apply recent fixes for MySQL migration tasks to MariaDB as well.

This commit is contained in:
ianmarshall 2020-06-24 17:42:46 -04:00
parent 5e3e7c46a8
commit 053094f2a6
7 changed files with 9 additions and 12 deletions

View File

@ -54,11 +54,11 @@ public class AddColumnTask extends BaseTableColumnTypeTask {
String sql;
switch (getDriverType()) {
case MYSQL_5_7:
case MARIADB_10_1:
// Quote the column name as "SYSTEM" is a reserved word in MySQL
sql = "alter table " + getTableName() + " add column `" + getColumnName() + "` " + typeStatement;
break;
case DERBY_EMBEDDED:
case MARIADB_10_1:
case POSTGRES_9_4:
sql = "alter table " + getTableName() + " add column " + getColumnName() + " " + typeStatement;
break;

View File

@ -26,6 +26,7 @@ import org.intellij.lang.annotations.Language;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.List;
import java.util.Set;
@ -52,8 +53,8 @@ public class DropColumnTask extends BaseTableColumnTask {
return;
}
if(getDriverType().equals(DriverTypeEnum.MYSQL_5_7)) {
// Some DBs such as MYSQL require that foreign keys depending on the column be dropped before the column itself is dropped.
if(getDriverType().equals(DriverTypeEnum.MYSQL_5_7) || getDriverType().equals(DriverTypeEnum.MARIADB_10_1)) {
// Some DBs such as MYSQL and Maria DB require that foreign keys depending on the column be dropped before the column itself is dropped.
logInfo(ourLog, "Dropping any foreign keys on table {} depending on column {}", getTableName(), getColumnName());
Set<String> foreignKeys = JdbcUtils.getForeignKeysForColumn(getConnectionProperties(), getColumnName(), getTableName());
if(foreignKeys != null) {

View File

@ -101,10 +101,10 @@ public class DropForeignKeyTask extends BaseTableTask {
List<String> sqls = new ArrayList<>();
switch (theDriverType) {
case MYSQL_5_7:
case MARIADB_10_1:
// Lousy MYQL....
sqls.add("alter table " + theTableName + " drop foreign key " + theConstraintName);
break;
case MARIADB_10_1:
case POSTGRES_9_4:
case DERBY_EMBEDDED:
case H2_EMBEDDED:

View File

@ -107,12 +107,10 @@ public class DropIndexTask extends BaseTableTask {
// Drop constraint
switch (theDriverType) {
case MYSQL_5_7:
case MARIADB_10_1:
// Need to quote the index name as the word "PRIMARY" is reserved in MySQL
sql.add("alter table " + theTableName + " drop index `" + theIndexName + "`");
break;
case MARIADB_10_1:
sql.add("alter table " + theTableName + " drop index " + theIndexName);
break;
case H2_EMBEDDED:
sql.add("drop index " + theIndexName);
break;

View File

@ -139,10 +139,8 @@ public class RenameColumnTask extends BaseTableTask {
case DERBY_EMBEDDED:
sql = "RENAME COLUMN " + getTableName() + "." + myOldName + " TO " + myNewName;
break;
case MARIADB_10_1:
sql = "ALTER TABLE " + getTableName() + " CHANGE COLUMN " + myOldName + " TO " + myNewName;
break;
case MYSQL_5_7:
case MARIADB_10_1:
// Quote the column names as "SYSTEM" is a reserved word in MySQL
sql = "ALTER TABLE " + getTableName() + " CHANGE COLUMN `" + myOldName + "` `" + myNewName + "` " + theExistingType + " " + theExistingNotNull;
break;

View File

@ -110,10 +110,10 @@ public class RenameIndexTask extends BaseTableTask {
// Drop constraint
switch (theDriverType) {
case MYSQL_5_7:
case MARIADB_10_1:
// Quote the index names as "PRIMARY" is a reserved word in MySQL
sql.add("rename index `" + theOldIndexName + "` to `" + theNewIndexName + "`");
break;
case MARIADB_10_1:
case DERBY_EMBEDDED:
sql.add("rename index " + theOldIndexName + " to " + theNewIndexName);
break;

View File

@ -27,7 +27,7 @@ public class RenameColumnTaskDbSpecificTest {
@Test
public void testBuildSqlStatementForMariaDB() {
assertEquals("ALTER TABLE SOMETABLE CHANGE COLUMN myTextCol TO TEXTCOL", createRenameColumnSql(DriverTypeEnum.MARIADB_10_1));
assertEquals("ALTER TABLE SOMETABLE CHANGE COLUMN `myTextCol` `TEXTCOL` integer null", createRenameColumnSql(DriverTypeEnum.MARIADB_10_1));
}
@Test