-- Migration script to change all primary keys from numeric to UUID
-- This script will:
-- 1. Add new UUID columns to all tables
-- 2. Populate the UUID columns with generated UUIDs
-- 3. Update foreign key references to use UUIDs
-- 4. Drop old numeric columns
-- 5. Rename new UUID columns to original names

-- NOTE: This migration will require downtime and data loss for existing data
-- Please backup your database before running this script

-- Enable UUID extension
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

-- 1. Add new UUID columns to all tables with primary keys

-- Countries table
ALTER TABLE countries ADD COLUMN country_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE countries ADD CONSTRAINT countries_country_uuid_key UNIQUE (country_uuid);

-- Currencies table
ALTER TABLE currencies ADD COLUMN currency_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE currencies ADD CONSTRAINT currencies_currency_uuid_key UNIQUE (currency_uuid);

-- Languages table
ALTER TABLE languages ADD COLUMN language_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE languages ADD CONSTRAINT languages_language_uuid_key UNIQUE (language_uuid);

-- User roles table
ALTER TABLE user_roles ADD COLUMN role_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE user_roles ADD CONSTRAINT user_roles_role_uuid_key UNIQUE (role_uuid);

-- Users table
ALTER TABLE users ADD COLUMN user_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE users ADD CONSTRAINT users_user_uuid_key UNIQUE (user_uuid);

-- Companies table
ALTER TABLE companies ADD COLUMN company_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE companies ADD CONSTRAINT companies_company_uuid_key UNIQUE (company_uuid);

-- User-Company relationships
ALTER TABLE user_companies ADD COLUMN user_company_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE user_companies ADD CONSTRAINT user_companies_user_company_uuid_key UNIQUE (user_company_uuid);

-- Beach terrain types table
ALTER TABLE beach_terrain_types ADD COLUMN terrain_type_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE beach_terrain_types ADD CONSTRAINT beach_terrain_types_terrain_type_uuid_key UNIQUE (terrain_type_uuid);

-- Beach bed types table
ALTER TABLE beach_bed_types ADD COLUMN bed_type_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE beach_bed_types ADD CONSTRAINT beach_bed_types_bed_type_uuid_key UNIQUE (bed_type_uuid);

-- Beach places table
ALTER TABLE beach_places ADD COLUMN beach_place_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE beach_places ADD CONSTRAINT beach_places_beach_place_uuid_key UNIQUE (beach_place_uuid);

-- Beach places photos table
ALTER TABLE beach_places_photos ADD COLUMN photo_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE beach_places_photos ADD CONSTRAINT beach_places_photos_photo_uuid_key UNIQUE (photo_uuid);

-- Beach places schedules table
ALTER TABLE beach_places_schedules ADD COLUMN schedule_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE beach_places_schedules ADD CONSTRAINT beach_places_schedules_schedule_uuid_key UNIQUE (schedule_uuid);

-- Beach place terrains table (already has UUID, but we'll keep it for consistency)
-- No changes needed for beach_place_terrains

-- Restaurants table
ALTER TABLE restaurants ADD COLUMN restaurant_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE restaurants ADD CONSTRAINT restaurants_restaurant_uuid_key UNIQUE (restaurant_uuid);

-- Restaurant categories table
ALTER TABLE restaurant_categories ADD COLUMN category_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE restaurant_categories ADD CONSTRAINT restaurant_categories_category_uuid_key UNIQUE (category_uuid);

-- Restaurant items table
ALTER TABLE restaurant_items ADD COLUMN item_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE restaurant_items ADD CONSTRAINT restaurant_items_item_uuid_key UNIQUE (item_uuid);

-- Markets table
ALTER TABLE markets ADD COLUMN market_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE markets ADD CONSTRAINT markets_market_uuid_key UNIQUE (market_uuid);

-- Market categories table
ALTER TABLE market_categories ADD COLUMN category_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE market_categories ADD CONSTRAINT market_categories_category_uuid_key UNIQUE (category_uuid);

-- Market items table
ALTER TABLE market_items ADD COLUMN item_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE market_items ADD CONSTRAINT market_items_item_uuid_key UNIQUE (item_uuid);

-- Adventures table
ALTER TABLE adventures ADD COLUMN adventure_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE adventures ADD CONSTRAINT adventures_adventure_uuid_key UNIQUE (adventure_uuid);

-- Adventure schedules table
ALTER TABLE adventure_schedules ADD COLUMN schedule_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE adventure_schedules ADD CONSTRAINT adventure_schedules_schedule_uuid_key UNIQUE (schedule_uuid);

-- Bookings table
ALTER TABLE bookings ADD COLUMN booking_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE bookings ADD CONSTRAINT bookings_booking_uuid_key UNIQUE (booking_uuid);

-- Reviews table
ALTER TABLE reviews ADD COLUMN review_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE reviews ADD CONSTRAINT reviews_review_uuid_key UNIQUE (review_uuid);

-- User wallet table
ALTER TABLE user_wallets ADD COLUMN wallet_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE user_wallets ADD CONSTRAINT user_wallets_wallet_uuid_key UNIQUE (wallet_uuid);

-- Wallet transactions table
ALTER TABLE wallet_transactions ADD COLUMN transaction_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE wallet_transactions ADD CONSTRAINT wallet_transactions_transaction_uuid_key UNIQUE (transaction_uuid);

-- Email templates table
ALTER TABLE email_templates ADD COLUMN template_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE email_templates ADD CONSTRAINT email_templates_template_uuid_key UNIQUE (template_uuid);

-- Email logs table
ALTER TABLE email_logs ADD COLUMN log_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE email_logs ADD CONSTRAINT email_logs_log_uuid_key UNIQUE (log_uuid);

-- System settings table
ALTER TABLE system_settings ADD COLUMN setting_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE system_settings ADD CONSTRAINT system_settings_setting_uuid_key UNIQUE (setting_uuid);

-- Email verification tokens table
ALTER TABLE email_verification_tokens ADD COLUMN token_uuid UUID DEFAULT uuid_generate_v4();
ALTER TABLE email_verification_tokens ADD CONSTRAINT email_verification_tokens_token_uuid_key UNIQUE (token_uuid);

-- 2. Update foreign key references to use UUIDs instead of numeric IDs

-- Update foreign keys in users table
ALTER TABLE users ADD COLUMN role_uuid_fk UUID REFERENCES user_roles(role_uuid);
ALTER TABLE users ADD COLUMN preferred_language_uuid UUID REFERENCES languages(language_uuid);
ALTER TABLE users ADD COLUMN preferred_currency_uuid UUID REFERENCES currencies(currency_uuid);

-- Update foreign keys in email_verification_tokens table
ALTER TABLE email_verification_tokens ADD COLUMN user_uuid_fk UUID REFERENCES users(user_uuid);

-- Update foreign keys in companies table
ALTER TABLE companies ADD COLUMN country_uuid_fk UUID REFERENCES countries(country_uuid);

-- Update foreign keys in user_companies table
ALTER TABLE user_companies ADD COLUMN user_uuid_fk UUID REFERENCES users(user_uuid);
ALTER TABLE user_companies ADD COLUMN company_uuid_fk UUID REFERENCES companies(company_uuid);

-- Update foreign keys in beach_places table
ALTER TABLE beach_places ADD COLUMN company_uuid_fk UUID REFERENCES companies(company_uuid);
ALTER TABLE beach_places ADD COLUMN terrain_type_uuid_fk UUID REFERENCES beach_terrain_types(terrain_type_uuid);
ALTER TABLE beach_places ADD COLUMN country_uuid_fk UUID REFERENCES countries(country_uuid);

-- Update foreign keys in beach_places_photos table
ALTER TABLE beach_places_photos ADD COLUMN beach_place_uuid_fk UUID REFERENCES beach_places(beach_place_uuid);

-- Update foreign keys in beach_places_schedules table
ALTER TABLE beach_places_schedules ADD COLUMN beach_place_uuid_fk UUID REFERENCES beach_places(beach_place_uuid);
ALTER TABLE beach_places_schedules ADD COLUMN currency_uuid_fk UUID REFERENCES currencies(currency_uuid);

-- Update foreign keys in beach_place_terrains table
ALTER TABLE beach_place_terrains ADD COLUMN beach_place_uuid_fk UUID REFERENCES beach_places(beach_place_uuid);

-- Update foreign keys in restaurants table
ALTER TABLE restaurants ADD COLUMN company_uuid_fk UUID REFERENCES companies(company_uuid);
ALTER TABLE restaurants ADD COLUMN beach_place_uuid_fk UUID REFERENCES beach_places(beach_place_uuid);

-- Update foreign keys in restaurant_categories table
ALTER TABLE restaurant_categories ADD COLUMN restaurant_uuid_fk UUID REFERENCES restaurants(restaurant_uuid);

-- Update foreign keys in restaurant_items table
ALTER TABLE restaurant_items ADD COLUMN restaurant_uuid_fk UUID REFERENCES restaurants(restaurant_uuid);
ALTER TABLE restaurant_items ADD COLUMN category_uuid_fk UUID REFERENCES restaurant_categories(category_uuid);
ALTER TABLE restaurant_items ADD COLUMN currency_uuid_fk UUID REFERENCES currencies(currency_uuid);

-- Update foreign keys in markets table
ALTER TABLE markets ADD COLUMN company_uuid_fk UUID REFERENCES companies(company_uuid);
ALTER TABLE markets ADD COLUMN beach_place_uuid_fk UUID REFERENCES beach_places(beach_place_uuid);

-- Update foreign keys in market_categories table
ALTER TABLE market_categories ADD COLUMN market_uuid_fk UUID REFERENCES markets(market_uuid);

-- Update foreign keys in market_items table
ALTER TABLE market_items ADD COLUMN market_uuid_fk UUID REFERENCES markets(market_uuid);
ALTER TABLE market_items ADD COLUMN category_uuid_fk UUID REFERENCES market_categories(category_uuid);
ALTER TABLE market_items ADD COLUMN currency_uuid_fk UUID REFERENCES currencies(currency_uuid);

-- Update foreign keys in adventures table
ALTER TABLE adventures ADD COLUMN company_uuid_fk UUID REFERENCES companies(company_uuid);
ALTER TABLE adventures ADD COLUMN beach_place_uuid_fk UUID REFERENCES beach_places(beach_place_uuid);
ALTER TABLE adventures ADD COLUMN currency_uuid_fk UUID REFERENCES currencies(currency_uuid);

-- Update foreign keys in adventure_schedules table
ALTER TABLE adventure_schedules ADD COLUMN adventure_uuid_fk UUID REFERENCES adventures(adventure_uuid);

-- Update foreign keys in bookings table
ALTER TABLE bookings ADD COLUMN user_uuid_fk UUID REFERENCES users(user_uuid);
ALTER TABLE bookings ADD COLUMN beach_place_uuid_fk UUID REFERENCES beach_places(beach_place_uuid);
ALTER TABLE bookings ADD COLUMN currency_uuid_fk UUID REFERENCES currencies(currency_uuid);

-- Update foreign keys in reviews table
ALTER TABLE reviews ADD COLUMN user_uuid_fk UUID REFERENCES users(user_uuid);
ALTER TABLE reviews ADD COLUMN beach_place_uuid_fk UUID REFERENCES beach_places(beach_place_uuid);
ALTER TABLE reviews ADD COLUMN booking_uuid_fk UUID REFERENCES bookings(booking_uuid);

-- Update foreign keys in user_wallets table
ALTER TABLE user_wallets ADD COLUMN user_uuid_fk UUID REFERENCES users(user_uuid);
ALTER TABLE user_wallets ADD COLUMN currency_uuid_fk UUID REFERENCES currencies(currency_uuid);

-- Update foreign keys in wallet_transactions table
ALTER TABLE wallet_transactions ADD COLUMN wallet_uuid_fk UUID REFERENCES user_wallets(wallet_uuid);
ALTER TABLE wallet_transactions ADD COLUMN currency_uuid_fk UUID REFERENCES currencies(currency_uuid);

-- Update foreign keys in email_logs table
ALTER TABLE email_logs ADD COLUMN template_uuid_fk UUID REFERENCES email_templates(template_uuid);

-- 3. Populate the new UUID foreign key columns with matching UUIDs

-- Populate foreign keys in users table
UPDATE users u SET role_uuid_fk = (SELECT role_uuid FROM user_roles WHERE role_id = u.role_id);
UPDATE users u SET preferred_language_uuid = (SELECT language_uuid FROM languages WHERE language_id = u.preferred_language_id);
UPDATE users u SET preferred_currency_uuid = (SELECT currency_uuid FROM currencies WHERE currency_id = u.preferred_currency_id);

-- Populate foreign keys in email_verification_tokens table
UPDATE email_verification_tokens e SET user_uuid_fk = (SELECT user_uuid FROM users WHERE user_id = e.user_id);

-- Populate foreign keys in companies table
UPDATE companies c SET country_uuid_fk = (SELECT country_uuid FROM countries WHERE country_id = c.country_id);

-- Populate foreign keys in user_companies table
UPDATE user_companies uc SET user_uuid_fk = (SELECT user_uuid FROM users WHERE user_id = uc.user_id);
UPDATE user_companies uc SET company_uuid_fk = (SELECT company_uuid FROM companies WHERE company_id = uc.company_id);

-- Populate foreign keys in beach_places table
UPDATE beach_places bp SET company_uuid_fk = (SELECT company_uuid FROM companies WHERE company_id = bp.company_id);
UPDATE beach_places bp SET terrain_type_uuid_fk = (SELECT terrain_type_uuid FROM beach_terrain_types WHERE terrain_type_id = bp.terrain_type_id);
UPDATE beach_places bp SET country_uuid_fk = (SELECT country_uuid FROM countries WHERE country_id = bp.country_id);

-- Populate foreign keys in beach_places_photos table
UPDATE beach_places_photos bpp SET beach_place_uuid_fk = (SELECT beach_place_uuid FROM beach_places WHERE beach_place_id = bpp.beach_place_id);

-- Populate foreign keys in beach_places_schedules table
UPDATE beach_places_schedules bps SET beach_place_uuid_fk = (SELECT beach_place_uuid FROM beach_places WHERE beach_place_id = bps.beach_place_id);
UPDATE beach_places_schedules bps SET currency_uuid_fk = (SELECT currency_uuid FROM currencies WHERE currency_id = bps.currency_id);

-- Populate foreign keys in beach_place_terrains table
UPDATE beach_place_terrains bpt SET beach_place_uuid_fk = (SELECT beach_place_uuid FROM beach_places WHERE beach_place_id = bpt.beach_place_id);

-- Populate foreign keys in restaurants table
UPDATE restaurants r SET company_uuid_fk = (SELECT company_uuid FROM companies WHERE company_id = r.company_id);
UPDATE restaurants r SET beach_place_uuid_fk = (SELECT beach_place_uuid FROM beach_places WHERE beach_place_id = r.beach_place_id);

-- Populate foreign keys in restaurant_categories table
UPDATE restaurant_categories rc SET restaurant_uuid_fk = (SELECT restaurant_uuid FROM restaurants WHERE restaurant_id = rc.restaurant_id);

-- Populate foreign keys in restaurant_items table
UPDATE restaurant_items ri SET restaurant_uuid_fk = (SELECT restaurant_uuid FROM restaurants WHERE restaurant_id = ri.restaurant_id);
UPDATE restaurant_items ri SET category_uuid_fk = (SELECT category_uuid FROM restaurant_categories WHERE category_id = ri.category_id);
UPDATE restaurant_items ri SET currency_uuid_fk = (SELECT currency_uuid FROM currencies WHERE currency_id = ri.currency_id);

-- Populate foreign keys in markets table
UPDATE markets m SET company_uuid_fk = (SELECT company_uuid FROM companies WHERE company_id = m.company_id);
UPDATE markets m SET beach_place_uuid_fk = (SELECT beach_place_uuid FROM beach_places WHERE beach_place_id = m.beach_place_id);

-- Populate foreign keys in market_categories table
UPDATE market_categories mc SET market_uuid_fk = (SELECT market_uuid FROM markets WHERE market_id = mc.market_id);

-- Populate foreign keys in market_items table
UPDATE market_items mi SET market_uuid_fk = (SELECT market_uuid FROM markets WHERE market_id = mi.market_id);
UPDATE market_items mi SET category_uuid_fk = (SELECT category_uuid FROM market_categories WHERE category_id = mi.category_id);
UPDATE market_items mi SET currency_uuid_fk = (SELECT currency_uuid FROM currencies WHERE currency_id = mi.currency_id);

-- Populate foreign keys in adventures table
UPDATE adventures a SET company_uuid_fk = (SELECT company_uuid FROM companies WHERE company_id = a.company_id);
UPDATE adventures a SET beach_place_uuid_fk = (SELECT beach_place_uuid FROM beach_places WHERE beach_place_id = a.beach_place_id);
UPDATE adventures a SET currency_uuid_fk = (SELECT currency_uuid FROM currencies WHERE currency_id = a.currency_id);

-- Populate foreign keys in adventure_schedules table
UPDATE adventure_schedules a_s SET adventure_uuid_fk = (SELECT adventure_uuid FROM adventures WHERE adventure_id = a_s.adventure_id);

-- Populate foreign keys in bookings table
UPDATE bookings b SET user_uuid_fk = (SELECT user_uuid FROM users WHERE user_id = b.user_id);
UPDATE bookings b SET beach_place_uuid_fk = (SELECT beach_place_uuid FROM beach_places WHERE beach_place_id = b.beach_place_id);
UPDATE bookings b SET currency_uuid_fk = (SELECT currency_uuid FROM currencies WHERE currency_id = b.currency_id);

-- Populate foreign keys in reviews table
UPDATE reviews r SET user_uuid_fk = (SELECT user_uuid FROM users WHERE user_id = r.user_id);
UPDATE reviews r SET beach_place_uuid_fk = (SELECT beach_place_uuid FROM beach_places WHERE beach_place_id = r.beach_place_id);
UPDATE reviews r SET booking_uuid_fk = (SELECT booking_uuid FROM bookings WHERE booking_id = r.booking_id);

-- Populate foreign keys in user_wallets table
UPDATE user_wallets uw SET user_uuid_fk = (SELECT user_uuid FROM users WHERE user_id = uw.user_id);
UPDATE user_wallets uw SET currency_uuid_fk = (SELECT currency_uuid FROM currencies WHERE currency_id = uw.currency_id);

-- Populate foreign keys in wallet_transactions table
UPDATE wallet_transactions wt SET wallet_uuid_fk = (SELECT wallet_uuid FROM user_wallets WHERE wallet_id = wt.wallet_id);
UPDATE wallet_transactions wt SET currency_uuid_fk = (SELECT currency_uuid FROM currencies WHERE currency_id = wt.currency_id);

-- Populate foreign keys in email_logs table
UPDATE email_logs el SET template_uuid_fk = (SELECT template_uuid FROM email_templates WHERE template_id = el.template_id);

-- 4. Drop old numeric primary key columns and foreign key columns

-- Drop primary keys and foreign keys in countries table
ALTER TABLE countries DROP CONSTRAINT countries_pkey;
ALTER TABLE countries DROP COLUMN country_id;

-- Drop primary keys and foreign keys in currencies table
ALTER TABLE currencies DROP CONSTRAINT currencies_pkey;
ALTER TABLE currencies DROP COLUMN currency_id;

-- Drop primary keys and foreign keys in languages table
ALTER TABLE languages DROP CONSTRAINT languages_pkey;
ALTER TABLE languages DROP COLUMN language_id;

-- Drop primary keys and foreign keys in user_roles table
ALTER TABLE user_roles DROP CONSTRAINT user_roles_pkey;
ALTER TABLE user_roles DROP COLUMN role_id;

-- Drop primary keys and foreign keys in users table
ALTER TABLE users DROP CONSTRAINT users_pkey;
ALTER TABLE users DROP COLUMN user_id;
ALTER TABLE users DROP COLUMN role_id;
ALTER TABLE users DROP COLUMN preferred_language_id;
ALTER TABLE users DROP COLUMN preferred_currency_id;

-- Drop primary keys and foreign keys in companies table
ALTER TABLE companies DROP CONSTRAINT companies_pkey;
ALTER TABLE companies DROP COLUMN company_id;
ALTER TABLE companies DROP COLUMN country_id;

-- Drop primary keys and foreign keys in user_companies table
ALTER TABLE user_companies DROP CONSTRAINT user_companies_pkey;
ALTER TABLE user_companies DROP COLUMN user_company_id;
ALTER TABLE user_companies DROP COLUMN user_id;
ALTER TABLE user_companies DROP COLUMN company_id;

-- Drop primary keys and foreign keys in beach_terrain_types table
ALTER TABLE beach_terrain_types DROP CONSTRAINT beach_terrain_types_pkey;
ALTER TABLE beach_terrain_types DROP COLUMN terrain_type_id;

-- Drop primary keys and foreign keys in beach_bed_types table
ALTER TABLE beach_bed_types DROP CONSTRAINT beach_bed_types_pkey;
ALTER TABLE beach_bed_types DROP COLUMN bed_type_id;

-- Drop primary keys and foreign keys in beach_places table
ALTER TABLE beach_places DROP CONSTRAINT beach_places_pkey;
ALTER TABLE beach_places DROP COLUMN beach_place_id;
ALTER TABLE beach_places DROP COLUMN company_id;
ALTER TABLE beach_places DROP COLUMN terrain_type_id;
ALTER TABLE beach_places DROP COLUMN country_id;

-- Drop primary keys and foreign keys in beach_places_photos table
ALTER TABLE beach_places_photos DROP CONSTRAINT beach_places_photos_pkey;
ALTER TABLE beach_places_photos DROP COLUMN photo_id;
ALTER TABLE beach_places_photos DROP COLUMN beach_place_id;

-- Drop primary keys and foreign keys in beach_places_schedules table
ALTER TABLE beach_places_schedules DROP CONSTRAINT beach_places_schedules_pkey;
ALTER TABLE beach_places_schedules DROP COLUMN schedule_id;
ALTER TABLE beach_places_schedules DROP COLUMN beach_place_id;
ALTER TABLE beach_places_schedules DROP COLUMN currency_id;

-- Drop foreign keys in beach_place_terrains table
ALTER TABLE beach_place_terrains DROP COLUMN beach_place_id;

-- Drop primary keys and foreign keys in restaurants table
ALTER TABLE restaurants DROP CONSTRAINT restaurants_pkey;
ALTER TABLE restaurants DROP COLUMN restaurant_id;
ALTER TABLE restaurants DROP COLUMN company_id;
ALTER TABLE restaurants DROP COLUMN beach_place_id;

-- Drop primary keys and foreign keys in restaurant_categories table
ALTER TABLE restaurant_categories DROP CONSTRAINT restaurant_categories_pkey;
ALTER TABLE restaurant_categories DROP COLUMN category_id;
ALTER TABLE restaurant_categories DROP COLUMN restaurant_id;

-- Drop primary keys and foreign keys in restaurant_items table
ALTER TABLE restaurant_items DROP CONSTRAINT restaurant_items_pkey;
ALTER TABLE restaurant_items DROP COLUMN item_id;
ALTER TABLE restaurant_items DROP COLUMN restaurant_id;
ALTER TABLE restaurant_items DROP COLUMN category_id;
ALTER TABLE restaurant_items DROP COLUMN currency_id;

-- Drop primary keys and foreign keys in markets table
ALTER TABLE markets DROP CONSTRAINT markets_pkey;
ALTER TABLE markets DROP COLUMN market_id;
ALTER TABLE markets DROP COLUMN company_id;
ALTER TABLE markets DROP COLUMN beach_place_id;

-- Drop primary keys and foreign keys in market_categories table
ALTER TABLE market_categories DROP CONSTRAINT market_categories_pkey;
ALTER TABLE market_categories DROP COLUMN category_id;
ALTER TABLE market_categories DROP COLUMN market_id;

-- Drop primary keys and foreign keys in market_items table
ALTER TABLE market_items DROP CONSTRAINT market_items_pkey;
ALTER TABLE market_items DROP COLUMN item_id;
ALTER TABLE market_items DROP COLUMN market_id;
ALTER TABLE market_items DROP COLUMN category_id;
ALTER TABLE market_items DROP COLUMN currency_id;

-- Drop primary keys and foreign keys in adventures table
ALTER TABLE adventures DROP CONSTRAINT adventures_pkey;
ALTER TABLE adventures DROP COLUMN adventure_id;
ALTER TABLE adventures DROP COLUMN company_id;
ALTER TABLE adventures DROP COLUMN beach_place_id;
ALTER TABLE adventures DROP COLUMN currency_id;

-- Drop primary keys and foreign keys in adventure_schedules table
ALTER TABLE adventure_schedules DROP CONSTRAINT adventure_schedules_pkey;
ALTER TABLE adventure_schedules DROP COLUMN schedule_id;
ALTER TABLE adventure_schedules DROP COLUMN adventure_id;

-- Drop primary keys and foreign keys in bookings table
ALTER TABLE bookings DROP CONSTRAINT bookings_pkey;
ALTER TABLE bookings DROP COLUMN booking_id;
ALTER TABLE bookings DROP COLUMN user_id;
ALTER TABLE bookings DROP COLUMN beach_place_id;
ALTER TABLE bookings DROP COLUMN currency_id;

-- Drop primary keys and foreign keys in reviews table
ALTER TABLE reviews DROP CONSTRAINT reviews_pkey;
ALTER TABLE reviews DROP COLUMN review_id;
ALTER TABLE reviews DROP COLUMN user_id;
ALTER TABLE reviews DROP COLUMN beach_place_id;
ALTER TABLE reviews DROP COLUMN booking_id;

-- Drop primary keys and foreign keys in user_wallets table
ALTER TABLE user_wallets DROP CONSTRAINT user_wallets_pkey;
ALTER TABLE user_wallets DROP COLUMN wallet_id;
ALTER TABLE user_wallets DROP COLUMN user_id;
ALTER TABLE user_wallets DROP COLUMN currency_id;

-- Drop primary keys and foreign keys in wallet_transactions table
ALTER TABLE wallet_transactions DROP CONSTRAINT wallet_transactions_pkey;
ALTER TABLE wallet_transactions DROP COLUMN transaction_id;
ALTER TABLE wallet_transactions DROP COLUMN wallet_id;
ALTER TABLE wallet_transactions DROP COLUMN currency_id;

-- Drop primary keys and foreign keys in email_templates table
ALTER TABLE email_templates DROP CONSTRAINT email_templates_pkey;
ALTER TABLE email_templates DROP COLUMN template_id;

-- Drop primary keys and foreign keys in email_logs table
ALTER TABLE email_logs DROP CONSTRAINT email_logs_pkey;
ALTER TABLE email_logs DROP COLUMN log_id;
ALTER TABLE email_logs DROP COLUMN template_id;

-- Drop primary keys and foreign keys in system_settings table
ALTER TABLE system_settings DROP CONSTRAINT system_settings_pkey;
ALTER TABLE system_settings DROP COLUMN setting_id;

-- Drop primary keys and foreign keys in email_verification_tokens table
ALTER TABLE email_verification_tokens DROP CONSTRAINT email_verification_tokens_pkey;
ALTER TABLE email_verification_tokens DROP COLUMN token_id;
ALTER TABLE email_verification_tokens DROP COLUMN user_id;

-- 5. Rename new UUID columns to original names and set as primary keys

-- Rename and set primary keys in countries table
ALTER TABLE countries RENAME COLUMN country_uuid TO country_id;
ALTER TABLE countries ADD PRIMARY KEY (country_id);

-- Rename and set primary keys in currencies table
ALTER TABLE currencies RENAME COLUMN currency_uuid TO currency_id;
ALTER TABLE currencies ADD PRIMARY KEY (currency_id);

-- Rename and set primary keys in languages table
ALTER TABLE languages RENAME COLUMN language_uuid TO language_id;
ALTER TABLE languages ADD PRIMARY KEY (language_id);

-- Rename and set primary keys in user_roles table
ALTER TABLE user_roles RENAME COLUMN role_uuid TO role_id;
ALTER TABLE user_roles ADD PRIMARY KEY (role_id);

-- Rename and set primary keys in users table
ALTER TABLE users RENAME COLUMN user_uuid TO user_id;
ALTER TABLE users ADD PRIMARY KEY (user_id);
ALTER TABLE users RENAME COLUMN role_uuid_fk TO role_id;
ALTER TABLE users RENAME COLUMN preferred_language_uuid TO preferred_language_id;
ALTER TABLE users RENAME COLUMN preferred_currency_uuid TO preferred_currency_id;

-- Rename and set primary keys in companies table
ALTER TABLE companies RENAME COLUMN company_uuid TO company_id;
ALTER TABLE companies ADD PRIMARY KEY (company_id);
ALTER TABLE companies RENAME COLUMN country_uuid_fk TO country_id;

-- Rename and set primary keys in user_companies table
ALTER TABLE user_companies RENAME COLUMN user_company_uuid TO user_company_id;
ALTER TABLE user_companies ADD PRIMARY KEY (user_company_id);
ALTER TABLE user_companies RENAME COLUMN user_uuid_fk TO user_id;
ALTER TABLE user_companies RENAME COLUMN company_uuid_fk TO company_id;

-- Rename and set primary keys in beach_terrain_types table
ALTER TABLE beach_terrain_types RENAME COLUMN terrain_type_uuid TO terrain_type_id;
ALTER TABLE beach_terrain_types ADD PRIMARY KEY (terrain_type_id);

-- Rename and set primary keys in beach_bed_types table
ALTER TABLE beach_bed_types RENAME COLUMN bed_type_uuid TO bed_type_id;
ALTER TABLE beach_bed_types ADD PRIMARY KEY (bed_type_id);

-- Rename and set primary keys in beach_places table
ALTER TABLE beach_places RENAME COLUMN beach_place_uuid TO beach_place_id;
ALTER TABLE beach_places ADD PRIMARY KEY (beach_place_id);
ALTER TABLE beach_places RENAME COLUMN company_uuid_fk TO company_id;
ALTER TABLE beach_places RENAME COLUMN terrain_type_uuid_fk TO terrain_type_id;
ALTER TABLE beach_places RENAME COLUMN country_uuid_fk TO country_id;

-- Rename and set primary keys in beach_places_photos table
ALTER TABLE beach_places_photos RENAME COLUMN photo_uuid TO photo_id;
ALTER TABLE beach_places_photos ADD PRIMARY KEY (photo_id);
ALTER TABLE beach_places_photos RENAME COLUMN beach_place_uuid_fk TO beach_place_id;

-- Rename and set primary keys in beach_places_schedules table
ALTER TABLE beach_places_schedules RENAME COLUMN schedule_uuid TO schedule_id;
ALTER TABLE beach_places_schedules ADD PRIMARY KEY (schedule_id);
ALTER TABLE beach_places_schedules RENAME COLUMN beach_place_uuid_fk TO beach_place_id;
ALTER TABLE beach_places_schedules RENAME COLUMN currency_uuid_fk TO currency_id;

-- Rename and set primary keys in beach_place_terrains table
ALTER TABLE beach_place_terrains RENAME COLUMN beach_place_uuid_fk TO beach_place_id;

-- Rename and set primary keys in restaurants table
ALTER TABLE restaurants RENAME COLUMN restaurant_uuid TO restaurant_id;
ALTER TABLE restaurants ADD PRIMARY KEY (restaurant_id);
ALTER TABLE restaurants RENAME COLUMN company_uuid_fk TO company_id;
ALTER TABLE restaurants RENAME COLUMN beach_place_uuid_fk TO beach_place_id;

-- Rename and set primary keys in restaurant_categories table
ALTER TABLE restaurant_categories RENAME COLUMN category_uuid TO category_id;
ALTER TABLE restaurant_categories ADD PRIMARY KEY (category_id);
ALTER TABLE restaurant_categories RENAME COLUMN restaurant_uuid_fk TO restaurant_id;

-- Rename and set primary keys in restaurant_items table
ALTER TABLE restaurant_items RENAME COLUMN item_uuid TO item_id;
ALTER TABLE restaurant_items ADD PRIMARY KEY (item_id);
ALTER TABLE restaurant_items RENAME COLUMN restaurant_uuid_fk TO restaurant_id;
ALTER TABLE restaurant_items RENAME COLUMN category_uuid_fk TO category_id;
ALTER TABLE restaurant_items RENAME COLUMN currency_uuid_fk TO currency_id;

-- Rename and set primary keys in markets table
ALTER TABLE markets RENAME COLUMN market_uuid TO market_id;
ALTER TABLE markets ADD PRIMARY KEY (market_id);
ALTER TABLE markets RENAME COLUMN company_uuid_fk TO company_id;
ALTER TABLE markets RENAME COLUMN beach_place_uuid_fk TO beach_place_id;

-- Rename and set primary keys in market_categories table
ALTER TABLE market_categories RENAME COLUMN category_uuid TO category_id;
ALTER TABLE market_categories ADD PRIMARY KEY (category_id);
ALTER TABLE market_categories RENAME COLUMN market_uuid_fk TO market_id;

-- Rename and set primary keys in market_items table
ALTER TABLE market_items RENAME COLUMN item_uuid TO item_id;
ALTER TABLE market_items ADD PRIMARY KEY (item_id);
ALTER TABLE market_items RENAME COLUMN market_uuid_fk TO market_id;
ALTER TABLE market_items RENAME COLUMN category_uuid_fk TO category_id;
ALTER TABLE market_items RENAME COLUMN currency_uuid_fk TO currency_id;

-- Rename and set primary keys in adventures table
ALTER TABLE adventures RENAME COLUMN adventure_uuid TO adventure_id;
ALTER TABLE adventures ADD PRIMARY KEY (adventure_id);
ALTER TABLE adventures RENAME COLUMN company_uuid_fk TO company_id;
ALTER TABLE adventures RENAME COLUMN beach_place_uuid_fk TO beach_place_id;
ALTER TABLE adventures RENAME COLUMN currency_uuid_fk TO currency_id;

-- Rename and set primary keys in adventure_schedules table
ALTER TABLE adventure_schedules RENAME COLUMN schedule_uuid TO schedule_id;
ALTER TABLE adventure_schedules ADD PRIMARY KEY (schedule_id);
ALTER TABLE adventure_schedules RENAME COLUMN adventure_uuid_fk TO adventure_id;

-- Rename and set primary keys in bookings table
ALTER TABLE bookings RENAME COLUMN booking_uuid TO booking_id;
ALTER TABLE bookings ADD PRIMARY KEY (booking_id);
ALTER TABLE bookings RENAME COLUMN user_uuid_fk TO user_id;
ALTER TABLE bookings RENAME COLUMN beach_place_uuid_fk TO beach_place_id;
ALTER TABLE bookings RENAME COLUMN currency_uuid_fk TO currency_id;

-- Rename and set primary keys in reviews table
ALTER TABLE reviews RENAME COLUMN review_uuid TO review_id;
ALTER TABLE reviews ADD PRIMARY KEY (review_id);
ALTER TABLE reviews RENAME COLUMN user_uuid_fk TO user_id;
ALTER TABLE reviews RENAME COLUMN beach_place_uuid_fk TO beach_place_id;
ALTER TABLE reviews RENAME COLUMN booking_uuid_fk TO booking_id;

-- Rename and set primary keys in user_wallets table
ALTER TABLE user_wallets RENAME COLUMN wallet_uuid TO wallet_id;
ALTER TABLE user_wallets ADD PRIMARY KEY (wallet_id);
ALTER TABLE user_wallets RENAME COLUMN user_uuid_fk TO user_id;
ALTER TABLE user_wallets RENAME COLUMN currency_uuid_fk TO currency_id;

-- Rename and set primary keys in wallet_transactions table
ALTER TABLE wallet_transactions RENAME COLUMN transaction_uuid TO transaction_id;
ALTER TABLE wallet_transactions ADD PRIMARY KEY (transaction_id);
ALTER TABLE wallet_transactions RENAME COLUMN wallet_uuid_fk TO wallet_id;
ALTER TABLE wallet_transactions RENAME COLUMN currency_uuid_fk TO currency_id;

-- Rename and set primary keys in email_templates table
ALTER TABLE email_templates RENAME COLUMN template_uuid TO template_id;
ALTER TABLE email_templates ADD PRIMARY KEY (template_id);

-- Rename and set primary keys in email_logs table
ALTER TABLE email_logs RENAME COLUMN log_uuid TO log_id;
ALTER TABLE email_logs ADD PRIMARY KEY (log_id);
ALTER TABLE email_logs RENAME COLUMN template_uuid_fk TO template_id;

-- Rename and set primary keys in system_settings table
ALTER TABLE system_settings RENAME COLUMN setting_uuid TO setting_id;
ALTER TABLE system_settings ADD PRIMARY KEY (setting_id);

-- Rename and set primary keys in email_verification_tokens table
ALTER TABLE email_verification_tokens RENAME COLUMN token_uuid TO token_id;
ALTER TABLE email_verification_tokens ADD PRIMARY KEY (token_id);
ALTER TABLE email_verification_tokens RENAME COLUMN user_uuid_fk TO user_id;

-- 6. Add foreign key constraints

-- Add foreign key constraints to users table
ALTER TABLE users ADD CONSTRAINT fk_users_role FOREIGN KEY (role_id) REFERENCES user_roles(role_id);
ALTER TABLE users ADD CONSTRAINT fk_users_language FOREIGN KEY (preferred_language_id) REFERENCES languages(language_id);
ALTER TABLE users ADD CONSTRAINT fk_users_currency FOREIGN KEY (preferred_currency_id) REFERENCES currencies(currency_id);

-- Add foreign key constraints to email_verification_tokens table
ALTER TABLE email_verification_tokens ADD CONSTRAINT fk_email_tokens_user FOREIGN KEY (user_id) REFERENCES users(user_id);

-- Add foreign key constraints to companies table
ALTER TABLE companies ADD CONSTRAINT fk_companies_country FOREIGN KEY (country_id) REFERENCES countries(country_id);

-- Add foreign key constraints to user_companies table
ALTER TABLE user_companies ADD CONSTRAINT fk_user_companies_user FOREIGN KEY (user_id) REFERENCES users(user_id);
ALTER TABLE user_companies ADD CONSTRAINT fk_user_companies_company FOREIGN KEY (company_id) REFERENCES companies(company_id);

-- Add foreign key constraints to beach_places table
ALTER TABLE beach_places ADD CONSTRAINT fk_beach_places_company FOREIGN KEY (company_id) REFERENCES companies(company_id);
ALTER TABLE beach_places ADD CONSTRAINT fk_beach_places_terrain_type FOREIGN KEY (terrain_type_id) REFERENCES beach_terrain_types(terrain_type_id);
ALTER TABLE beach_places ADD CONSTRAINT fk_beach_places_country FOREIGN KEY (country_id) REFERENCES countries(country_id);

-- Add foreign key constraints to beach_places_photos table
ALTER TABLE beach_places_photos ADD CONSTRAINT fk_beach_photos_beach_place FOREIGN KEY (beach_place_id) REFERENCES beach_places(beach_place_id);

-- Add foreign key constraints to beach_places_schedules table
ALTER TABLE beach_places_schedules ADD CONSTRAINT fk_beach_schedules_beach_place FOREIGN KEY (beach_place_id) REFERENCES beach_places(beach_place_id);
ALTER TABLE beach_places_schedules ADD CONSTRAINT fk_beach_schedules_currency FOREIGN KEY (currency_id) REFERENCES currencies(currency_id);

-- Add foreign key constraints to beach_place_terrains table
ALTER TABLE beach_place_terrains ADD CONSTRAINT fk_beach_terrains_beach_place FOREIGN KEY (beach_place_id) REFERENCES beach_places(beach_place_id);

-- Add foreign key constraints to restaurants table
ALTER TABLE restaurants ADD CONSTRAINT fk_restaurants_company FOREIGN KEY (company_id) REFERENCES companies(company_id);
ALTER TABLE restaurants ADD CONSTRAINT fk_restaurants_beach_place FOREIGN KEY (beach_place_id) REFERENCES beach_places(beach_place_id);

-- Add foreign key constraints to restaurant_categories table
ALTER TABLE restaurant_categories ADD CONSTRAINT fk_restaurant_categories_restaurant FOREIGN KEY (restaurant_id) REFERENCES restaurants(restaurant_id);

-- Add foreign key constraints to restaurant_items table
ALTER TABLE restaurant_items ADD CONSTRAINT fk_restaurant_items_restaurant FOREIGN KEY (restaurant_id) REFERENCES restaurants(restaurant_id);
ALTER TABLE restaurant_items ADD CONSTRAINT fk_restaurant_items_category FOREIGN KEY (category_id) REFERENCES restaurant_categories(category_id);
ALTER TABLE restaurant_items ADD CONSTRAINT fk_restaurant_items_currency FOREIGN KEY (currency_id) REFERENCES currencies(currency_id);

-- Add foreign key constraints to markets table
ALTER TABLE markets ADD CONSTRAINT fk_markets_company FOREIGN KEY (company_id) REFERENCES companies(company_id);
ALTER TABLE markets ADD CONSTRAINT fk_markets_beach_place FOREIGN KEY (beach_place_id) REFERENCES beach_places(beach_place_id);

-- Add foreign key constraints to market_categories table
ALTER TABLE market_categories ADD CONSTRAINT fk_market_categories_market FOREIGN KEY (market_id) REFERENCES markets(market_id);

-- Add foreign key constraints to market_items table
ALTER TABLE market_items ADD CONSTRAINT fk_market_items_market FOREIGN KEY (market_id) REFERENCES markets(market_id);
ALTER TABLE market_items ADD CONSTRAINT fk_market_items_category FOREIGN KEY (category_id) REFERENCES market_categories(category_id);
ALTER TABLE market_items ADD CONSTRAINT fk_market_items_currency FOREIGN KEY (currency_id) REFERENCES currencies(currency_id);

-- Add foreign key constraints to adventures table
ALTER TABLE adventures ADD CONSTRAINT fk_adventures_company FOREIGN KEY (company_id) REFERENCES companies(company_id);
ALTER TABLE adventures ADD CONSTRAINT fk_adventures_beach_place FOREIGN KEY (beach_place_id) REFERENCES beach_places(beach_place_id);
ALTER TABLE adventures ADD CONSTRAINT fk_adventures_currency FOREIGN KEY (currency_id) REFERENCES currencies(currency_id);

-- Add foreign key constraints to adventure_schedules table
ALTER TABLE adventure_schedules ADD CONSTRAINT fk_adventure_schedules_adventure FOREIGN KEY (adventure_id) REFERENCES adventures(adventure_id);

-- Add foreign key constraints to bookings table
ALTER TABLE bookings ADD CONSTRAINT fk_bookings_user FOREIGN KEY (user_id) REFERENCES users(user_id);
ALTER TABLE bookings ADD CONSTRAINT fk_bookings_beach_place FOREIGN KEY (beach_place_id) REFERENCES beach_places(beach_place_id);
ALTER TABLE bookings ADD CONSTRAINT fk_bookings_currency FOREIGN KEY (currency_id) REFERENCES currencies(currency_id);

-- Add foreign key constraints to reviews table
ALTER TABLE reviews ADD CONSTRAINT fk_reviews_user FOREIGN KEY (user_id) REFERENCES users(user_id);
ALTER TABLE reviews ADD CONSTRAINT fk_reviews_beach_place FOREIGN KEY (beach_place_id) REFERENCES beach_places(beach_place_id);
ALTER TABLE reviews ADD CONSTRAINT fk_reviews_booking FOREIGN KEY (booking_id) REFERENCES bookings(booking_id);

-- Add foreign key constraints to user_wallets table
ALTER TABLE user_wallets ADD CONSTRAINT fk_user_wallets_user FOREIGN KEY (user_id) REFERENCES users(user_id);
ALTER TABLE user_wallets ADD CONSTRAINT fk_user_wallets_currency FOREIGN KEY (currency_id) REFERENCES currencies(currency_id);

-- Add foreign key constraints to wallet_transactions table
ALTER TABLE wallet_transactions ADD CONSTRAINT fk_wallet_transactions_wallet FOREIGN KEY (wallet_id) REFERENCES user_wallets(wallet_id);
ALTER TABLE wallet_transactions ADD CONSTRAINT fk_wallet_transactions_currency FOREIGN KEY (currency_id) REFERENCES currencies(currency_id);

-- Add foreign key constraints to email_logs table
ALTER TABLE email_logs ADD CONSTRAINT fk_email_logs_template FOREIGN KEY (template_id) REFERENCES email_templates(template_id);

-- 7. Create indexes for better performance

-- Create indexes on foreign key columns
CREATE INDEX idx_users_role_id ON users(role_id);
CREATE INDEX idx_users_preferred_language_id ON users(preferred_language_id);
CREATE INDEX idx_users_preferred_currency_id ON users(preferred_currency_id);
CREATE INDEX idx_email_verification_tokens_user_id ON email_verification_tokens(user_id);
CREATE INDEX idx_companies_country_id ON companies(country_id);
CREATE INDEX idx_user_companies_user_id ON user_companies(user_id);
CREATE INDEX idx_user_companies_company_id ON user_companies(company_id);
CREATE INDEX idx_beach_places_company_id ON beach_places(company_id);
CREATE INDEX idx_beach_places_terrain_type_id ON beach_places(terrain_type_id);
CREATE INDEX idx_beach_places_country_id ON beach_places(country_id);
CREATE INDEX idx_beach_places_photos_beach_place_id ON beach_places_photos(beach_place_id);
CREATE INDEX idx_beach_places_schedules_beach_place_id ON beach_places_schedules(beach_place_id);
CREATE INDEX idx_beach_places_schedules_currency_id ON beach_places_schedules(currency_id);
CREATE INDEX idx_beach_place_terrains_beach_place_id ON beach_place_terrains(beach_place_id);
CREATE INDEX idx_restaurants_company_id ON restaurants(company_id);
CREATE INDEX idx_restaurants_beach_place_id ON restaurants(beach_place_id);
CREATE INDEX idx_restaurant_categories_restaurant_id ON restaurant_categories(restaurant_id);
CREATE INDEX idx_restaurant_items_restaurant_id ON restaurant_items(restaurant_id);
CREATE INDEX idx_restaurant_items_category_id ON restaurant_items(category_id);
CREATE INDEX idx_restaurant_items_currency_id ON restaurant_items(currency_id);
CREATE INDEX idx_markets_company_id ON markets(company_id);
CREATE INDEX idx_markets_beach_place_id ON markets(beach_place_id);
CREATE INDEX idx_market_categories_market_id ON market_categories(market_id);
CREATE INDEX idx_market_items_market_id ON market_items(market_id);
CREATE INDEX idx_market_items_category_id ON market_items(category_id);
CREATE INDEX idx_market_items_currency_id ON market_items(currency_id);
CREATE INDEX idx_adventures_company_id ON adventures(company_id);
CREATE INDEX idx_adventures_beach_place_id ON adventures(beach_place_id);
CREATE INDEX idx_adventures_currency_id ON adventures(currency_id);
CREATE INDEX idx_adventure_schedules_adventure_id ON adventure_schedules(adventure_id);
CREATE INDEX idx_bookings_user_id ON bookings(user_id);
CREATE INDEX idx_bookings_beach_place_id ON bookings(beach_place_id);
CREATE INDEX idx_bookings_currency_id ON bookings(currency_id);
CREATE INDEX idx_reviews_user_id ON reviews(user_id);
CREATE INDEX idx_reviews_beach_place_id ON reviews(beach_place_id);
CREATE INDEX idx_reviews_booking_id ON reviews(booking_id);
CREATE INDEX idx_user_wallets_user_id ON user_wallets(user_id);
CREATE INDEX idx_user_wallets_currency_id ON user_wallets(currency_id);
CREATE INDEX idx_wallet_transactions_wallet_id ON wallet_transactions(wallet_id);
CREATE INDEX idx_wallet_transactions_currency_id ON wallet_transactions(currency_id);
CREATE INDEX idx_email_logs_template_id ON email_logs(template_id);

-- Migration completed