Files
MusicServer/internal/db/migrations/000007_add_uuid_and_backfill.up.sql
T
Sansan 0f552282f3 step 2: Add UUID columns with backfill and dual-write support
- Add migration 000007: Add UUID columns to soundtrack and song with backfill
- Update InsertSoundtrack and InsertSoundtrackWithExistingId to accept UUID
- Update AddSong to accept UUID
- Add dual-write: Go code now generates UUIDs for new records
- Add uuid and pgtype imports

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-01 22:40:21 +02:00

22 lines
826 B
SQL

-- Migration: Add UUID columns to soundtrack and song, then backfill
-- Add UUID column to soundtrack (nullable for now)
ALTER TABLE soundtrack ADD COLUMN uuid UUID NULL UNIQUE;
-- Create index on uuid for performance
CREATE INDEX IF NOT EXISTS idx_soundtrack_uuid ON soundtrack(uuid);
-- Add UUID column to song (nullable for now)
ALTER TABLE song ADD COLUMN uuid UUID NULL UNIQUE;
-- Create index on uuid for performance
CREATE INDEX IF NOT EXISTS idx_song_uuid ON song(uuid);
-- Backfill existing records immediately
UPDATE soundtrack SET uuid = gen_random_uuid() WHERE uuid IS NULL;
UPDATE song SET uuid = gen_random_uuid() WHERE uuid IS NULL;
-- Verify no nulls remain
-- SELECT COUNT(*) FROM soundtrack WHERE uuid IS NULL; -- Should be 0
-- SELECT COUNT(*) FROM song WHERE uuid IS NULL; -- Should be 0