Apply recent fixes for MySQL migration tasks to MariaDB as well.
This commit is contained in:
parent
5e3e7c46a8
commit
053094f2a6
|
@ -54,11 +54,11 @@ public class AddColumnTask extends BaseTableColumnTypeTask {
|
||||||
String sql;
|
String sql;
|
||||||
switch (getDriverType()) {
|
switch (getDriverType()) {
|
||||||
case MYSQL_5_7:
|
case MYSQL_5_7:
|
||||||
|
case MARIADB_10_1:
|
||||||
// Quote the column name as "SYSTEM" is a reserved word in MySQL
|
// Quote the column name as "SYSTEM" is a reserved word in MySQL
|
||||||
sql = "alter table " + getTableName() + " add column `" + getColumnName() + "` " + typeStatement;
|
sql = "alter table " + getTableName() + " add column `" + getColumnName() + "` " + typeStatement;
|
||||||
break;
|
break;
|
||||||
case DERBY_EMBEDDED:
|
case DERBY_EMBEDDED:
|
||||||
case MARIADB_10_1:
|
|
||||||
case POSTGRES_9_4:
|
case POSTGRES_9_4:
|
||||||
sql = "alter table " + getTableName() + " add column " + getColumnName() + " " + typeStatement;
|
sql = "alter table " + getTableName() + " add column " + getColumnName() + " " + typeStatement;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.intellij.lang.annotations.Language;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.sql.Driver;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -52,8 +53,8 @@ public class DropColumnTask extends BaseTableColumnTask {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getDriverType().equals(DriverTypeEnum.MYSQL_5_7)) {
|
if(getDriverType().equals(DriverTypeEnum.MYSQL_5_7) || getDriverType().equals(DriverTypeEnum.MARIADB_10_1)) {
|
||||||
// Some DBs such as MYSQL require that foreign keys depending on the column be dropped before the column itself is dropped.
|
// 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());
|
logInfo(ourLog, "Dropping any foreign keys on table {} depending on column {}", getTableName(), getColumnName());
|
||||||
Set<String> foreignKeys = JdbcUtils.getForeignKeysForColumn(getConnectionProperties(), getColumnName(), getTableName());
|
Set<String> foreignKeys = JdbcUtils.getForeignKeysForColumn(getConnectionProperties(), getColumnName(), getTableName());
|
||||||
if(foreignKeys != null) {
|
if(foreignKeys != null) {
|
||||||
|
|
|
@ -101,10 +101,10 @@ public class DropForeignKeyTask extends BaseTableTask {
|
||||||
List<String> sqls = new ArrayList<>();
|
List<String> sqls = new ArrayList<>();
|
||||||
switch (theDriverType) {
|
switch (theDriverType) {
|
||||||
case MYSQL_5_7:
|
case MYSQL_5_7:
|
||||||
|
case MARIADB_10_1:
|
||||||
// Lousy MYQL....
|
// Lousy MYQL....
|
||||||
sqls.add("alter table " + theTableName + " drop foreign key " + theConstraintName);
|
sqls.add("alter table " + theTableName + " drop foreign key " + theConstraintName);
|
||||||
break;
|
break;
|
||||||
case MARIADB_10_1:
|
|
||||||
case POSTGRES_9_4:
|
case POSTGRES_9_4:
|
||||||
case DERBY_EMBEDDED:
|
case DERBY_EMBEDDED:
|
||||||
case H2_EMBEDDED:
|
case H2_EMBEDDED:
|
||||||
|
|
|
@ -107,12 +107,10 @@ public class DropIndexTask extends BaseTableTask {
|
||||||
// Drop constraint
|
// Drop constraint
|
||||||
switch (theDriverType) {
|
switch (theDriverType) {
|
||||||
case MYSQL_5_7:
|
case MYSQL_5_7:
|
||||||
|
case MARIADB_10_1:
|
||||||
// Need to quote the index name as the word "PRIMARY" is reserved in MySQL
|
// Need to quote the index name as the word "PRIMARY" is reserved in MySQL
|
||||||
sql.add("alter table " + theTableName + " drop index `" + theIndexName + "`");
|
sql.add("alter table " + theTableName + " drop index `" + theIndexName + "`");
|
||||||
break;
|
break;
|
||||||
case MARIADB_10_1:
|
|
||||||
sql.add("alter table " + theTableName + " drop index " + theIndexName);
|
|
||||||
break;
|
|
||||||
case H2_EMBEDDED:
|
case H2_EMBEDDED:
|
||||||
sql.add("drop index " + theIndexName);
|
sql.add("drop index " + theIndexName);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -139,10 +139,8 @@ public class RenameColumnTask extends BaseTableTask {
|
||||||
case DERBY_EMBEDDED:
|
case DERBY_EMBEDDED:
|
||||||
sql = "RENAME COLUMN " + getTableName() + "." + myOldName + " TO " + myNewName;
|
sql = "RENAME COLUMN " + getTableName() + "." + myOldName + " TO " + myNewName;
|
||||||
break;
|
break;
|
||||||
case MARIADB_10_1:
|
|
||||||
sql = "ALTER TABLE " + getTableName() + " CHANGE COLUMN " + myOldName + " TO " + myNewName;
|
|
||||||
break;
|
|
||||||
case MYSQL_5_7:
|
case MYSQL_5_7:
|
||||||
|
case MARIADB_10_1:
|
||||||
// Quote the column names as "SYSTEM" is a reserved word in MySQL
|
// Quote the column names as "SYSTEM" is a reserved word in MySQL
|
||||||
sql = "ALTER TABLE " + getTableName() + " CHANGE COLUMN `" + myOldName + "` `" + myNewName + "` " + theExistingType + " " + theExistingNotNull;
|
sql = "ALTER TABLE " + getTableName() + " CHANGE COLUMN `" + myOldName + "` `" + myNewName + "` " + theExistingType + " " + theExistingNotNull;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -110,10 +110,10 @@ public class RenameIndexTask extends BaseTableTask {
|
||||||
// Drop constraint
|
// Drop constraint
|
||||||
switch (theDriverType) {
|
switch (theDriverType) {
|
||||||
case MYSQL_5_7:
|
case MYSQL_5_7:
|
||||||
|
case MARIADB_10_1:
|
||||||
// Quote the index names as "PRIMARY" is a reserved word in MySQL
|
// Quote the index names as "PRIMARY" is a reserved word in MySQL
|
||||||
sql.add("rename index `" + theOldIndexName + "` to `" + theNewIndexName + "`");
|
sql.add("rename index `" + theOldIndexName + "` to `" + theNewIndexName + "`");
|
||||||
break;
|
break;
|
||||||
case MARIADB_10_1:
|
|
||||||
case DERBY_EMBEDDED:
|
case DERBY_EMBEDDED:
|
||||||
sql.add("rename index " + theOldIndexName + " to " + theNewIndexName);
|
sql.add("rename index " + theOldIndexName + " to " + theNewIndexName);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class RenameColumnTaskDbSpecificTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildSqlStatementForMariaDB() {
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue