Implemented better fix for migration
This commit is contained in:
@@ -1,51 +1,39 @@
|
|||||||
-- Room backgrounds: PNG assets in /public/room with ids room-1 .. room-4.
|
-- Room backgrounds: PNG assets in /public/room with ids room-1 .. room-4.
|
||||||
|
|
||||||
-- Drop legacy check before rewriting values (old ids: room-day, room-dusk, etc.).
|
-- Drop legacy check before rewriting values (old ids: room-day, room-dusk, etc.).
|
||||||
alter table
|
alter table public.avatar_state
|
||||||
public.avatar_state drop constraint if exists avatar_state_room_background_check;
|
drop constraint if exists avatar_state_room_background_check;
|
||||||
|
|
||||||
update
|
update public.avatar_state
|
||||||
public.avatar_state
|
set room_background = case room_background
|
||||||
set
|
when 'room-day' then 'room-1'
|
||||||
room_background = case
|
when 'room-dusk' then 'room-2'
|
||||||
room_background
|
when 'room-night' then 'room-3'
|
||||||
when 'room-day' then 'room-1'
|
when 'room-forest' then 'room-4'
|
||||||
when 'room-dusk' then 'room-2'
|
when 'room-space' then 'room-1'
|
||||||
when 'room-night' then 'room-3'
|
when 'room-neon' then 'room-1'
|
||||||
when 'room-forest' then 'room-4'
|
else room_background
|
||||||
when 'room-space' then 'room-1'
|
end
|
||||||
when 'room-neon' then 'room-1'
|
where room_background in (
|
||||||
else room_background
|
'room-day',
|
||||||
end
|
'room-dusk',
|
||||||
where
|
'room-night',
|
||||||
room_background in (
|
'room-forest',
|
||||||
'room-day',
|
'room-space',
|
||||||
'room-dusk',
|
'room-neon'
|
||||||
'room-night',
|
);
|
||||||
'room-forest',
|
|
||||||
'room-space',
|
|
||||||
'room-neon'
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Rows already on new ids or unknown values: coerce to a valid default.
|
update public.avatar_state
|
||||||
update
|
set room_background = 'room-1'
|
||||||
public.avatar_state
|
where room_background is null
|
||||||
set
|
|
||||||
room_background = 'room-1'
|
|
||||||
where
|
|
||||||
room_background is null
|
|
||||||
or room_background not in ('room-1', 'room-2', 'room-3', 'room-4');
|
or room_background not in ('room-1', 'room-2', 'room-3', 'room-4');
|
||||||
|
|
||||||
alter table
|
alter table public.avatar_state
|
||||||
public.avatar_state
|
alter column room_background set default 'room-1';
|
||||||
alter column
|
|
||||||
room_background
|
|
||||||
set
|
|
||||||
default 'room-1';
|
|
||||||
|
|
||||||
alter table
|
alter table public.avatar_state
|
||||||
public.avatar_state
|
add constraint avatar_state_room_background_check
|
||||||
add
|
check (
|
||||||
constraint avatar_state_room_background_check check (
|
|
||||||
room_background in (
|
room_background in (
|
||||||
'room-1',
|
'room-1',
|
||||||
'room-2',
|
'room-2',
|
||||||
@@ -54,43 +42,25 @@ add
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
update
|
-- New shop rows must exist before user_items FK references are updated.
|
||||||
public.user_items
|
insert into public.shop_items (id, name, type, price, image_path)
|
||||||
set
|
|
||||||
item_id = case
|
|
||||||
item_id
|
|
||||||
when 'room-night' then 'room-3'
|
|
||||||
when 'room-forest' then 'room-4'
|
|
||||||
else item_id
|
|
||||||
end
|
|
||||||
where
|
|
||||||
item_id in ('room-night', 'room-forest');
|
|
||||||
|
|
||||||
delete from
|
|
||||||
public.shop_items
|
|
||||||
where
|
|
||||||
id in ('room-night', 'room-forest');
|
|
||||||
|
|
||||||
insert into
|
|
||||||
public.shop_items (id, name, type, price, image_path)
|
|
||||||
values
|
values
|
||||||
(
|
('room-3', 'Starlit Night', 'room', 40, '/room/room-3.png'),
|
||||||
'room-3',
|
('room-4', 'Mystic Forest', 'room', 50, '/room/room-4.png')
|
||||||
'Starlit Night',
|
on conflict (id) do update
|
||||||
'room',
|
|
||||||
40,
|
|
||||||
'/room/room-3.png'
|
|
||||||
),
|
|
||||||
(
|
|
||||||
'room-4',
|
|
||||||
'Mystic Forest',
|
|
||||||
'room',
|
|
||||||
50,
|
|
||||||
'/room/room-4.png'
|
|
||||||
) on conflict (id) do
|
|
||||||
update
|
|
||||||
set
|
set
|
||||||
name = excluded.name,
|
name = excluded.name,
|
||||||
type = excluded.type,
|
type = excluded.type,
|
||||||
price = excluded.price,
|
price = excluded.price,
|
||||||
image_path = excluded.image_path;
|
image_path = excluded.image_path;
|
||||||
|
|
||||||
|
update public.user_items
|
||||||
|
set item_id = case item_id
|
||||||
|
when 'room-night' then 'room-3'
|
||||||
|
when 'room-forest' then 'room-4'
|
||||||
|
else item_id
|
||||||
|
end
|
||||||
|
where item_id in ('room-night', 'room-forest');
|
||||||
|
|
||||||
|
delete from public.shop_items
|
||||||
|
where id in ('room-night', 'room-forest');
|
||||||
|
|||||||
Reference in New Issue
Block a user