Skip to content

Commit

Permalink
feat(user): add user api keys schema + api
Browse files Browse the repository at this point in the history
  • Loading branch information
baktun14 authored Feb 12, 2025
1 parent c9d3b45 commit 2eac7e9
Show file tree
Hide file tree
Showing 31 changed files with 1,878 additions and 88 deletions.
2 changes: 1 addition & 1 deletion apps/api/drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { defineConfig } from "drizzle-kit";
import { config } from "./src/core/config";

export default defineConfig({
schema: ["billing", "user", "deployment"].map(schema => `./src/${schema}/model-schemas`),
schema: ["billing", "user", "deployment", "auth"].map(schema => `./src/${schema}/model-schemas`),
out: "./drizzle",
dialect: "postgresql",
dbCredentials: {
Expand Down
18 changes: 18 additions & 0 deletions apps/api/drizzle/0012_blushing_brother_voodoo.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TABLE IF NOT EXISTS "api_keys" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL,
"user_id" uuid NOT NULL,
"hashed_key" varchar NOT NULL,
"key_format" varchar NOT NULL,
"name" varchar NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
"expires_at" timestamp,
CONSTRAINT "api_keys_hashed_key_unique" UNIQUE("hashed_key"),
CONSTRAINT "api_keys_key_format_unique" UNIQUE("key_format")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "api_keys" ADD CONSTRAINT "api_keys_user_id_userSetting_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."userSetting"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
Loading

0 comments on commit 2eac7e9

Please sign in to comment.