20 lines
818 B
SQL
20 lines
818 B
SQL
-- Move users and refresh_tokens to auth schema for better isolation and consistency
|
|
CREATE SCHEMA IF NOT EXISTS auth;
|
|
|
|
-- Move the tables (safe and idempotent)
|
|
DO $$
|
|
BEGIN
|
|
IF EXISTS (SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = 'users') THEN
|
|
ALTER TABLE public.users SET SCHEMA auth;
|
|
END IF;
|
|
IF EXISTS (SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = 'refresh_tokens') THEN
|
|
ALTER TABLE public.refresh_tokens SET SCHEMA auth;
|
|
END IF;
|
|
END $$;
|
|
|
|
-- Note: Postgres automatically updates foreign key references and indexes
|
|
-- when a table is moved to a different schema using SET SCHEMA.
|
|
|
|
-- However, we might need to update any explicit cross-schema references in the future
|
|
-- if we were to move to entirely separate databases. For now, they remain in the same DB.
|