Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions apps/backend/migrations-postgres/0038_mcp_endpoint.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
CREATE TABLE "mcp_call_log" (
"id" text PRIMARY KEY NOT NULL,
"project_id" text NOT NULL,
"user_id" text NOT NULL,
"tool_name" text NOT NULL,
"duration_ms" integer,
"success" boolean NOT NULL,
"tool_input" jsonb,
"tool_output" jsonb,
"called_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "oauth_access_token" (
"id" text PRIMARY KEY NOT NULL,
"access_token" text NOT NULL,
"refresh_token" text NOT NULL,
"access_token_expires_at" timestamp NOT NULL,
"refresh_token_expires_at" timestamp NOT NULL,
"client_id" text NOT NULL,
"user_id" text,
"scopes" text NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "oauth_access_token_access_token_unique" UNIQUE("access_token"),
CONSTRAINT "oauth_access_token_refresh_token_unique" UNIQUE("refresh_token")
);
--> statement-breakpoint
CREATE TABLE "oauth_application" (
"id" text PRIMARY KEY NOT NULL,
"name" text,
"icon" text,
"metadata" text,
"client_id" text NOT NULL,
"client_secret" text,
"redirect_urls" text NOT NULL,
"type" text NOT NULL,
"authentication_scheme" text,
"disabled" boolean DEFAULT false,
"user_id" text,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "oauth_application_client_id_unique" UNIQUE("client_id")
);
--> statement-breakpoint
CREATE TABLE "oauth_consent" (
"id" text PRIMARY KEY NOT NULL,
"client_id" text NOT NULL,
"user_id" text NOT NULL,
"scopes" text NOT NULL,
"consent_given" boolean NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "story" ALTER COLUMN "chat_id" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "project" ADD COLUMN "mcp_endpoint_settings" jsonb;--> statement-breakpoint
ALTER TABLE "story" ADD COLUMN "project_id" text;--> statement-breakpoint
ALTER TABLE "story" ADD COLUMN "user_id" text;--> statement-breakpoint
ALTER TABLE "mcp_call_log" ADD CONSTRAINT "mcp_call_log_project_id_project_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."project"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "mcp_call_log" ADD CONSTRAINT "mcp_call_log_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "oauth_access_token" ADD CONSTRAINT "oauth_access_token_client_id_oauth_application_client_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."oauth_application"("client_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "oauth_access_token" ADD CONSTRAINT "oauth_access_token_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "oauth_application" ADD CONSTRAINT "oauth_application_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "oauth_consent" ADD CONSTRAINT "oauth_consent_client_id_oauth_application_client_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."oauth_application"("client_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "oauth_consent" ADD CONSTRAINT "oauth_consent_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "mcp_call_log_projectId_idx" ON "mcp_call_log" USING btree ("project_id");--> statement-breakpoint
CREATE INDEX "mcp_call_log_userId_idx" ON "mcp_call_log" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX "mcp_call_log_calledAt_idx" ON "mcp_call_log" USING btree ("called_at");--> statement-breakpoint
Comment thread
socallmebertille marked this conversation as resolved.
CREATE INDEX "oauth_access_token_clientId_idx" ON "oauth_access_token" USING btree ("client_id");--> statement-breakpoint
CREATE INDEX "oauth_access_token_userId_idx" ON "oauth_access_token" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX "oauth_application_userId_idx" ON "oauth_application" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX "oauth_consent_clientId_idx" ON "oauth_consent" USING btree ("client_id");--> statement-breakpoint
CREATE INDEX "oauth_consent_userId_idx" ON "oauth_consent" USING btree ("user_id");--> statement-breakpoint
ALTER TABLE "story" ADD CONSTRAINT "story_project_id_project_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."project"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "story" ADD CONSTRAINT "story_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "story_standalone_slug_unique" ON "story" USING btree ("project_id","user_id","slug") WHERE "story"."chat_id" IS NULL;--> statement-breakpoint
CREATE INDEX "story_projectId_idx" ON "story" USING btree ("project_id");--> statement-breakpoint
CREATE INDEX "story_userId_idx" ON "story" USING btree ("user_id");--> statement-breakpoint
ALTER TABLE "story" ADD CONSTRAINT "story_owner_required" CHECK ("story"."chat_id" IS NOT NULL OR ("story"."project_id" IS NOT NULL AND "story"."user_id" IS NOT NULL));
Loading
Loading