This repository was archived by the owner on Dec 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: migrate from CHAR-based UUIDs to native UUID types in database schema #82
Merged
twisti-dev
merged 2 commits into
master
from
81-replace-uuid-string-columns-with-native-uuid-type-in-database
Jul 22, 2025
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
25 changes: 25 additions & 0 deletions
25
...er/src/main/kotlin/dev/slne/surf/cloud/api/server/exposed/columns/NativeUuidColumnType.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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package dev.slne.surf.cloud.api.server.exposed.columns | ||
|
|
||
| import org.intellij.lang.annotations.Language | ||
| import org.jetbrains.exposed.sql.Column | ||
| import org.jetbrains.exposed.sql.ColumnType | ||
| import org.jetbrains.exposed.sql.Table | ||
| import java.nio.ByteBuffer | ||
| import java.util.* | ||
|
|
||
| class NativeUuidColumnType : ColumnType<UUID>() { | ||
| @Language("SQL") | ||
| override fun sqlType() = "UUID" | ||
|
|
||
| override fun valueFromDB(value: Any): UUID? = when (value) { | ||
| is UUID -> value | ||
| is String if value.matches(CharUuidColumnType.uuidRegexp) -> UUID.fromString(value) | ||
| is String -> ByteBuffer.wrap(value.toByteArray()).let { UUID(it.long, it.long) } | ||
| is ByteArray -> ByteBuffer.wrap(value).let { UUID(it.long, it.long) } | ||
twisti-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| is ByteBuffer -> UUID(value.long, value.long) | ||
| else -> error("Unexpected value of type UUID: $value of ${value::class.qualifiedName}") | ||
| } | ||
| } | ||
|
|
||
| fun Table.nativeUuid(name: String): Column<UUID> = | ||
| registerColumn(name, NativeUuidColumnType()) | ||
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
4 changes: 2 additions & 2 deletions
4
...one/src/main/kotlin/dev/slne/surf/cloud/standalone/player/db/exposed/CloudPlayerTables.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
8 changes: 4 additions & 4 deletions
8
.../slne/surf/cloud/standalone/player/db/exposed/punishment/table/AbstractPunishmentTable.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
7 changes: 4 additions & 3 deletions
7
...dalone/player/db/exposed/punishment/table/AbstractUnpunishableExpirablePunishmentTable.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
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
45 changes: 45 additions & 0 deletions
45
...d-standalone/src/main/resources/db/migration/V5__replace_string_uuid_with_native_uuid.sql
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,45 @@ | ||
| -- V5__replace_string_uuid_with_native_uuid.sql | ||
| -- Migration to replace CHAR(36) UUID columns with native UUID types | ||
| -- Assumes data is UUID-valid and castable | ||
|
|
||
| -- Convert `cloud_player`.`uuid` | ||
| ALTER TABLE cloud_player | ||
| MODIFY COLUMN uuid UUID NOT NULL; | ||
|
|
||
| -- Convert `punish_bans` UUID columns | ||
| ALTER TABLE punish_bans | ||
| MODIFY COLUMN punished_uuid UUID NOT NULL, | ||
| MODIFY COLUMN issuer_uuid UUID NULL, | ||
| MODIFY COLUMN unpunisher_uuid UUID NULL; | ||
|
|
||
| -- Convert `punish_kicks` UUID columns | ||
| ALTER TABLE punish_kicks | ||
| MODIFY COLUMN punished_uuid UUID NOT NULL, | ||
| MODIFY COLUMN issuer_uuid UUID NULL; | ||
|
|
||
| -- Convert `punish_mutes` UUID columns | ||
| ALTER TABLE punish_mutes | ||
| MODIFY COLUMN punished_uuid UUID NOT NULL, | ||
| MODIFY COLUMN issuer_uuid UUID NULL, | ||
| MODIFY COLUMN unpunisher_uuid UUID NULL; | ||
|
|
||
| -- Convert `punish_notes_ban`.`note_id` | ||
| ALTER TABLE punish_notes_ban | ||
| MODIFY COLUMN note_id UUID NOT NULL; | ||
|
|
||
| -- Convert `punish_notes_kick`.`note_id` | ||
| ALTER TABLE punish_notes_kick | ||
| MODIFY COLUMN note_id UUID NOT NULL; | ||
|
|
||
| -- Convert `punish_notes_mute`.`note_id` | ||
| ALTER TABLE punish_notes_mute | ||
| MODIFY COLUMN note_id UUID NOT NULL; | ||
|
|
||
| -- Convert `punish_notes_warn`.`note_id` | ||
| ALTER TABLE punish_notes_warn | ||
| MODIFY COLUMN note_id UUID NOT NULL; | ||
|
|
||
| -- Convert `punish_warnings` UUID columns | ||
| ALTER TABLE punish_warnings | ||
| MODIFY COLUMN punished_uuid UUID NOT NULL, | ||
| MODIFY COLUMN issuer_uuid UUID NULL; |
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.