Files
madbase/migrations/20260317100000_move_users_to_auth.sql
Vlad Durnea a66d908eff
Some checks failed
CI / podman-build (push) Has been cancelled
CI / rust (push) Has been cancelled
chore: full stack stability and migration fixes, plus react UI progress
2026-03-18 09:01:38 +02:00

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.