-
Notifications
You must be signed in to change notification settings - Fork 0
add: mysql driver and new mysql/mariadb schema #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /** | ||
| MySQL-spezifisches Schema für den v3 Backend. | ||
| Diese Datei enthält Anpassungen für MySQL/MariaDB. | ||
| Wird automatisch verwendet, wenn MySQL als Datenbank konfiguriert ist. | ||
| */ | ||
|
|
||
| CREATE TABLE IF NOT EXISTS cloud_servers ( | ||
| unique_id VARCHAR(36) NOT NULL PRIMARY KEY, | ||
| group_name VARCHAR(255) NOT NULL, | ||
| host_id VARCHAR(36) NOT NULL, | ||
| numerical_id INT NOT NULL, | ||
| ip VARCHAR(45) NOT NULL, | ||
| port INT NOT NULL, | ||
| minimum_memory INT NOT NULL, | ||
| maximum_memory INT NOT NULL, | ||
| max_players INT NOT NULL, | ||
| player_count INT NOT NULL, | ||
| state VARCHAR(50) NOT NULL, | ||
| type VARCHAR(50) NOT NULL, | ||
| created_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
| updated_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS cloud_server_properties ( | ||
| server_id VARCHAR(36) NOT NULL, | ||
| `key` VARCHAR(255) NOT NULL, | ||
| value TEXT, | ||
| PRIMARY KEY (server_id, `key`), | ||
| CONSTRAINT fk_server_props_server FOREIGN KEY (server_id) | ||
| REFERENCES cloud_servers(unique_id) ON DELETE CASCADE | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS oauth2_client_details ( | ||
| client_id VARCHAR(36) PRIMARY KEY, | ||
| client_secret VARCHAR(255), | ||
| redirect_uri VARCHAR(512), | ||
| grant_types TEXT, | ||
| scope TEXT | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS oauth2_users ( | ||
| user_id VARCHAR(36) PRIMARY KEY, | ||
| scopes TEXT, | ||
| username VARCHAR(255) UNIQUE NOT NULL, | ||
| hashed_password VARCHAR(255) NOT NULL | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS oauth2_tokens ( | ||
| token_id VARCHAR(36) PRIMARY KEY, | ||
| client_id VARCHAR(36), | ||
| access_token TEXT, | ||
| scope TEXT, | ||
| expires_in TIMESTAMP NULL DEFAULT NULL, | ||
| user_id VARCHAR(36), | ||
| CONSTRAINT fk_token_user FOREIGN KEY (user_id) | ||
| REFERENCES oauth2_users(user_id) ON DELETE CASCADE, | ||
| CONSTRAINT fk_token_client FOREIGN KEY (client_id) | ||
| REFERENCES oauth2_client_details(client_id) ON DELETE CASCADE | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS oauth2_groups ( | ||
| group_name VARCHAR(255) PRIMARY KEY, | ||
| scopes TEXT | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS oauth2_user_groups ( | ||
| user_id VARCHAR(36), | ||
| group_name VARCHAR(255), | ||
| PRIMARY KEY (user_id, group_name) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; |
34 changes: 26 additions & 8 deletions
34
controller-runtime/src/main/kotlin/app/simplecloud/controller/runtime/database/Database.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,40 @@ | ||
| package app.simplecloud.controller.runtime.database | ||
|
|
||
| import org.apache.logging.log4j.LogManager | ||
| import org.jooq.DSLContext | ||
| import org.jooq.SQLDialect | ||
| import org.jooq.impl.DSL | ||
|
|
||
| class Database( | ||
| val context: DSLContext | ||
| ) { | ||
|
|
||
| private val logger = LogManager.getLogger(Database::class.java) | ||
|
|
||
| fun setup() { | ||
| System.setProperty("org.jooq.no-logo", "true") | ||
| System.setProperty("org.jooq.no-tips", "true") | ||
| val setupInputStream = Database::class.java.getResourceAsStream("/schema.sql") | ||
| ?: throw IllegalArgumentException("Database schema not found.") | ||
| val setupCommands = setupInputStream.bufferedReader().use { it.readText() }.split(";") | ||
| setupCommands.forEach { | ||
| val trimmed = it.trim() | ||
| if (trimmed.isNotEmpty()) | ||
| context.execute(org.jooq.impl.DSL.sql(trimmed)) | ||
|
|
||
| val schemaFile = when (context.dialect().family()) { | ||
| SQLDialect.MARIADB, SQLDialect.MYSQL -> "/schema/mysql.sql" | ||
| else -> "/schema/default.sql" | ||
| } | ||
|
|
||
| val setupInputStream = Database::class.java.getResourceAsStream(schemaFile) | ||
| ?: throw IllegalArgumentException("Database schema not found: $schemaFile") | ||
|
|
||
| val setupCommands = setupInputStream.bufferedReader().use { it.readText() } | ||
| .split(";") | ||
| .map { it.trim() } | ||
| .filter { it.isNotEmpty() } | ||
|
|
||
| setupCommands.forEach { command -> | ||
| try { | ||
| context.execute(DSL.using(context.dialect()).parser().parseQuery(command)) | ||
| } catch (e: Exception) { | ||
| logger.error("Error executing SQL command: {}", command, e) | ||
| throw e | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.