diff --git a/src/main/java/ru/tehkode/permissions/backends/sql/SQLBackend.java b/src/main/java/ru/tehkode/permissions/backends/sql/SQLBackend.java index 4a7319518..b09e01c1b 100644 --- a/src/main/java/ru/tehkode/permissions/backends/sql/SQLBackend.java +++ b/src/main/java/ru/tehkode/permissions/backends/sql/SQLBackend.java @@ -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); } @@ -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 @@ -557,6 +562,7 @@ private void writeTable(String table, SQLConnection conn, Writer writer) throws @Override public void close() throws PermissionBackendException { + super.close(); if (ds != null) { try { ds.close(); @@ -564,7 +570,6 @@ public void close() throws PermissionBackendException { throw new PermissionBackendException("Error while closing", e); } } - super.close(); } } diff --git a/src/main/resources/sql/mysql/deploy.sql b/src/main/resources/sql/mysql/deploy.sql index a28d0794d..cd0312bc9 100644 --- a/src/main/resources/sql/mysql/deploy.sql +++ b/src/main/resources/sql/mysql/deploy.sql @@ -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}` ( @@ -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, @@ -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;