Skip to content

Commit 375081e

Browse files
committed
Fixed bad migration
1 parent 1b5c459 commit 375081e

1 file changed

Lines changed: 83 additions & 46 deletions

File tree

Lines changed: 83 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,96 @@
11
-- Room backgrounds: PNG assets in /public/room with ids room-1 .. room-4.
2+
-- Drop legacy check before rewriting values (old ids: room-day, room-dusk, etc.).
3+
alter table
4+
public.avatar_state drop constraint if exists avatar_state_room_background_check;
25

3-
alter table public.avatar_state
4-
alter column room_background set default 'room-1';
5-
6-
update public.avatar_state
7-
set room_background = case room_background
8-
when 'room-day' then 'room-1'
9-
when 'room-dusk' then 'room-2'
10-
when 'room-night' then 'room-3'
11-
when 'room-forest' then 'room-4'
12-
when 'room-space' then 'room-1'
13-
when 'room-neon' then 'room-1'
14-
else room_background
15-
end
16-
where room_background in (
17-
'room-day',
18-
'room-dusk',
19-
'room-night',
20-
'room-forest',
21-
'room-space',
22-
'room-neon'
23-
);
24-
25-
update public.user_items
26-
set item_id = case item_id
27-
when 'room-night' then 'room-3'
28-
when 'room-forest' then 'room-4'
29-
else item_id
30-
end
31-
where item_id in ('room-night', 'room-forest');
32-
33-
delete from public.shop_items
34-
where id in ('room-night', 'room-forest');
6+
update
7+
public.avatar_state
8+
set
9+
room_background = case
10+
room_background
11+
when 'room-day' then 'room-1'
12+
when 'room-dusk' then 'room-2'
13+
when 'room-night' then 'room-3'
14+
when 'room-forest' then 'room-4'
15+
when 'room-space' then 'room-1'
16+
when 'room-neon' then 'room-1'
17+
else room_background
18+
end
19+
where
20+
room_background in (
21+
'room-day',
22+
'room-dusk',
23+
'room-night',
24+
'room-forest',
25+
'room-space',
26+
'room-neon'
27+
);
3528

36-
insert into public.shop_items (id, name, type, price, image_path)
37-
values
38-
('room-3', 'Starlit Night', 'room', 40, '/room/room-3.png'),
39-
('room-4', 'Mystic Forest', 'room', 50, '/room/room-4.png')
40-
on conflict (id) do update
29+
-- Rows already on new ids or unknown values: coerce to a valid default.
30+
update
31+
public.avatar_state
4132
set
42-
name = excluded.name,
43-
type = excluded.type,
44-
price = excluded.price,
45-
image_path = excluded.image_path;
33+
room_background = 'room-1'
34+
where
35+
room_background is null
36+
or room_background not in ('room-1', 'room-2', 'room-3', 'room-4');
4637

47-
alter table public.avatar_state
48-
drop constraint if exists avatar_state_room_background_check;
38+
alter table
39+
public.avatar_state
40+
alter column
41+
room_background
42+
set
43+
default 'room-1';
4944

50-
alter table public.avatar_state
51-
add constraint avatar_state_room_background_check
52-
check (
45+
alter table
46+
public.avatar_state
47+
add
48+
constraint avatar_state_room_background_check check (
5349
room_background in (
5450
'room-1',
5551
'room-2',
5652
'room-3',
5753
'room-4'
5854
)
5955
);
56+
57+
update
58+
public.user_items
59+
set
60+
item_id = case
61+
item_id
62+
when 'room-night' then 'room-3'
63+
when 'room-forest' then 'room-4'
64+
else item_id
65+
end
66+
where
67+
item_id in ('room-night', 'room-forest');
68+
69+
delete from
70+
public.shop_items
71+
where
72+
id in ('room-night', 'room-forest');
73+
74+
insert into
75+
public.shop_items (id, name, type, price, image_path)
76+
values
77+
(
78+
'room-3',
79+
'Starlit Night',
80+
'room',
81+
40,
82+
'/room/room-3.png'
83+
),
84+
(
85+
'room-4',
86+
'Mystic Forest',
87+
'room',
88+
50,
89+
'/room/room-4.png'
90+
) on conflict (id) do
91+
update
92+
set
93+
name = excluded.name,
94+
type = excluded.type,
95+
price = excluded.price,
96+
image_path = excluded.image_path;

0 commit comments

Comments
 (0)