Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import me.confuser.banmanager.common.runnables.Runner;
import me.confuser.banmanager.common.storage.*;
import me.confuser.banmanager.common.storage.global.*;
import me.confuser.banmanager.common.storage.migration.MigrationRunner;
import me.confuser.banmanager.common.storage.mariadb.MariaDBDatabase;
import me.confuser.banmanager.common.storage.mysql.MySQLDatabase;
import me.confuser.banmanager.common.util.DriverManagerUtil;
Expand Down Expand Up @@ -174,6 +175,17 @@ public final void enable() throws Exception {
throw new Exception("Unable to connect to database, ensure local is enabled in config and your connection details are correct");
}

ClassLoader cl = MigrationRunner.class.getClassLoader();

MigrationRunner localMigrations = new MigrationRunner(
this, localConn, config.getLocalDb(), "local", "players", cl);
localMigrations.migrate();

if (globalConn != null) {
MigrationRunner globalMigrations = new MigrationRunner(
this, globalConn, config.getGlobalDb(), "global", "playerBans", cl);
globalMigrations.migrate();
}

setupStorage();
} catch (SQLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public abstract class DatabaseConfig {
@Getter
private int connectionTimeout;
@Getter
private String instanceId;
@Getter
private HashMap<String, DatabaseTableConfig<?>> tables = new HashMap<>();

private File dataFolder;
Expand All @@ -62,6 +64,7 @@ private DatabaseConfig(File dataFolder, ConfigurationSection conf) {
verifyServerCertificate = conf.getBoolean("verifyServerCertificate", false);
maxLifetime = conf.getInt("maxLifetime", 1800000);
connectionTimeout = conf.getInt("connectionTimeout", 30000);
instanceId = conf.getString("instanceId", "");

if (maxConnections > 30) maxConnections = 30;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import me.confuser.banmanager.common.ormlite.support.ConnectionSource;
import me.confuser.banmanager.common.ormlite.table.DatabaseTableConfig;
import me.confuser.banmanager.common.ormlite.table.TableUtils;
import me.confuser.banmanager.common.util.StorageUtils;

import java.sql.SQLException;

Expand All @@ -30,28 +29,6 @@ public IpBanRecordStorage(BanManagerPlugin plugin) throws SQLException {

if (!this.isTableExists()) {
TableUtils.createTable(connectionSource, tableConfig);
} else {
// Attempt to add new columns
try {
String update = "ALTER TABLE " + tableConfig.getTableName() + " ADD COLUMN `createdReason` VARCHAR(255)";
executeRawNoArgs(update);
} catch (SQLException e) {
}
try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() + " ADD COLUMN `silent` TINYINT(1)");
} catch (SQLException e) {
}

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName()
+ " CHANGE `created` `created` BIGINT UNSIGNED,"
+ " CHANGE `pastCreated` `pastCreated` BIGINT UNSIGNED,"
+ " CHANGE `expired` `expired` BIGINT UNSIGNED"
);
} catch (SQLException e) {
}

StorageUtils.convertIpColumn(plugin, tableConfig.getTableName(), "ip");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import me.confuser.banmanager.common.ormlite.table.DatabaseTableConfig;
import me.confuser.banmanager.common.ormlite.table.TableUtils;
import me.confuser.banmanager.common.util.IPUtils;
import me.confuser.banmanager.common.util.StorageUtils;
import me.confuser.banmanager.common.util.TransactionHelper;
import me.confuser.banmanager.common.util.UUIDUtils;

Expand All @@ -39,22 +38,6 @@ public IpBanStorage(BanManagerPlugin plugin) throws SQLException {

if (!this.isTableExists()) {
TableUtils.createTable(connectionSource, tableConfig);
} else {
StorageUtils.convertIpColumn(plugin, tableConfig.getTableName(), "ip");

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() + " ADD COLUMN `silent` TINYINT(1)");
} catch (SQLException e) {
}

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName()
+ " CHANGE `created` `created` BIGINT UNSIGNED,"
+ " CHANGE `updated` `updated` BIGINT UNSIGNED,"
+ " CHANGE `expires` `expires` BIGINT UNSIGNED"
);
} catch (SQLException e) {
}
}

loadAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import me.confuser.banmanager.common.ormlite.support.ConnectionSource;
import me.confuser.banmanager.common.ormlite.table.DatabaseTableConfig;
import me.confuser.banmanager.common.ormlite.table.TableUtils;
import me.confuser.banmanager.common.util.StorageUtils;

import java.sql.SQLException;

Expand All @@ -29,22 +28,6 @@ public IpMuteRecordStorage(BanManagerPlugin plugin) throws SQLException {

if (!this.isTableExists()) {
TableUtils.createTable(connectionSource, tableConfig);
} else {
StorageUtils.convertIpColumn(plugin, tableConfig.getTableName(), "ip");

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() + " ADD COLUMN `silent` TINYINT(1)");
} catch (SQLException e) {
}

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName()
+ " CHANGE `created` `created` BIGINT UNSIGNED,"
+ " CHANGE `pastCreated` `pastCreated` BIGINT UNSIGNED,"
+ " CHANGE `expired` `expired` BIGINT UNSIGNED"
);
} catch (SQLException e) {
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import me.confuser.banmanager.common.ormlite.table.DatabaseTableConfig;
import me.confuser.banmanager.common.ormlite.table.TableUtils;
import me.confuser.banmanager.common.util.IPUtils;
import me.confuser.banmanager.common.util.StorageUtils;
import me.confuser.banmanager.common.util.TransactionHelper;
import me.confuser.banmanager.common.util.UUIDUtils;

Expand All @@ -36,22 +35,6 @@ public IpMuteStorage(BanManagerPlugin plugin) throws SQLException {

if (!this.isTableExists()) {
TableUtils.createTable(connectionSource, tableConfig);
} else {
StorageUtils.convertIpColumn(plugin, tableConfig.getTableName(), "ip");

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() + " ADD COLUMN `silent` TINYINT(1)");
} catch (SQLException e) {
}

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName()
+ " CHANGE `created` `created` BIGINT UNSIGNED,"
+ " CHANGE `updated` `updated` BIGINT UNSIGNED,"
+ " CHANGE `expires` `expires` BIGINT UNSIGNED"
);
} catch (SQLException e) {
}
}

loadAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import me.confuser.banmanager.common.ormlite.support.ConnectionSource;
import me.confuser.banmanager.common.ormlite.table.DatabaseTableConfig;
import me.confuser.banmanager.common.ormlite.table.TableUtils;
import me.confuser.banmanager.common.util.StorageUtils;

import java.sql.SQLException;

Expand All @@ -30,30 +29,6 @@ public IpRangeBanRecordStorage(BanManagerPlugin plugin) throws SQLException {

if (!this.isTableExists()) {
TableUtils.createTable(connectionSource, tableConfig);
} else {
// Attempt to add new columns
try {
String update = "ALTER TABLE " + tableConfig.getTableName() + " ADD COLUMN `createdReason` VARCHAR(255)";
executeRawNoArgs(update);
} catch (SQLException e) {
}

StorageUtils.convertIpColumn(plugin, tableConfig.getTableName(), "fromIp");
StorageUtils.convertIpColumn(plugin, tableConfig.getTableName(), "toIp");

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() + " ADD COLUMN `silent` TINYINT(1)");
} catch (SQLException e) {
}

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName()
+ " CHANGE `created` `created` BIGINT UNSIGNED,"
+ " CHANGE `pastCreated` `pastCreated` BIGINT UNSIGNED,"
+ " CHANGE `expired` `expired` BIGINT UNSIGNED"
);
} catch (SQLException e) {
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import me.confuser.banmanager.common.ormlite.table.DatabaseTableConfig;
import me.confuser.banmanager.common.ormlite.table.TableUtils;
import me.confuser.banmanager.common.util.IPUtils;
import me.confuser.banmanager.common.util.StorageUtils;
import me.confuser.banmanager.common.util.TransactionHelper;
import me.confuser.banmanager.common.util.UUIDUtils;

Expand All @@ -40,24 +39,6 @@ public IpRangeBanStorage(BanManagerPlugin plugin) throws SQLException {

if (!this.isTableExists()) {
TableUtils.createTable(connectionSource, tableConfig);
return;
} else {
StorageUtils.convertIpColumn(plugin, tableConfig.getTableName(), "fromIp");
StorageUtils.convertIpColumn(plugin, tableConfig.getTableName(), "toIp");

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() + " ADD COLUMN `silent` TINYINT(1)");
} catch (SQLException e) {
}

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName()
+ " CHANGE `created` `created` BIGINT UNSIGNED,"
+ " CHANGE `updated` `updated` BIGINT UNSIGNED,"
+ " CHANGE `expires` `expires` BIGINT UNSIGNED"
);
} catch (SQLException e) {
}
}

loadAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ public NameBanRecordStorage(BanManagerPlugin plugin) throws SQLException {

if (!this.isTableExists()) {
TableUtils.createTable(connectionSource, tableConfig);
return;
} else {
try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName()
+ " CHANGE `created` `created` BIGINT UNSIGNED,"
+ " CHANGE `pastCreated` `pastCreated` BIGINT UNSIGNED,"
+ " CHANGE `expired` `expired` BIGINT UNSIGNED"
);
} catch (SQLException e) {
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,6 @@ public NameBanStorage(BanManagerPlugin plugin) throws SQLException {

if (!this.isTableExists()) {
TableUtils.createTable(connectionSource, tableConfig);
return;
} else {
try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() + " ADD COLUMN `silent` TINYINT(1)");
} catch (SQLException e) {
}

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName()
+ " CHANGE `created` `created` BIGINT UNSIGNED,"
+ " CHANGE `updated` `updated` BIGINT UNSIGNED,"
+ " CHANGE `expires` `expires` BIGINT UNSIGNED"
);
} catch (SQLException e) {
}
}

loadAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,6 @@ public PlayerBanRecordStorage(BanManagerPlugin plugin) throws SQLException {

if (!this.isTableExists()) {
TableUtils.createTable(connectionSource, tableConfig);
return;
} else {
// Attempt to add new columns
try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() + " ADD COLUMN `createdReason` VARCHAR(255)");
} catch (SQLException e) {
}
try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() + " ADD COLUMN `silent` TINYINT(1)");
} catch (SQLException e) {
}

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName()
+ " CHANGE `created` `created` BIGINT UNSIGNED,"
+ " CHANGE `pastCreated` `pastCreated` BIGINT UNSIGNED,"
+ " CHANGE `expired` `expired` BIGINT UNSIGNED"
);
} catch (SQLException e) {
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,6 @@ public PlayerBanStorage(BanManagerPlugin plugin) throws SQLException {

if (!this.isTableExists()) {
TableUtils.createTable(connectionSource, tableConfig);
return;
} else {
try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() + " ADD COLUMN `silent` TINYINT(1)");
} catch (SQLException e) {
}

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName()
+ " CHANGE `created` `created` BIGINT UNSIGNED,"
+ " CHANGE `updated` `updated` BIGINT UNSIGNED,"
+ " CHANGE `expires` `expires` BIGINT UNSIGNED"
);
} catch (SQLException e) {
}
}

loadAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import me.confuser.banmanager.common.ormlite.support.ConnectionSource;
import me.confuser.banmanager.common.ormlite.table.DatabaseTableConfig;
import me.confuser.banmanager.common.ormlite.table.TableUtils;
import me.confuser.banmanager.common.util.StorageUtils;

import java.sql.SQLException;
import java.util.ArrayList;
Expand All @@ -37,35 +36,6 @@ public PlayerHistoryStorage(BanManagerPlugin plugin) throws SQLException {

if (!this.isTableExists()) {
TableUtils.createTable(connectionSource, tableConfig);
} else {
try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName()
+ " CHANGE `join` `join` BIGINT UNSIGNED,"
+ " CHANGE `leave` `leave` BIGINT UNSIGNED"
);
} catch (SQLException e) {
}

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName()
+ " MODIFY `ip` VARBINARY(16) NULL"
);
} catch (SQLException e) {
}

try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName()
+ " ADD COLUMN `name` VARCHAR(16) NOT NULL DEFAULT '' AFTER `player_id`"
);
} catch (SQLException e) {
}

try {
executeRawNoArgs("CREATE INDEX idx_playerhistory_name ON " + tableConfig.getTableName() + " (name)");
} catch (SQLException e) {
}

StorageUtils.convertIpColumn(plugin, tableConfig.getTableName(), "ip");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public PlayerKickStorage(BanManagerPlugin plugin) throws SQLException {

if (!this.isTableExists()) {
TableUtils.createTable(connectionSource, tableConfig);
} else {
try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() + " CHANGE `created` `created` BIGINT UNSIGNED");
} catch (SQLException e) {
}
}
}

Expand Down
Loading
Loading