-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmigrate_map_id_to_integer.sql
More file actions
39 lines (30 loc) · 1.14 KB
/
migrate_map_id_to_integer.sql
File metadata and controls
39 lines (30 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- Migration script to change maps.id from UUID to SERIAL (auto-incrementing integer)
-- This will make the map_id smaller and more manageable
-- Step 1: Create a new temporary column with SERIAL type
ALTER TABLE maps ADD COLUMN new_id SERIAL;
-- Step 2: Update any foreign key references (if they exist)
-- Note: Check if there are any tables that reference maps.id before running this
-- Step 3: Drop the old UUID primary key constraint
ALTER TABLE maps DROP CONSTRAINT maps_pkey;
-- Step 4: Drop the old id column
ALTER TABLE maps DROP COLUMN id;
-- Step 5: Rename the new column to id
ALTER TABLE maps RENAME COLUMN new_id TO id;
-- Step 6: Add the new primary key constraint
ALTER TABLE maps ADD PRIMARY KEY (id);
-- Step 7: Create an index for better performance (optional, since PRIMARY KEY creates one)
-- CREATE INDEX IF NOT EXISTS maps_id_idx ON maps (id);
-- Verify the changes
SELECT
column_name,
data_type,
is_nullable,
column_default
FROM information_schema.columns
WHERE table_name = 'maps'
AND column_name = 'id';
-- Show sample of updated records
SELECT id, title, type, created_at
FROM maps
ORDER BY id
LIMIT 5;