-- Script to rename UUID columns to original names and add primary key constraints
-- This is the fourth and final step of the migration process

-- Rename primary key columns in key tables
ALTER TABLE users RENAME COLUMN user_uuid TO user_id;
ALTER TABLE companies RENAME COLUMN company_uuid TO company_id;
ALTER TABLE beach_places RENAME COLUMN beach_place_uuid TO beach_place_id;
ALTER TABLE restaurants RENAME COLUMN restaurant_uuid TO restaurant_id;
ALTER TABLE restaurant_items RENAME COLUMN item_uuid TO item_id;
ALTER TABLE markets RENAME COLUMN market_uuid TO market_id;
ALTER TABLE market_items RENAME COLUMN item_uuid TO item_id;
ALTER TABLE adventures RENAME COLUMN adventure_uuid TO adventure_id;
ALTER TABLE bookings RENAME COLUMN booking_uuid TO booking_id;
ALTER TABLE reviews RENAME COLUMN review_uuid TO review_id;

-- Add primary key constraints back to the renamed columns
ALTER TABLE users ADD CONSTRAINT users_pkey PRIMARY KEY (user_id);
ALTER TABLE companies ADD CONSTRAINT companies_pkey PRIMARY KEY (company_id);
ALTER TABLE beach_places ADD CONSTRAINT beach_places_pkey PRIMARY KEY (beach_place_id);
ALTER TABLE restaurants ADD CONSTRAINT restaurants_pkey PRIMARY KEY (restaurant_id);
ALTER TABLE restaurant_items ADD CONSTRAINT restaurant_items_pkey PRIMARY KEY (item_id);
ALTER TABLE markets ADD CONSTRAINT markets_pkey PRIMARY KEY (market_id);
ALTER TABLE market_items ADD CONSTRAINT market_items_pkey PRIMARY KEY (item_id);
ALTER TABLE adventures ADD CONSTRAINT adventures_pkey PRIMARY KEY (adventure_id);
ALTER TABLE bookings ADD CONSTRAINT bookings_pkey PRIMARY KEY (booking_id);
ALTER TABLE reviews ADD CONSTRAINT reviews_pkey PRIMARY KEY (review_id);