Files
editor/supabase/migrations/20240211000001_create_auth_tables.sql
T
Aymeric RabotandClaude Opus 4.6 aa27e0dd7a refactor: move supabase config to repo root, fix port and env setup
- Move supabase/ from packages/db/ to repo root for simpler CLI usage
- Use custom ports (553xx) to avoid conflicts with other local Supabase instances
- Add --env-mode=loose to turbo dev so root .env vars reach Next.js
- Remove hardcoded --port 3000 from next dev (reads PORT env var instead)
- Add .env.example with Supabase env var placeholders
- Add supabase local state dirs to .gitignore

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-18 01:48:53 -05:00

81 lines
2.8 KiB
SQL

-- Better Auth tables (copied from working monorepo)
-- Using auth_ prefix and snake_case columns
CREATE TYPE "public"."auth_user_roles" AS ENUM('user', 'admin');
CREATE TABLE "auth_accounts" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"provider_id" text NOT NULL,
"account_id" text NOT NULL,
"password" text,
"access_token" text,
"refresh_token" text,
"id_token" text,
"access_token_expires_at" timestamp with time zone,
"refresh_token_expires_at" timestamp with time zone,
"scope" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
ALTER TABLE "auth_accounts" ENABLE ROW LEVEL SECURITY;
CREATE TABLE "auth_jwks" (
"id" text PRIMARY KEY NOT NULL,
"public_key" text NOT NULL,
"private_key" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
ALTER TABLE "auth_jwks" ENABLE ROW LEVEL SECURITY;
CREATE TABLE "auth_sessions" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"expires_at" timestamp with time zone,
"token" text NOT NULL,
"ip_address" text,
"user_agent" text,
"impersonated_by" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
ALTER TABLE "auth_sessions" ENABLE ROW LEVEL SECURITY;
CREATE TABLE "auth_users" (
"id" text PRIMARY KEY NOT NULL,
"email" text NOT NULL,
"email_verified" boolean DEFAULT false NOT NULL,
"name" text NOT NULL,
"image" text,
"role" "auth_user_roles" DEFAULT 'user' NOT NULL,
"banned" boolean DEFAULT false NOT NULL,
"ban_reason" text,
"ban_expires" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
ALTER TABLE "auth_users" ENABLE ROW LEVEL SECURITY;
CREATE TABLE "auth_verifications" (
"id" text PRIMARY KEY NOT NULL,
"value" text NOT NULL,
"identifier" text NOT NULL,
"expires_at" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
ALTER TABLE "auth_verifications" ENABLE ROW LEVEL SECURITY;
ALTER TABLE "auth_accounts" ADD CONSTRAINT "auth_accounts_user_id_auth_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."auth_users"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "auth_sessions" ADD CONSTRAINT "auth_sessions_user_id_auth_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."auth_users"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "auth_sessions" ADD CONSTRAINT "auth_sessions_impersonated_by_auth_users_id_fk" FOREIGN KEY ("impersonated_by") REFERENCES "public"."auth_users"("id") ON DELETE set null ON UPDATE no action;
CREATE UNIQUE INDEX "email_unique_index" ON "auth_users" USING btree (lower("email"));