9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-19 14:59:21 +00:00

feat: add create_tables config option to disable automatic DDL operations (#377)

* Add config option for creating tables

* Move createTables config to a better position
This commit is contained in:
Coded
2024-09-28 14:32:53 +01:00
committed by GitHub
parent 2d5648408e
commit 842ec0e28d
4 changed files with 13 additions and 0 deletions

View File

@@ -141,6 +141,9 @@ public class Settings {
@Getter(AccessLevel.NONE) @Getter(AccessLevel.NONE)
private Map<String, String> tableNames = Database.TableName.getDefaults(); private Map<String, String> tableNames = Database.TableName.getDefaults();
@Comment("Whether to run the creation SQL on the database when the server starts. Don't modify this unless you know what you're doing!")
private boolean createTables = true;
@NotNull @NotNull
public String getTableName(@NotNull Database.TableName tableName) { public String getTableName(@NotNull Database.TableName tableName) {
return tableNames.getOrDefault(tableName.name().toLowerCase(Locale.ENGLISH), tableName.getDefaultName()); return tableNames.getOrDefault(tableName.name().toLowerCase(Locale.ENGLISH), tableName.getDefaultName());

View File

@@ -64,6 +64,10 @@ public class MongoDbDatabase extends Database {
ConnectionString URI = createConnectionURI(credentials); ConnectionString URI = createConnectionURI(credentials);
mongoConnectionHandler = new MongoConnectionHandler(URI, credentials.getDatabase()); mongoConnectionHandler = new MongoConnectionHandler(URI, credentials.getDatabase());
mongoCollectionHelper = new MongoCollectionHelper(mongoConnectionHandler); mongoCollectionHelper = new MongoCollectionHelper(mongoConnectionHandler);
// Check config for if tables should be created
if (!plugin.getSettings().getDatabase().isCreateTables()) return;
if (mongoCollectionHelper.getCollection(usersTable) == null) { if (mongoCollectionHelper.getCollection(usersTable) == null) {
mongoCollectionHelper.createCollection(usersTable); mongoCollectionHelper.createCollection(usersTable);
} }

View File

@@ -115,6 +115,9 @@ public class MySqlDatabase extends Database {
); );
dataSource.setDataSourceProperties(properties); dataSource.setDataSourceProperties(properties);
// Check config for if tables should be created
if (!plugin.getSettings().getDatabase().isCreateTables()) return;
// Prepare database schema; make tables if they don't exist // Prepare database schema; make tables if they don't exist
try (Connection connection = dataSource.getConnection()) { try (Connection connection = dataSource.getConnection()) {
final String[] databaseSchema = getSchemaStatements(String.format("database/%s_schema.sql", flavor)); final String[] databaseSchema = getSchemaStatements(String.format("database/%s_schema.sql", flavor));

View File

@@ -108,6 +108,9 @@ public class PostgresDatabase extends Database {
); );
dataSource.setDataSourceProperties(properties); dataSource.setDataSourceProperties(properties);
// Check config for if tables should be created
if (!plugin.getSettings().getDatabase().isCreateTables()) return;
// Prepare database schema; make tables if they don't exist // Prepare database schema; make tables if they don't exist
try (Connection connection = dataSource.getConnection()) { try (Connection connection = dataSource.getConnection()) {
final String[] databaseSchema = getSchemaStatements(String.format("database/%s_schema.sql", flavor)); final String[] databaseSchema = getSchemaStatements(String.format("database/%s_schema.sql", flavor));