50 lines
1.7 KiB
MySQL
50 lines
1.7 KiB
MySQL
|
|
CREATE TABLE IF NOT EXISTS "accounts" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"account_id" text NOT NULL,
|
||
|
|
"provider_id" text NOT NULL,
|
||
|
|
"user_id" uuid NOT NULL,
|
||
|
|
"access_token" text,
|
||
|
|
"refresh_token" text,
|
||
|
|
"id_token" text,
|
||
|
|
"expires_at" timestamp,
|
||
|
|
"password" text,
|
||
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updated_at" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE IF NOT EXISTS "sessions" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"expires_at" timestamp NOT NULL,
|
||
|
|
"token" text NOT NULL,
|
||
|
|
"user_id" uuid NOT NULL,
|
||
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updated_at" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"ip_address" text,
|
||
|
|
"user_agent" text,
|
||
|
|
CONSTRAINT "sessions_token_unique" UNIQUE("token")
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE IF NOT EXISTS "verifications" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"identifier" text NOT NULL,
|
||
|
|
"value" text NOT NULL,
|
||
|
|
"expires_at" timestamp NOT NULL,
|
||
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updated_at" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
ALTER TABLE "users" ALTER COLUMN "clerk_id" DROP NOT NULL;--> statement-breakpoint
|
||
|
|
ALTER TABLE "users" ADD COLUMN "email_verified" boolean DEFAULT false NOT NULL;--> statement-breakpoint
|
||
|
|
DO $$ BEGIN
|
||
|
|
ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
|
||
|
|
EXCEPTION
|
||
|
|
WHEN duplicate_object THEN null;
|
||
|
|
END $$;
|
||
|
|
--> statement-breakpoint
|
||
|
|
DO $$ BEGIN
|
||
|
|
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
|
||
|
|
EXCEPTION
|
||
|
|
WHEN duplicate_object THEN null;
|
||
|
|
END $$;
|
||
|
|
--> statement-breakpoint
|