peppa/packages/db/migrations/0000_safe_shiver_man.sql
Асель 9824ce4c18 Add Peppa MCP server, core domain package and peppa CLI
- @peppa/core: projects, goals, tasks (atomic per-project numbering),
  PM questions, progress events, pg NOTIFY on peppa_events
- @peppa/mcp (peppa-mcp): get_task, list_tasks, list_goals, create_task,
  update_task, request_approval, ask_pm, report_progress
- @peppa/cli (peppa): project/goal/task/q commands
- questions/events now link to project and task; session is optional
- scripts/install-bins.sh; bootstrap-project.sh registers the project

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 19:18:35 +05:00

94 lines
5.0 KiB
SQL

CREATE TYPE "public"."goal_status" AS ENUM('open', 'done', 'archived');--> statement-breakpoint
CREATE TYPE "public"."session_status" AS ENUM('starting', 'running', 'waiting_input', 'idle', 'stalled', 'done', 'failed');--> statement-breakpoint
CREATE TYPE "public"."task_status" AS ENUM('backlog', 'proposing', 'awaiting_approval', 'in_progress', 'review', 'done', 'blocked');--> statement-breakpoint
CREATE TABLE "events" (
"id" serial PRIMARY KEY NOT NULL,
"project_id" integer NOT NULL,
"task_id" integer,
"session_id" integer,
"type" text NOT NULL,
"payload" jsonb,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "goals" (
"id" serial PRIMARY KEY NOT NULL,
"project_id" integer NOT NULL,
"title" text NOT NULL,
"description" text,
"status" "goal_status" DEFAULT 'open' NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "projects" (
"id" serial PRIMARY KEY NOT NULL,
"slug" text NOT NULL,
"key" text NOT NULL,
"name" text NOT NULL,
"description" text,
"gitea_owner" text NOT NULL,
"gitea_repo" text NOT NULL,
"default_branch" text DEFAULT 'main' NOT NULL,
"workspace_path" text NOT NULL,
"next_task_number" integer DEFAULT 1 NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "projects_slug_unique" UNIQUE("slug"),
CONSTRAINT "projects_key_unique" UNIQUE("key")
);
--> statement-breakpoint
CREATE TABLE "questions" (
"id" serial PRIMARY KEY NOT NULL,
"project_id" integer NOT NULL,
"task_id" integer,
"session_id" integer,
"kind" text NOT NULL,
"text" text NOT NULL,
"options" jsonb,
"answer" text,
"answered_via" text,
"telegram_message_id" integer,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"answered_at" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "sessions" (
"id" serial PRIMARY KEY NOT NULL,
"project_id" integer NOT NULL,
"task_id" integer,
"tmux_name" text NOT NULL,
"claude_session_id" text,
"status" "session_status" DEFAULT 'starting' NOT NULL,
"last_activity_at" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"ended_at" timestamp with time zone,
CONSTRAINT "sessions_tmux_name_unique" UNIQUE("tmux_name")
);
--> statement-breakpoint
CREATE TABLE "tasks" (
"id" serial PRIMARY KEY NOT NULL,
"project_id" integer NOT NULL,
"goal_id" integer,
"number" integer NOT NULL,
"title" text NOT NULL,
"description" text,
"status" "task_status" DEFAULT 'backlog' NOT NULL,
"openspec_change" text,
"pr_url" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "events" ADD CONSTRAINT "events_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "events" ADD CONSTRAINT "events_task_id_tasks_id_fk" FOREIGN KEY ("task_id") REFERENCES "public"."tasks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "events" ADD CONSTRAINT "events_session_id_sessions_id_fk" FOREIGN KEY ("session_id") REFERENCES "public"."sessions"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "goals" ADD CONSTRAINT "goals_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "questions" ADD CONSTRAINT "questions_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "questions" ADD CONSTRAINT "questions_task_id_tasks_id_fk" FOREIGN KEY ("task_id") REFERENCES "public"."tasks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "questions" ADD CONSTRAINT "questions_session_id_sessions_id_fk" FOREIGN KEY ("session_id") REFERENCES "public"."sessions"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_task_id_tasks_id_fk" FOREIGN KEY ("task_id") REFERENCES "public"."tasks"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "tasks" ADD CONSTRAINT "tasks_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "tasks" ADD CONSTRAINT "tasks_goal_id_goals_id_fk" FOREIGN KEY ("goal_id") REFERENCES "public"."goals"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "tasks_project_number" ON "tasks" USING btree ("project_id","number");