Skip to content

Commit 73895a8

Browse files
[feat] initial agent store schema (#219)
Co-authored-by: Codebuff <noreply@codebuff.com>
1 parent 47c6ae4 commit 73895a8

File tree

4 files changed

+2073
-0
lines changed

4 files changed

+2073
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
CREATE TABLE IF NOT EXISTS "agent_template" (
2+
"id" text,
3+
"version" text NOT NULL,
4+
"publisher_id" text NOT NULL,
5+
"major" integer GENERATED ALWAYS AS (CAST(SPLIT_PART("agent_template"."version", '.', 1) AS INTEGER)) STORED,
6+
"minor" integer GENERATED ALWAYS AS (CAST(SPLIT_PART("agent_template"."version", '.', 2) AS INTEGER)) STORED,
7+
"patch" integer GENERATED ALWAYS AS (CAST(SPLIT_PART("agent_template"."version", '.', 3) AS INTEGER)) STORED,
8+
"template" jsonb NOT NULL,
9+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
10+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
11+
CONSTRAINT "agent_template_id_version_pk" PRIMARY KEY("id","version")
12+
);
13+
--> statement-breakpoint
14+
CREATE TABLE IF NOT EXISTS "publisher" (
15+
"id" text PRIMARY KEY NOT NULL,
16+
"slug" text NOT NULL,
17+
"name" text NOT NULL,
18+
"email" text,
19+
"verified" boolean DEFAULT false NOT NULL,
20+
"bio" text,
21+
"avatar_url" text,
22+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
23+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
24+
CONSTRAINT "publisher_slug_unique" UNIQUE("slug")
25+
);
26+
--> statement-breakpoint
27+
DO $$ BEGIN
28+
ALTER TABLE "agent_template" ADD CONSTRAINT "agent_template_publisher_id_publisher_id_fk" FOREIGN KEY ("publisher_id") REFERENCES "public"."publisher"("id") ON DELETE no action ON UPDATE no action;
29+
EXCEPTION
30+
WHEN duplicate_object THEN null;
31+
END $$;
32+
--> statement-breakpoint
33+
CREATE INDEX IF NOT EXISTS "idx_agent_template_publisher" ON "agent_template" USING btree ("publisher_id");

0 commit comments

Comments
 (0)