Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

Commit

Permalink
Add backwards compatibility for SQL encodings with older MySQL versions
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Jan 17, 2015
1 parent b7443ee commit 2a21e89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ public void performUpdate() throws PermissionBackendException {
// Change collation for all columns to utf8mb4_general_ci
try (SQLConnection conn = getSQL()) {
conn.prep("ALTER TABLE `{permissions}` DROP KEY `unique`, MODIFY COLUMN `permission` TEXT NOT NULL").execute();
conn.prep("ALTER TABLE `{permissions}` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci").execute();
conn.prep("ALTER TABLE `{permissions_entity}` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci").execute();
conn.prep("ALTER TABLE `{permissions_inheritance}` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci").execute();
} catch (SQLException | IOException e) {
throw new PermissionBackendException(e);
}
Expand Down Expand Up @@ -194,6 +191,14 @@ public void performUpdate() throws PermissionBackendException {
this.setupAliases();
this.deployTables();
performSchemaUpdate();

try (SQLConnection conn = getSQL()) {
conn.prep("ALTER TABLE `{permissions}` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci").execute();
conn.prep("ALTER TABLE `{permissions_entity}` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci").execute();
conn.prep("ALTER TABLE `{permissions_inheritance}` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci").execute();
} catch (SQLException | IOException e) {
// Ignore, this MySQL version just doesn't support it.
}
}

@Override
Expand Down Expand Up @@ -557,14 +562,14 @@ private void writeTable(String table, SQLConnection conn, Writer writer) throws

@Override
public void close() throws PermissionBackendException {
super.close();
if (ds != null) {
try {
ds.close();
} catch (SQLException e) {
throw new PermissionBackendException("Error while closing", e);
}
}
super.close();
}

}
6 changes: 3 additions & 3 deletions src/main/resources/sql/mysql/deploy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS `{permissions}` (
#UNIQUE KEY `unique` (`name`,`permission`,`world`,`type`),
KEY `user` (`name`,`type`),
KEY `world` (`world`,`name`,`type`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;


CREATE TABLE IF NOT EXISTS `{permissions_entity}` (
Expand All @@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS `{permissions_entity}` (
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`, `type`),
KEY `default` (`default`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS `{permissions_inheritance}` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand All @@ -32,4 +32,4 @@ CREATE TABLE IF NOT EXISTS `{permissions_inheritance}` (
UNIQUE KEY `child` (`child`,`parent`,`type`,`world`),
KEY `child_2` (`child`,`type`),
KEY `parent` (`parent`,`type`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

0 comments on commit 2a21e89

Please sign in to comment.