b0418b4f38
- Add id serial4 PK to song table (was composite PK) - Update queries to use soundtrack_id + path - Add UUID columns to soundtrack and song (nullable) - Add migration tracking table TODO: Run sqlc generate, then create backfill migration (000008) Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
25 lines
852 B
SQL
25 lines
852 B
SQL
-- Rollback: Remove id column and restore composite PK
|
|
|
|
-- Step 1: Drop indexes created in up migration
|
|
DROP INDEX IF EXISTS idx_song_soundtrack_id;
|
|
DROP INDEX IF EXISTS idx_song_path;
|
|
|
|
-- Step 2: Drop foreign key constraint
|
|
ALTER TABLE song DROP CONSTRAINT IF EXISTS song_soundtrack_id_fkey;
|
|
|
|
-- Step 3: Drop new primary key
|
|
ALTER TABLE song DROP CONSTRAINT song_pkey;
|
|
|
|
-- Step 4: Drop unique constraint on id
|
|
ALTER TABLE song DROP CONSTRAINT IF EXISTS song_id_unique;
|
|
|
|
-- Step 5: Restore composite primary key
|
|
ALTER TABLE song ADD CONSTRAINT song_pkey PRIMARY KEY (soundtrack_id, path);
|
|
|
|
-- Step 6: Drop the id column
|
|
ALTER TABLE song DROP COLUMN id;
|
|
|
|
-- Step 7: Recreate original foreign key (soundtrack_id references soundtrack.id)
|
|
ALTER TABLE song ADD CONSTRAINT song_soundtrack_id_fkey
|
|
FOREIGN KEY (soundtrack_id) REFERENCES soundtrack(id);
|