Merge pull request #13 from blockgamecode/feat/table_prefix

add setting to change mysql table prefix
This commit is contained in:
Kiran Hart 2022-10-18 18:54:19 -04:00 committed by GitHub
commit 6108855ce5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 3 deletions

View File

@ -168,7 +168,10 @@ public class AuctionHouse extends TweetyPlugin {
// Setup the database if enabled
this.databaseConnector = Settings.DATABASE_USE.getBoolean() ? new MySQLConnector(this, Settings.DATABASE_HOST.getString(), Settings.DATABASE_PORT.getInt(), Settings.DATABASE_NAME.getString(), Settings.DATABASE_USERNAME.getString(), Settings.DATABASE_PASSWORD.getString(), Settings.DATABASE_USE_SSL.getBoolean()) : new SQLiteConnector(this);
this.dataManager = new DataManager(this.databaseConnector, this);
// Use a custom table prefix if using a remote database. The default prefix setting acts exactly like if the prefix is null
final String tablePrefix = Settings.DATABASE_USE.getBoolean() ? Settings.DATABASE_TABLE_PREFIX.getString() : null;
this.dataManager = new DataManager(this.databaseConnector, this, tablePrefix);
DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager,
new _1_InitialMigration(),

View File

@ -42,7 +42,7 @@ public final class CommandUpload extends AbstractCommand {
if (!args[0].equalsIgnoreCase("-confirm")) return ReturnType.FAILURE;
DatabaseConnector databaseConnector = new SQLiteConnector(AuctionHouse.getInstance());
DataManager manager = new DataManager(databaseConnector, AuctionHouse.getInstance());
DataManager manager = new DataManager(databaseConnector, AuctionHouse.getInstance(), null);
manager.getItems((error, items) -> {
if (error == null)

View File

@ -39,8 +39,16 @@ public class DataManager extends DataManagerAbstract {
private final ExecutorService thread = Executors.newSingleThreadExecutor();
public DataManager(DatabaseConnector databaseConnector, Plugin plugin) {
private final @Nullable String customTablePrefix;
public DataManager(DatabaseConnector databaseConnector, Plugin plugin, @Nullable String customTablePrefix) {
super(databaseConnector, plugin);
this.customTablePrefix = customTablePrefix;
}
@Override
public String getTablePrefix() {
return customTablePrefix == null ? super.getTablePrefix() : customTablePrefix;
}
public void close() {

View File

@ -241,6 +241,7 @@ public class Settings {
* DATABASE OPTIONS
* ===============================*/
public static final ConfigSetting DATABASE_USE = new ConfigSetting(config, "database.use database", false, "Should the plugin use a database to store shop data?");
public static final ConfigSetting DATABASE_TABLE_PREFIX = new ConfigSetting(config, "database.table prefix", "auctionhouse_", "What prefix should be used for table names");
public static final ConfigSetting DATABASE_HOST = new ConfigSetting(config, "database.host", "localhost", "What is the connection url/host");
public static final ConfigSetting DATABASE_PORT = new ConfigSetting(config, "database.port", 3306, "What is the port to database (default is 3306)");
public static final ConfigSetting DATABASE_NAME = new ConfigSetting(config, "database.name", "plugin_dev", "What is the name of the database?");