throw new PermissionBackendException("Unable to connect to SQL database", e);
}
getManager().getLogger().info("Successfully connected to SQL database");
addSchemaUpdate(new SchemaUpdate(2) {
@Override
public void performUpdate() throws PermissionBackendException {
// Change encoding for all columns to utf8mb4
// 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);
}
}
});
addSchemaUpdate(new SchemaUpdate(1) {
@Override
public void performUpdate() throws PermissionBackendException {
try (SQLConnection conn = getSQL()) {
PreparedStatement updateStmt = conn.prep("entity.options.add");
ResultSet res = conn.prepAndBind("SELECT `name`, `type` FROM `{permissions_entity}` WHERE `default`='1'").executeQuery();
while (res.next()) {
conn.bind(updateStmt, res.getString("name"), res.getInt("type"), "default", "", "true");
updateStmt.addBatch();
}
updateStmt.executeBatch();
// Update tables
conn.prep("ALTER TABLE `{permissions_entity}` DROP COLUMN `default`").execute();
} catch (SQLException | IOException e) {
throw new PermissionBackendException(e);
}
}
});
addSchemaUpdate(new SchemaUpdate(0) {
@Override
public void performUpdate() throws PermissionBackendException {
try (SQLConnection conn = getSQL()) {
// TODO: Table modifications not supported in SQLite
// Prefix/sufix -> options