-- Migration: Create users table -- Created at: 2026-01-27 -- 1. Create the table CREATE TABLE IF NOT EXISTS public.users ( id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, name TEXT NOT NULL, email TEXT, role TEXT, created_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL ); -- 2. Enable RLS ALTER TABLE public.users ENABLE ROW LEVEL SECURITY; -- 3. Create Policy (Dev Mode: Allow All) -- WARN: In production, you should restrict this! DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM pg_policies WHERE schemaname = 'public' AND tablename = 'users' AND policyname = 'Enable all operations for anon users' ) THEN CREATE POLICY "Enable all operations for anon users" ON public.users FOR ALL TO anon USING (true) WITH CHECK (true); END IF; END $$; -- 4. Seed Data (Optional) INSERT INTO public.users (name, email, role) SELECT 'Alice', 'alice@example.com', 'Admin' WHERE NOT EXISTS ( SELECT 1 FROM public.users WHERE email = 'alice@example.com' ); INSERT INTO public.users (name, email, role) SELECT 'Bob', 'bob@example.com', 'User' WHERE NOT EXISTS ( SELECT 1 FROM public.users WHERE email = 'bob@example.com' );