26 lines
1.0 KiB
SQL
26 lines
1.0 KiB
SQL
CREATE TABLE IF NOT EXISTS "auth_sessions" (
|
|
"id" uuid PRIMARY KEY NOT NULL,
|
|
"user_id" integer NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"last_active_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"expires_at" timestamp with time zone NOT NULL,
|
|
"ip_address" text,
|
|
"user_agent" text,
|
|
"browser" text,
|
|
"operating_system" text,
|
|
"device" text,
|
|
"login_method" text DEFAULT 'password' NOT NULL,
|
|
"revoked_at" timestamp with time zone,
|
|
"revoked_reason" text
|
|
);
|
|
--> statement-breakpoint
|
|
DO $$ BEGIN
|
|
ALTER TABLE "auth_sessions" ADD CONSTRAINT "auth_sessions_user_id_User_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE no action;
|
|
EXCEPTION
|
|
WHEN duplicate_object THEN null;
|
|
END $$;
|
|
--> statement-breakpoint
|
|
CREATE INDEX IF NOT EXISTS "auth_sessions_user_active_idx" ON "auth_sessions" USING btree ("user_id","revoked_at","expires_at");
|
|
--> statement-breakpoint
|
|
CREATE INDEX IF NOT EXISTS "auth_sessions_last_active_idx" ON "auth_sessions" USING btree ("last_active_at");
|