Skip to content

Commit 5898293

Browse files
committed
fix(database): V3 migration — convert UUID columns from BINARY(16) to native uuid type
Hibernate ORM 7 maps java.util.UUID to MariaDB's native uuid type, but the V1 baseline created elytra_players.playerId and game_results.player_id as BINARY(16). This caused two runtime errors: - hbm2ddl=update tried to ALTER the columns but MariaDB refused due to FK - INSERT failed with 'Data too long' because Hibernate sends UUID as a 36-char string, not 16-byte binary V3 drops fk_game_results_player, converts both columns to uuid NOT NULL, and re-adds the FK. Safe on fresh installs too (no-op if already uuid).
1 parent 5af240b commit 5898293

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- =============================================================================
2+
-- V3__fix_uuid_column_types.sql
3+
-- =============================================================================
4+
-- Hibernate ORM 7 maps java.util.UUID to MariaDB's native `uuid` type.
5+
-- The V1 baseline created both UUID columns as BINARY(16), causing Hibernate's
6+
-- hbm2ddl=update to attempt an ALTER that MariaDB rejects because the FK
7+
-- fk_game_results_player references elytra_players.playerId.
8+
--
9+
-- Fix: drop the FK, convert both columns, re-add the FK.
10+
-- Safe to run on fresh databases too: MODIFY COLUMN is a no-op when the
11+
-- column type is already `uuid NOT NULL`.
12+
-- =============================================================================
13+
14+
ALTER TABLE game_results DROP FOREIGN KEY fk_game_results_player;
15+
16+
ALTER TABLE elytra_players MODIFY COLUMN playerId uuid NOT NULL;
17+
ALTER TABLE game_results MODIFY COLUMN player_id uuid NOT NULL;
18+
19+
ALTER TABLE game_results ADD CONSTRAINT fk_game_results_player
20+
FOREIGN KEY (player_id) REFERENCES elytra_players (playerId);

0 commit comments

Comments
 (0)