Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Conversation

@twisti-dev
Copy link
Contributor

Overview of Changes

Replaced all usages of CHAR(36)-based UUID columns in both application schema definitions and actual database migration scripts with native UUID types. This includes creating a new NativeUuidColumnType, updating Exposed table definitions, and modifying the relevant SQL migration.

Details

  • Refactor: Introduced NativeUuidColumnType

    • Added a new NativeUuidColumnType in exposed/columns, supporting native SQL UUID storage with robust deserialization from multiple formats (UUID, ByteArray, String, ByteBuffer).
    • Created helper method nativeUuid() for easier column registration.
  • Refactor: Updated Table Column Definitions

    • Replaced charUuid() usages with nativeUuid() in the following tables:
      • CloudPlayerTable
      • AbstractPunishmentTable
      • AbstractUnpunishableExpirablePunishmentTable
      • AbstractPunishmentNoteTable
    • Updated imports to reflect the new column usage.
  • Refactor: Simplified Imports in Migration Script Generator

    • Replaced explicit punishment table imports with wildcard to reduce boilerplate.
    • Updated script name to match the new migration (V5).
  • Migration Script: V5__replace_string_uuid_with_native_uuid.sql

    • Adds ALTER statements to convert UUID-related columns from CHAR(36) to native UUID types in all affected tables:
      • cloud_player
      • punish_bans
      • punish_kicks
      • punish_mutes
      • punish_notes_*
      • punish_warnings

Motivation

The use of native UUID types improves database performance, storage efficiency, and compatibility with UUID-aware tools and platforms. It also aligns better with type-safe practices in Kotlin and Exposed.

Impact

  • Reduces storage overhead by using a more compact representation of UUIDs.
  • Enhances data integrity by leveraging the database's native UUID validation.
  • Simplifies future development by avoiding UUID string parsing and formatting issues.

Testing

  • Manually verified updated tables compile and match expected SQL definitions.
  • Confirmed schema migration script (V5__replace_string_uuid_with_native_uuid.sql) runs without errors on test databases.
  • Ensured UUID parsing logic handles all expected formats gracefully via Exposed column type tests.

Additional Notes

  • Migration assumes UUID strings already stored in the DB are valid and convertible.
  • Consider adding integration tests to validate full CRUD behavior with native UUID columns post-migration.

Closes #81

@twisti-dev twisti-dev requested a review from Copilot July 22, 2025 15:15
@twisti-dev twisti-dev self-assigned this Jul 22, 2025
@twisti-dev twisti-dev linked an issue Jul 22, 2025 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates from CHAR(36) UUID columns to native UUID types in the database schema to improve performance, storage efficiency, and type safety.

  • Introduces NativeUuidColumnType with robust UUID deserialization from multiple formats
  • Updates all table definitions to use nativeUuid() instead of charUuid()
  • Adds SQL migration script to convert existing CHAR(36) columns to native UUID types

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
NativeUuidColumnType.kt New column type implementation for native UUID support
CharUuidColumnType.kt Refactored UUID regex visibility and improved value parsing logic
CloudPlayerTables.kt Updated uuid column to use native UUID type
AbstractPunishmentTable.kt Converted punishment UUID columns to native type
AbstractUnpunishableExpirablePunishmentTable.kt Updated unpunisher UUID column to native type
PunishmentNoteTables.kt Converted note ID column to native UUID type
GenerateExposedMigrationScript.kt Updated imports and migration script name
V5__replace_string_uuid_with_native_uuid.sql Migration script to alter existing tables

…surf/cloud/api/server/exposed/columns/NativeUuidColumnType.kt

Co-authored-by: Copilot <[email protected]>
@twisti-dev twisti-dev merged commit 5fb2ff4 into master Jul 22, 2025
@twisti-dev twisti-dev deleted the 81-replace-uuid-string-columns-with-native-uuid-type-in-database branch July 22, 2025 15:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace uuid String Columns with Native UUID Type in Database

2 participants