Closed dchecheb closed 2 years ago
kosalaam=> create extension if not exists "uuid-ossp";
kosalaam=> alter table accommodation add uuid uuid default uuid_generate_v4 ();
ALTER TABLE
kosalaam=> alter table accommodation alter column uuid set not null;
ALTER TABLE
kosalaam=> create unique index accommodation_uuid_uindex
on accommodation (uuid);
-- Firstly, remove PRIMARY KEY attribute of former PRIMARY KEY
ALTER TABLE accommodation DROP CONSTRAINT pk_accommodation CASCADE;
ALTER TABLE accommodation DROP COLUMN id;
-- Then change column name of your PRIMARY KEY and PRIMARY KEY candidates properly.
ALTER TABLE accommodation RENAME COLUMN uuid TO id;
-- Lastly set your new PRIMARY KEY
ALTER TABLE accommodation ADD PRIMARY KEY (id);
-- Review & Like
DELETE FROM accommodation_like;
DELETE FROM accommodation_review;
ALTER TABLE accommodation_like DROP COLUMN accommodation_id;
ALTER TABLE accommodation_review DROP COLUMN accommodation_id;
ALTER TABLE accommodation_like ADD COLUMN accommodation_id uuid;
ALTER TABLE accommodation_review ADD COLUMN accommodation_id uuid;
ALTER TABLE accommodation_like
ADD CONSTRAINT fk_accommodation_like_id_accommodation_id
FOREIGN KEY (accommodation_id)
REFERENCES accommodation(id)
ON DELETE CASCADE;
ALTER TABLE accommodation_review
ADD CONSTRAINT fk_accommodation_review_id_accommodation_id
FOREIGN KEY (accommodation_id)
REFERENCES accommodation(id)
ON DELETE CASCADE;
식당, 숙박, 기도실 통합 검색