forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use UTF8/InnoDB for new MySQL tables (metabase#11742)
* Move Liquibase code to different namespace * Append ENGINE/CHARACTER SET/COLLATE to all MySQL CREATE TABLE statements [ci mysql] * Test fixes; make sure read-column impls check for nil [ci drivers]
- Loading branch information
Showing
18 changed files
with
366 additions
and
232 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
java/metabase/db/liquibase/MetabaseMySqlCreateTableSqlGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package metabase.db.liquibase; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import liquibase.database.Database; | ||
import liquibase.database.core.MySQLDatabase; | ||
import liquibase.exception.ValidationErrors; | ||
import liquibase.sql.Sql; | ||
import liquibase.sql.UnparsedSql; | ||
import liquibase.sqlgenerator.SqlGeneratorChain; | ||
import liquibase.sqlgenerator.core.AbstractSqlGenerator; | ||
import liquibase.sqlgenerator.core.CreateTableGenerator; | ||
import liquibase.statement.core.CreateTableStatement; | ||
import liquibase.structure.DatabaseObject; | ||
|
||
// This class is a simple wrapper around a CreateTableGenerator that appends ENGINE InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci to the generated SQL | ||
public class MetabaseMySqlCreateTableSqlGenerator extends AbstractSqlGenerator<CreateTableStatement> { | ||
private CreateTableGenerator parentGenerator; | ||
|
||
public MetabaseMySqlCreateTableSqlGenerator() { | ||
this.parentGenerator = new CreateTableGenerator(); | ||
} | ||
|
||
@Override | ||
public boolean supports(CreateTableStatement statement, Database database) { | ||
return parentGenerator.supports(statement, database) && (database instanceof MySQLDatabase); | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
return parentGenerator.getPriority() + 1; | ||
} | ||
|
||
@Override | ||
public Sql[] generateSql(CreateTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { | ||
Sql[] sqls = this.parentGenerator.generateSql(statement, database, sqlGeneratorChain); | ||
for (int i = 0; i < sqls.length; i++) { | ||
Sql sql = sqls[i]; | ||
if (!sql.toSql().startsWith("CREATE TABLE")) continue; | ||
|
||
Collection<? extends DatabaseObject> affectedObjects = sql.getAffectedDatabaseObjects(); | ||
|
||
sqls[i] = new UnparsedSql(sql.toSql() + " ENGINE InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci", | ||
sql.getEndDelimiter(), | ||
affectedObjects.toArray(new DatabaseObject[affectedObjects.size()])); | ||
} | ||
return sqls; | ||
} | ||
|
||
@Override | ||
public ValidationErrors validate(CreateTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { | ||
return this.parentGenerator.validate(statement, database, sqlGeneratorChain); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.