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:
@@ -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());
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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));
|
||||||
|
|||||||
@@ -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));
|
||||||
|
|||||||
Reference in New Issue
Block a user