@paperclipai/db 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/migrations/0000_mature_masked_marvel.sql +208 -0
- package/dist/migrations/0001_fast_northstar.sql +87 -0
- package/dist/migrations/0002_big_zaladane.sql +1 -0
- package/dist/migrations/0003_shallow_quentin_quire.sql +5 -0
- package/dist/migrations/0004_issue_identifiers.sql +28 -0
- package/dist/migrations/0005_chief_luke_cage.sql +19 -0
- package/dist/migrations/0006_overjoyed_mister_sinister.sql +36 -0
- package/dist/migrations/0007_new_quentin_quire.sql +20 -0
- package/dist/migrations/0008_amused_zzzax.sql +1 -0
- package/dist/migrations/0009_fast_jackal.sql +36 -0
- package/dist/migrations/0010_stale_justin_hammer.sql +37 -0
- package/dist/migrations/0011_windy_corsair.sql +18 -0
- package/dist/migrations/0012_perpetual_ser_duncan.sql +2 -0
- package/dist/migrations/0013_dashing_wasp.sql +4 -0
- package/dist/migrations/0014_many_mikhail_rasputin.sql +135 -0
- package/dist/migrations/0015_project_color_archived.sql +2 -0
- package/dist/migrations/0016_agent_icon.sql +1 -0
- package/dist/migrations/0017_tiresome_gabe_jones.sql +51 -0
- package/dist/migrations/0018_flat_sleepwalker.sql +26 -0
- package/dist/migrations/0019_public_victor_mancha.sql +18 -0
- package/dist/migrations/0020_white_anita_blake.sql +1 -0
- package/dist/migrations/0021_chief_vindicator.sql +1 -0
- package/dist/migrations/0022_company_brand_color.sql +1 -0
- package/dist/migrations/0023_fair_lethal_legion.sql +3 -0
- package/dist/migrations/meta/0000_snapshot.json +1743 -0
- package/dist/migrations/meta/0001_snapshot.json +2441 -0
- package/dist/migrations/meta/0002_snapshot.json +2454 -0
- package/dist/migrations/meta/0003_snapshot.json +2502 -0
- package/dist/migrations/meta/0005_snapshot.json +2719 -0
- package/dist/migrations/meta/0006_snapshot.json +3048 -0
- package/dist/migrations/meta/0007_snapshot.json +3258 -0
- package/dist/migrations/meta/0008_snapshot.json +3264 -0
- package/dist/migrations/meta/0009_snapshot.json +3587 -0
- package/dist/migrations/meta/0010_snapshot.json +3929 -0
- package/dist/migrations/meta/0011_snapshot.json +4068 -0
- package/dist/migrations/meta/0012_snapshot.json +4087 -0
- package/dist/migrations/meta/0013_snapshot.json +4118 -0
- package/dist/migrations/meta/0014_snapshot.json +5187 -0
- package/dist/migrations/meta/0017_snapshot.json +5215 -0
- package/dist/migrations/meta/0018_snapshot.json +5450 -0
- package/dist/migrations/meta/0019_snapshot.json +5603 -0
- package/dist/migrations/meta/0020_snapshot.json +5603 -0
- package/dist/migrations/meta/0021_snapshot.json +5609 -0
- package/dist/migrations/meta/0023_snapshot.json +5633 -0
- package/dist/migrations/meta/_journal.json +174 -0
- package/dist/migrations/migrations/0000_mature_masked_marvel.sql +208 -0
- package/dist/migrations/migrations/0001_fast_northstar.sql +87 -0
- package/dist/migrations/migrations/0002_big_zaladane.sql +1 -0
- package/dist/migrations/migrations/0003_shallow_quentin_quire.sql +5 -0
- package/dist/migrations/migrations/0004_issue_identifiers.sql +28 -0
- package/dist/migrations/migrations/0005_chief_luke_cage.sql +19 -0
- package/dist/migrations/migrations/0006_overjoyed_mister_sinister.sql +36 -0
- package/dist/migrations/migrations/0007_new_quentin_quire.sql +20 -0
- package/dist/migrations/migrations/0008_amused_zzzax.sql +1 -0
- package/dist/migrations/migrations/0009_fast_jackal.sql +36 -0
- package/dist/migrations/migrations/0010_stale_justin_hammer.sql +37 -0
- package/dist/migrations/migrations/0011_windy_corsair.sql +18 -0
- package/dist/migrations/migrations/0012_perpetual_ser_duncan.sql +2 -0
- package/dist/migrations/migrations/0013_dashing_wasp.sql +4 -0
- package/dist/migrations/migrations/0014_many_mikhail_rasputin.sql +135 -0
- package/dist/migrations/migrations/0015_project_color_archived.sql +2 -0
- package/dist/migrations/migrations/0016_agent_icon.sql +1 -0
- package/dist/migrations/migrations/0017_tiresome_gabe_jones.sql +51 -0
- package/dist/migrations/migrations/0018_flat_sleepwalker.sql +26 -0
- package/dist/migrations/migrations/0019_public_victor_mancha.sql +18 -0
- package/dist/migrations/migrations/0020_white_anita_blake.sql +1 -0
- package/dist/migrations/migrations/0021_chief_vindicator.sql +1 -0
- package/dist/migrations/migrations/0022_company_brand_color.sql +1 -0
- package/dist/migrations/migrations/0023_fair_lethal_legion.sql +3 -0
- package/dist/migrations/migrations/meta/0000_snapshot.json +1743 -0
- package/dist/migrations/migrations/meta/0001_snapshot.json +2441 -0
- package/dist/migrations/migrations/meta/0002_snapshot.json +2454 -0
- package/dist/migrations/migrations/meta/0003_snapshot.json +2502 -0
- package/dist/migrations/migrations/meta/0005_snapshot.json +2719 -0
- package/dist/migrations/migrations/meta/0006_snapshot.json +3048 -0
- package/dist/migrations/migrations/meta/0007_snapshot.json +3258 -0
- package/dist/migrations/migrations/meta/0008_snapshot.json +3264 -0
- package/dist/migrations/migrations/meta/0009_snapshot.json +3587 -0
- package/dist/migrations/migrations/meta/0010_snapshot.json +3929 -0
- package/dist/migrations/migrations/meta/0011_snapshot.json +4068 -0
- package/dist/migrations/migrations/meta/0012_snapshot.json +4087 -0
- package/dist/migrations/migrations/meta/0013_snapshot.json +4118 -0
- package/dist/migrations/migrations/meta/0014_snapshot.json +5187 -0
- package/dist/migrations/migrations/meta/0017_snapshot.json +5215 -0
- package/dist/migrations/migrations/meta/0018_snapshot.json +5450 -0
- package/dist/migrations/migrations/meta/0019_snapshot.json +5603 -0
- package/dist/migrations/migrations/meta/0020_snapshot.json +5603 -0
- package/dist/migrations/migrations/meta/0021_snapshot.json +5609 -0
- package/dist/migrations/migrations/meta/0023_snapshot.json +5633 -0
- package/dist/migrations/migrations/meta/_journal.json +174 -0
- package/package.json +3 -3
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
CREATE TABLE "activity_log" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"company_id" uuid NOT NULL,
|
|
4
|
+
"actor_type" text DEFAULT 'system' NOT NULL,
|
|
5
|
+
"actor_id" text NOT NULL,
|
|
6
|
+
"action" text NOT NULL,
|
|
7
|
+
"entity_type" text NOT NULL,
|
|
8
|
+
"entity_id" text NOT NULL,
|
|
9
|
+
"agent_id" uuid,
|
|
10
|
+
"details" jsonb,
|
|
11
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
12
|
+
);
|
|
13
|
+
--> statement-breakpoint
|
|
14
|
+
CREATE TABLE "agent_api_keys" (
|
|
15
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
16
|
+
"agent_id" uuid NOT NULL,
|
|
17
|
+
"company_id" uuid NOT NULL,
|
|
18
|
+
"name" text NOT NULL,
|
|
19
|
+
"key_hash" text NOT NULL,
|
|
20
|
+
"last_used_at" timestamp with time zone,
|
|
21
|
+
"revoked_at" timestamp with time zone,
|
|
22
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
23
|
+
);
|
|
24
|
+
--> statement-breakpoint
|
|
25
|
+
CREATE TABLE "agents" (
|
|
26
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
27
|
+
"company_id" uuid NOT NULL,
|
|
28
|
+
"name" text NOT NULL,
|
|
29
|
+
"role" text DEFAULT 'general' NOT NULL,
|
|
30
|
+
"title" text,
|
|
31
|
+
"status" text DEFAULT 'idle' NOT NULL,
|
|
32
|
+
"reports_to" uuid,
|
|
33
|
+
"capabilities" text,
|
|
34
|
+
"adapter_type" text DEFAULT 'process' NOT NULL,
|
|
35
|
+
"adapter_config" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
36
|
+
"context_mode" text DEFAULT 'thin' NOT NULL,
|
|
37
|
+
"budget_monthly_cents" integer DEFAULT 0 NOT NULL,
|
|
38
|
+
"spent_monthly_cents" integer DEFAULT 0 NOT NULL,
|
|
39
|
+
"last_heartbeat_at" timestamp with time zone,
|
|
40
|
+
"metadata" jsonb,
|
|
41
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
42
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
43
|
+
);
|
|
44
|
+
--> statement-breakpoint
|
|
45
|
+
CREATE TABLE "approvals" (
|
|
46
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
47
|
+
"company_id" uuid NOT NULL,
|
|
48
|
+
"type" text NOT NULL,
|
|
49
|
+
"requested_by_agent_id" uuid,
|
|
50
|
+
"requested_by_user_id" text,
|
|
51
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
52
|
+
"payload" jsonb NOT NULL,
|
|
53
|
+
"decision_note" text,
|
|
54
|
+
"decided_by_user_id" text,
|
|
55
|
+
"decided_at" timestamp with time zone,
|
|
56
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
57
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
58
|
+
);
|
|
59
|
+
--> statement-breakpoint
|
|
60
|
+
CREATE TABLE "companies" (
|
|
61
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
62
|
+
"name" text NOT NULL,
|
|
63
|
+
"description" text,
|
|
64
|
+
"status" text DEFAULT 'active' NOT NULL,
|
|
65
|
+
"budget_monthly_cents" integer DEFAULT 0 NOT NULL,
|
|
66
|
+
"spent_monthly_cents" integer DEFAULT 0 NOT NULL,
|
|
67
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
68
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
69
|
+
);
|
|
70
|
+
--> statement-breakpoint
|
|
71
|
+
CREATE TABLE "cost_events" (
|
|
72
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
73
|
+
"company_id" uuid NOT NULL,
|
|
74
|
+
"agent_id" uuid NOT NULL,
|
|
75
|
+
"issue_id" uuid,
|
|
76
|
+
"project_id" uuid,
|
|
77
|
+
"goal_id" uuid,
|
|
78
|
+
"billing_code" text,
|
|
79
|
+
"provider" text NOT NULL,
|
|
80
|
+
"model" text NOT NULL,
|
|
81
|
+
"input_tokens" integer DEFAULT 0 NOT NULL,
|
|
82
|
+
"output_tokens" integer DEFAULT 0 NOT NULL,
|
|
83
|
+
"cost_cents" integer NOT NULL,
|
|
84
|
+
"occurred_at" timestamp with time zone NOT NULL,
|
|
85
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
86
|
+
);
|
|
87
|
+
--> statement-breakpoint
|
|
88
|
+
CREATE TABLE "goals" (
|
|
89
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
90
|
+
"company_id" uuid NOT NULL,
|
|
91
|
+
"title" text NOT NULL,
|
|
92
|
+
"description" text,
|
|
93
|
+
"level" text DEFAULT 'task' NOT NULL,
|
|
94
|
+
"status" text DEFAULT 'planned' NOT NULL,
|
|
95
|
+
"parent_id" uuid,
|
|
96
|
+
"owner_agent_id" uuid,
|
|
97
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
98
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
99
|
+
);
|
|
100
|
+
--> statement-breakpoint
|
|
101
|
+
CREATE TABLE "heartbeat_runs" (
|
|
102
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
103
|
+
"company_id" uuid NOT NULL,
|
|
104
|
+
"agent_id" uuid NOT NULL,
|
|
105
|
+
"invocation_source" text DEFAULT 'manual' NOT NULL,
|
|
106
|
+
"status" text DEFAULT 'queued' NOT NULL,
|
|
107
|
+
"started_at" timestamp with time zone,
|
|
108
|
+
"finished_at" timestamp with time zone,
|
|
109
|
+
"error" text,
|
|
110
|
+
"external_run_id" text,
|
|
111
|
+
"context_snapshot" jsonb,
|
|
112
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
113
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
114
|
+
);
|
|
115
|
+
--> statement-breakpoint
|
|
116
|
+
CREATE TABLE "issue_comments" (
|
|
117
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
118
|
+
"company_id" uuid NOT NULL,
|
|
119
|
+
"issue_id" uuid NOT NULL,
|
|
120
|
+
"author_agent_id" uuid,
|
|
121
|
+
"author_user_id" text,
|
|
122
|
+
"body" text NOT NULL,
|
|
123
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
124
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
125
|
+
);
|
|
126
|
+
--> statement-breakpoint
|
|
127
|
+
CREATE TABLE "issues" (
|
|
128
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
129
|
+
"company_id" uuid NOT NULL,
|
|
130
|
+
"project_id" uuid,
|
|
131
|
+
"goal_id" uuid,
|
|
132
|
+
"parent_id" uuid,
|
|
133
|
+
"title" text NOT NULL,
|
|
134
|
+
"description" text,
|
|
135
|
+
"status" text DEFAULT 'backlog' NOT NULL,
|
|
136
|
+
"priority" text DEFAULT 'medium' NOT NULL,
|
|
137
|
+
"assignee_agent_id" uuid,
|
|
138
|
+
"created_by_agent_id" uuid,
|
|
139
|
+
"created_by_user_id" text,
|
|
140
|
+
"request_depth" integer DEFAULT 0 NOT NULL,
|
|
141
|
+
"billing_code" text,
|
|
142
|
+
"started_at" timestamp with time zone,
|
|
143
|
+
"completed_at" timestamp with time zone,
|
|
144
|
+
"cancelled_at" timestamp with time zone,
|
|
145
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
146
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
147
|
+
);
|
|
148
|
+
--> statement-breakpoint
|
|
149
|
+
CREATE TABLE "projects" (
|
|
150
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
151
|
+
"company_id" uuid NOT NULL,
|
|
152
|
+
"goal_id" uuid,
|
|
153
|
+
"name" text NOT NULL,
|
|
154
|
+
"description" text,
|
|
155
|
+
"status" text DEFAULT 'backlog' NOT NULL,
|
|
156
|
+
"lead_agent_id" uuid,
|
|
157
|
+
"target_date" date,
|
|
158
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
159
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
160
|
+
);
|
|
161
|
+
--> statement-breakpoint
|
|
162
|
+
ALTER TABLE "activity_log" ADD CONSTRAINT "activity_log_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
163
|
+
ALTER TABLE "activity_log" ADD CONSTRAINT "activity_log_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
164
|
+
ALTER TABLE "agent_api_keys" ADD CONSTRAINT "agent_api_keys_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
165
|
+
ALTER TABLE "agent_api_keys" ADD CONSTRAINT "agent_api_keys_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
166
|
+
ALTER TABLE "agents" ADD CONSTRAINT "agents_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
167
|
+
ALTER TABLE "agents" ADD CONSTRAINT "agents_reports_to_agents_id_fk" FOREIGN KEY ("reports_to") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
168
|
+
ALTER TABLE "approvals" ADD CONSTRAINT "approvals_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
169
|
+
ALTER TABLE "approvals" ADD CONSTRAINT "approvals_requested_by_agent_id_agents_id_fk" FOREIGN KEY ("requested_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
170
|
+
ALTER TABLE "cost_events" ADD CONSTRAINT "cost_events_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
171
|
+
ALTER TABLE "cost_events" ADD CONSTRAINT "cost_events_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
172
|
+
ALTER TABLE "cost_events" ADD CONSTRAINT "cost_events_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
173
|
+
ALTER TABLE "cost_events" ADD CONSTRAINT "cost_events_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
174
|
+
ALTER TABLE "cost_events" ADD CONSTRAINT "cost_events_goal_id_goals_id_fk" FOREIGN KEY ("goal_id") REFERENCES "public"."goals"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
175
|
+
ALTER TABLE "goals" ADD CONSTRAINT "goals_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
176
|
+
ALTER TABLE "goals" ADD CONSTRAINT "goals_parent_id_goals_id_fk" FOREIGN KEY ("parent_id") REFERENCES "public"."goals"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
177
|
+
ALTER TABLE "goals" ADD CONSTRAINT "goals_owner_agent_id_agents_id_fk" FOREIGN KEY ("owner_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
178
|
+
ALTER TABLE "heartbeat_runs" ADD CONSTRAINT "heartbeat_runs_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
179
|
+
ALTER TABLE "heartbeat_runs" ADD CONSTRAINT "heartbeat_runs_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
180
|
+
ALTER TABLE "issue_comments" ADD CONSTRAINT "issue_comments_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
181
|
+
ALTER TABLE "issue_comments" ADD CONSTRAINT "issue_comments_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
182
|
+
ALTER TABLE "issue_comments" ADD CONSTRAINT "issue_comments_author_agent_id_agents_id_fk" FOREIGN KEY ("author_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
183
|
+
ALTER TABLE "issues" ADD CONSTRAINT "issues_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
184
|
+
ALTER TABLE "issues" ADD CONSTRAINT "issues_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
185
|
+
ALTER TABLE "issues" ADD CONSTRAINT "issues_goal_id_goals_id_fk" FOREIGN KEY ("goal_id") REFERENCES "public"."goals"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
186
|
+
ALTER TABLE "issues" ADD CONSTRAINT "issues_parent_id_issues_id_fk" FOREIGN KEY ("parent_id") REFERENCES "public"."issues"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
187
|
+
ALTER TABLE "issues" ADD CONSTRAINT "issues_assignee_agent_id_agents_id_fk" FOREIGN KEY ("assignee_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
188
|
+
ALTER TABLE "issues" ADD CONSTRAINT "issues_created_by_agent_id_agents_id_fk" FOREIGN KEY ("created_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
189
|
+
ALTER TABLE "projects" ADD CONSTRAINT "projects_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
190
|
+
ALTER TABLE "projects" ADD CONSTRAINT "projects_goal_id_goals_id_fk" FOREIGN KEY ("goal_id") REFERENCES "public"."goals"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
191
|
+
ALTER TABLE "projects" ADD CONSTRAINT "projects_lead_agent_id_agents_id_fk" FOREIGN KEY ("lead_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
192
|
+
CREATE INDEX "activity_log_company_created_idx" ON "activity_log" USING btree ("company_id","created_at");--> statement-breakpoint
|
|
193
|
+
CREATE INDEX "agent_api_keys_key_hash_idx" ON "agent_api_keys" USING btree ("key_hash");--> statement-breakpoint
|
|
194
|
+
CREATE INDEX "agent_api_keys_company_agent_idx" ON "agent_api_keys" USING btree ("company_id","agent_id");--> statement-breakpoint
|
|
195
|
+
CREATE INDEX "agents_company_status_idx" ON "agents" USING btree ("company_id","status");--> statement-breakpoint
|
|
196
|
+
CREATE INDEX "agents_company_reports_to_idx" ON "agents" USING btree ("company_id","reports_to");--> statement-breakpoint
|
|
197
|
+
CREATE INDEX "approvals_company_status_type_idx" ON "approvals" USING btree ("company_id","status","type");--> statement-breakpoint
|
|
198
|
+
CREATE INDEX "cost_events_company_occurred_idx" ON "cost_events" USING btree ("company_id","occurred_at");--> statement-breakpoint
|
|
199
|
+
CREATE INDEX "cost_events_company_agent_occurred_idx" ON "cost_events" USING btree ("company_id","agent_id","occurred_at");--> statement-breakpoint
|
|
200
|
+
CREATE INDEX "goals_company_idx" ON "goals" USING btree ("company_id");--> statement-breakpoint
|
|
201
|
+
CREATE INDEX "heartbeat_runs_company_agent_started_idx" ON "heartbeat_runs" USING btree ("company_id","agent_id","started_at");--> statement-breakpoint
|
|
202
|
+
CREATE INDEX "issue_comments_issue_idx" ON "issue_comments" USING btree ("issue_id");--> statement-breakpoint
|
|
203
|
+
CREATE INDEX "issue_comments_company_idx" ON "issue_comments" USING btree ("company_id");--> statement-breakpoint
|
|
204
|
+
CREATE INDEX "issues_company_status_idx" ON "issues" USING btree ("company_id","status");--> statement-breakpoint
|
|
205
|
+
CREATE INDEX "issues_company_assignee_status_idx" ON "issues" USING btree ("company_id","assignee_agent_id","status");--> statement-breakpoint
|
|
206
|
+
CREATE INDEX "issues_company_parent_idx" ON "issues" USING btree ("company_id","parent_id");--> statement-breakpoint
|
|
207
|
+
CREATE INDEX "issues_company_project_idx" ON "issues" USING btree ("company_id","project_id");--> statement-breakpoint
|
|
208
|
+
CREATE INDEX "projects_company_idx" ON "projects" USING btree ("company_id");
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
CREATE TABLE "agent_runtime_state" (
|
|
2
|
+
"agent_id" uuid PRIMARY KEY NOT NULL,
|
|
3
|
+
"company_id" uuid NOT NULL,
|
|
4
|
+
"adapter_type" text NOT NULL,
|
|
5
|
+
"session_id" text,
|
|
6
|
+
"state_json" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
7
|
+
"last_run_id" uuid,
|
|
8
|
+
"last_run_status" text,
|
|
9
|
+
"total_input_tokens" bigint DEFAULT 0 NOT NULL,
|
|
10
|
+
"total_output_tokens" bigint DEFAULT 0 NOT NULL,
|
|
11
|
+
"total_cached_input_tokens" bigint DEFAULT 0 NOT NULL,
|
|
12
|
+
"total_cost_cents" bigint DEFAULT 0 NOT NULL,
|
|
13
|
+
"last_error" text,
|
|
14
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
15
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
16
|
+
);
|
|
17
|
+
--> statement-breakpoint
|
|
18
|
+
CREATE TABLE "agent_wakeup_requests" (
|
|
19
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
20
|
+
"company_id" uuid NOT NULL,
|
|
21
|
+
"agent_id" uuid NOT NULL,
|
|
22
|
+
"source" text NOT NULL,
|
|
23
|
+
"trigger_detail" text,
|
|
24
|
+
"reason" text,
|
|
25
|
+
"payload" jsonb,
|
|
26
|
+
"status" text DEFAULT 'queued' NOT NULL,
|
|
27
|
+
"coalesced_count" integer DEFAULT 0 NOT NULL,
|
|
28
|
+
"requested_by_actor_type" text,
|
|
29
|
+
"requested_by_actor_id" text,
|
|
30
|
+
"idempotency_key" text,
|
|
31
|
+
"run_id" uuid,
|
|
32
|
+
"requested_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
33
|
+
"claimed_at" timestamp with time zone,
|
|
34
|
+
"finished_at" timestamp with time zone,
|
|
35
|
+
"error" text,
|
|
36
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
37
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
38
|
+
);
|
|
39
|
+
--> statement-breakpoint
|
|
40
|
+
CREATE TABLE "heartbeat_run_events" (
|
|
41
|
+
"id" bigserial PRIMARY KEY NOT NULL,
|
|
42
|
+
"company_id" uuid NOT NULL,
|
|
43
|
+
"run_id" uuid NOT NULL,
|
|
44
|
+
"agent_id" uuid NOT NULL,
|
|
45
|
+
"seq" integer NOT NULL,
|
|
46
|
+
"event_type" text NOT NULL,
|
|
47
|
+
"stream" text,
|
|
48
|
+
"level" text,
|
|
49
|
+
"color" text,
|
|
50
|
+
"message" text,
|
|
51
|
+
"payload" jsonb,
|
|
52
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
53
|
+
);
|
|
54
|
+
--> statement-breakpoint
|
|
55
|
+
ALTER TABLE "heartbeat_runs" ALTER COLUMN "invocation_source" SET DEFAULT 'on_demand';--> statement-breakpoint
|
|
56
|
+
ALTER TABLE "agents" ADD COLUMN "runtime_config" jsonb DEFAULT '{}'::jsonb NOT NULL;--> statement-breakpoint
|
|
57
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "trigger_detail" text;--> statement-breakpoint
|
|
58
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "wakeup_request_id" uuid;--> statement-breakpoint
|
|
59
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "exit_code" integer;--> statement-breakpoint
|
|
60
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "signal" text;--> statement-breakpoint
|
|
61
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "usage_json" jsonb;--> statement-breakpoint
|
|
62
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "result_json" jsonb;--> statement-breakpoint
|
|
63
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "session_id_before" text;--> statement-breakpoint
|
|
64
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "session_id_after" text;--> statement-breakpoint
|
|
65
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "log_store" text;--> statement-breakpoint
|
|
66
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "log_ref" text;--> statement-breakpoint
|
|
67
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "log_bytes" bigint;--> statement-breakpoint
|
|
68
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "log_sha256" text;--> statement-breakpoint
|
|
69
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "log_compressed" boolean DEFAULT false NOT NULL;--> statement-breakpoint
|
|
70
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "stdout_excerpt" text;--> statement-breakpoint
|
|
71
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "stderr_excerpt" text;--> statement-breakpoint
|
|
72
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "error_code" text;--> statement-breakpoint
|
|
73
|
+
ALTER TABLE "agent_runtime_state" ADD CONSTRAINT "agent_runtime_state_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
74
|
+
ALTER TABLE "agent_runtime_state" ADD CONSTRAINT "agent_runtime_state_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
75
|
+
ALTER TABLE "agent_wakeup_requests" ADD CONSTRAINT "agent_wakeup_requests_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
76
|
+
ALTER TABLE "agent_wakeup_requests" ADD CONSTRAINT "agent_wakeup_requests_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
77
|
+
ALTER TABLE "heartbeat_run_events" ADD CONSTRAINT "heartbeat_run_events_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
78
|
+
ALTER TABLE "heartbeat_run_events" ADD CONSTRAINT "heartbeat_run_events_run_id_heartbeat_runs_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."heartbeat_runs"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
79
|
+
ALTER TABLE "heartbeat_run_events" ADD CONSTRAINT "heartbeat_run_events_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
80
|
+
CREATE INDEX "agent_runtime_state_company_agent_idx" ON "agent_runtime_state" USING btree ("company_id","agent_id");--> statement-breakpoint
|
|
81
|
+
CREATE INDEX "agent_runtime_state_company_updated_idx" ON "agent_runtime_state" USING btree ("company_id","updated_at");--> statement-breakpoint
|
|
82
|
+
CREATE INDEX "agent_wakeup_requests_company_agent_status_idx" ON "agent_wakeup_requests" USING btree ("company_id","agent_id","status");--> statement-breakpoint
|
|
83
|
+
CREATE INDEX "agent_wakeup_requests_company_requested_idx" ON "agent_wakeup_requests" USING btree ("company_id","requested_at");--> statement-breakpoint
|
|
84
|
+
CREATE INDEX "agent_wakeup_requests_agent_requested_idx" ON "agent_wakeup_requests" USING btree ("agent_id","requested_at");--> statement-breakpoint
|
|
85
|
+
CREATE INDEX "heartbeat_run_events_run_seq_idx" ON "heartbeat_run_events" USING btree ("run_id","seq");--> statement-breakpoint
|
|
86
|
+
CREATE INDEX "heartbeat_run_events_company_run_idx" ON "heartbeat_run_events" USING btree ("company_id","run_id");--> statement-breakpoint
|
|
87
|
+
CREATE INDEX "heartbeat_run_events_company_created_idx" ON "heartbeat_run_events" USING btree ("company_id","created_at");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE "heartbeat_runs" ADD CONSTRAINT "heartbeat_runs_wakeup_request_id_agent_wakeup_requests_id_fk" FOREIGN KEY ("wakeup_request_id") REFERENCES "public"."agent_wakeup_requests"("id") ON DELETE no action ON UPDATE no action;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
ALTER TABLE "activity_log" ADD COLUMN "run_id" uuid;--> statement-breakpoint
|
|
2
|
+
ALTER TABLE "activity_log" ADD CONSTRAINT "activity_log_run_id_heartbeat_runs_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."heartbeat_runs"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
3
|
+
CREATE INDEX "activity_log_run_id_idx" ON "activity_log" USING btree ("run_id");--> statement-breakpoint
|
|
4
|
+
CREATE INDEX "activity_log_entity_type_id_idx" ON "activity_log" USING btree ("entity_type","entity_id");--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "agents" DROP COLUMN "context_mode";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
-- Add issue identifier columns to companies
|
|
2
|
+
ALTER TABLE "companies" ADD COLUMN "issue_prefix" text NOT NULL DEFAULT 'PAP';--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "companies" ADD COLUMN "issue_counter" integer NOT NULL DEFAULT 0;--> statement-breakpoint
|
|
4
|
+
|
|
5
|
+
-- Add issue identifier columns to issues
|
|
6
|
+
ALTER TABLE "issues" ADD COLUMN "issue_number" integer;--> statement-breakpoint
|
|
7
|
+
ALTER TABLE "issues" ADD COLUMN "identifier" text;--> statement-breakpoint
|
|
8
|
+
|
|
9
|
+
-- Backfill existing issues: assign sequential issue_number per company ordered by created_at
|
|
10
|
+
WITH numbered AS (
|
|
11
|
+
SELECT id, company_id, ROW_NUMBER() OVER (PARTITION BY company_id ORDER BY created_at ASC) AS rn
|
|
12
|
+
FROM issues
|
|
13
|
+
)
|
|
14
|
+
UPDATE issues
|
|
15
|
+
SET issue_number = numbered.rn,
|
|
16
|
+
identifier = (SELECT issue_prefix FROM companies WHERE companies.id = issues.company_id) || '-' || numbered.rn
|
|
17
|
+
FROM numbered
|
|
18
|
+
WHERE issues.id = numbered.id;--> statement-breakpoint
|
|
19
|
+
|
|
20
|
+
-- Sync each company's issue_counter to the max assigned number
|
|
21
|
+
UPDATE companies
|
|
22
|
+
SET issue_counter = COALESCE(
|
|
23
|
+
(SELECT MAX(issue_number) FROM issues WHERE issues.company_id = companies.id),
|
|
24
|
+
0
|
|
25
|
+
);--> statement-breakpoint
|
|
26
|
+
|
|
27
|
+
-- Create unique index on (company_id, identifier)
|
|
28
|
+
CREATE UNIQUE INDEX "issues_company_identifier_idx" ON "issues" USING btree ("company_id","identifier");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
CREATE TABLE "approval_comments" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"company_id" uuid NOT NULL,
|
|
4
|
+
"approval_id" uuid NOT NULL,
|
|
5
|
+
"author_agent_id" uuid,
|
|
6
|
+
"author_user_id" text,
|
|
7
|
+
"body" text NOT NULL,
|
|
8
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
9
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
10
|
+
);
|
|
11
|
+
--> statement-breakpoint
|
|
12
|
+
ALTER TABLE "agents" ADD COLUMN "permissions" jsonb DEFAULT '{}'::jsonb NOT NULL;--> statement-breakpoint
|
|
13
|
+
ALTER TABLE "companies" ADD COLUMN "require_board_approval_for_new_agents" boolean DEFAULT true NOT NULL;--> statement-breakpoint
|
|
14
|
+
ALTER TABLE "approval_comments" ADD CONSTRAINT "approval_comments_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
15
|
+
ALTER TABLE "approval_comments" ADD CONSTRAINT "approval_comments_approval_id_approvals_id_fk" FOREIGN KEY ("approval_id") REFERENCES "public"."approvals"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
16
|
+
ALTER TABLE "approval_comments" ADD CONSTRAINT "approval_comments_author_agent_id_agents_id_fk" FOREIGN KEY ("author_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
17
|
+
CREATE INDEX "approval_comments_company_idx" ON "approval_comments" USING btree ("company_id");--> statement-breakpoint
|
|
18
|
+
CREATE INDEX "approval_comments_approval_idx" ON "approval_comments" USING btree ("approval_id");--> statement-breakpoint
|
|
19
|
+
CREATE INDEX "approval_comments_approval_created_idx" ON "approval_comments" USING btree ("approval_id","created_at");--> statement-breakpoint
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
CREATE TABLE "agent_config_revisions" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"company_id" uuid NOT NULL,
|
|
4
|
+
"agent_id" uuid NOT NULL,
|
|
5
|
+
"created_by_agent_id" uuid,
|
|
6
|
+
"created_by_user_id" text,
|
|
7
|
+
"source" text DEFAULT 'patch' NOT NULL,
|
|
8
|
+
"rolled_back_from_revision_id" uuid,
|
|
9
|
+
"changed_keys" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
|
10
|
+
"before_config" jsonb NOT NULL,
|
|
11
|
+
"after_config" jsonb NOT NULL,
|
|
12
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
13
|
+
);
|
|
14
|
+
--> statement-breakpoint
|
|
15
|
+
CREATE TABLE "issue_approvals" (
|
|
16
|
+
"company_id" uuid NOT NULL,
|
|
17
|
+
"issue_id" uuid NOT NULL,
|
|
18
|
+
"approval_id" uuid NOT NULL,
|
|
19
|
+
"linked_by_agent_id" uuid,
|
|
20
|
+
"linked_by_user_id" text,
|
|
21
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
22
|
+
CONSTRAINT "issue_approvals_pk" PRIMARY KEY("issue_id","approval_id")
|
|
23
|
+
);
|
|
24
|
+
--> statement-breakpoint
|
|
25
|
+
ALTER TABLE "agent_config_revisions" ADD CONSTRAINT "agent_config_revisions_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
26
|
+
ALTER TABLE "agent_config_revisions" ADD CONSTRAINT "agent_config_revisions_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
27
|
+
ALTER TABLE "agent_config_revisions" ADD CONSTRAINT "agent_config_revisions_created_by_agent_id_agents_id_fk" FOREIGN KEY ("created_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
28
|
+
ALTER TABLE "issue_approvals" ADD CONSTRAINT "issue_approvals_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
29
|
+
ALTER TABLE "issue_approvals" ADD CONSTRAINT "issue_approvals_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
30
|
+
ALTER TABLE "issue_approvals" ADD CONSTRAINT "issue_approvals_approval_id_approvals_id_fk" FOREIGN KEY ("approval_id") REFERENCES "public"."approvals"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
31
|
+
ALTER TABLE "issue_approvals" ADD CONSTRAINT "issue_approvals_linked_by_agent_id_agents_id_fk" FOREIGN KEY ("linked_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
32
|
+
CREATE INDEX "agent_config_revisions_company_agent_created_idx" ON "agent_config_revisions" USING btree ("company_id","agent_id","created_at");--> statement-breakpoint
|
|
33
|
+
CREATE INDEX "agent_config_revisions_agent_created_idx" ON "agent_config_revisions" USING btree ("agent_id","created_at");--> statement-breakpoint
|
|
34
|
+
CREATE INDEX "issue_approvals_issue_idx" ON "issue_approvals" USING btree ("issue_id");--> statement-breakpoint
|
|
35
|
+
CREATE INDEX "issue_approvals_approval_idx" ON "issue_approvals" USING btree ("approval_id");--> statement-breakpoint
|
|
36
|
+
CREATE INDEX "issue_approvals_company_idx" ON "issue_approvals" USING btree ("company_id");
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
CREATE TABLE "agent_task_sessions" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"company_id" uuid NOT NULL,
|
|
4
|
+
"agent_id" uuid NOT NULL,
|
|
5
|
+
"adapter_type" text NOT NULL,
|
|
6
|
+
"task_key" text NOT NULL,
|
|
7
|
+
"session_params_json" jsonb,
|
|
8
|
+
"session_display_id" text,
|
|
9
|
+
"last_run_id" uuid,
|
|
10
|
+
"last_error" text,
|
|
11
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
12
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
13
|
+
);
|
|
14
|
+
--> statement-breakpoint
|
|
15
|
+
ALTER TABLE "agent_task_sessions" ADD CONSTRAINT "agent_task_sessions_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
16
|
+
ALTER TABLE "agent_task_sessions" ADD CONSTRAINT "agent_task_sessions_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
17
|
+
ALTER TABLE "agent_task_sessions" ADD CONSTRAINT "agent_task_sessions_last_run_id_heartbeat_runs_id_fk" FOREIGN KEY ("last_run_id") REFERENCES "public"."heartbeat_runs"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
18
|
+
CREATE UNIQUE INDEX "agent_task_sessions_company_agent_adapter_task_uniq" ON "agent_task_sessions" USING btree ("company_id","agent_id","adapter_type","task_key");--> statement-breakpoint
|
|
19
|
+
CREATE INDEX "agent_task_sessions_company_agent_updated_idx" ON "agent_task_sessions" USING btree ("company_id","agent_id","updated_at");--> statement-breakpoint
|
|
20
|
+
CREATE INDEX "agent_task_sessions_company_task_updated_idx" ON "agent_task_sessions" USING btree ("company_id","task_key","updated_at");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE "issues" ADD COLUMN "hidden_at" timestamp with time zone;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
CREATE TABLE "company_secret_versions" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"secret_id" uuid NOT NULL,
|
|
4
|
+
"version" integer NOT NULL,
|
|
5
|
+
"material" jsonb NOT NULL,
|
|
6
|
+
"value_sha256" text NOT NULL,
|
|
7
|
+
"created_by_agent_id" uuid,
|
|
8
|
+
"created_by_user_id" text,
|
|
9
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
10
|
+
"revoked_at" timestamp with time zone
|
|
11
|
+
);
|
|
12
|
+
--> statement-breakpoint
|
|
13
|
+
CREATE TABLE "company_secrets" (
|
|
14
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
15
|
+
"company_id" uuid NOT NULL,
|
|
16
|
+
"name" text NOT NULL,
|
|
17
|
+
"provider" text DEFAULT 'local_encrypted' NOT NULL,
|
|
18
|
+
"external_ref" text,
|
|
19
|
+
"latest_version" integer DEFAULT 1 NOT NULL,
|
|
20
|
+
"description" text,
|
|
21
|
+
"created_by_agent_id" uuid,
|
|
22
|
+
"created_by_user_id" text,
|
|
23
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
24
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
25
|
+
);
|
|
26
|
+
--> statement-breakpoint
|
|
27
|
+
ALTER TABLE "company_secret_versions" ADD CONSTRAINT "company_secret_versions_secret_id_company_secrets_id_fk" FOREIGN KEY ("secret_id") REFERENCES "public"."company_secrets"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
28
|
+
ALTER TABLE "company_secret_versions" ADD CONSTRAINT "company_secret_versions_created_by_agent_id_agents_id_fk" FOREIGN KEY ("created_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
29
|
+
ALTER TABLE "company_secrets" ADD CONSTRAINT "company_secrets_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
30
|
+
ALTER TABLE "company_secrets" ADD CONSTRAINT "company_secrets_created_by_agent_id_agents_id_fk" FOREIGN KEY ("created_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
31
|
+
CREATE INDEX "company_secret_versions_secret_idx" ON "company_secret_versions" USING btree ("secret_id","created_at");--> statement-breakpoint
|
|
32
|
+
CREATE INDEX "company_secret_versions_value_sha256_idx" ON "company_secret_versions" USING btree ("value_sha256");--> statement-breakpoint
|
|
33
|
+
CREATE UNIQUE INDEX "company_secret_versions_secret_version_uq" ON "company_secret_versions" USING btree ("secret_id","version");--> statement-breakpoint
|
|
34
|
+
CREATE INDEX "company_secrets_company_idx" ON "company_secrets" USING btree ("company_id");--> statement-breakpoint
|
|
35
|
+
CREATE INDEX "company_secrets_company_provider_idx" ON "company_secrets" USING btree ("company_id","provider");--> statement-breakpoint
|
|
36
|
+
CREATE UNIQUE INDEX "company_secrets_company_name_uq" ON "company_secrets" USING btree ("company_id","name");
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
CREATE TABLE "assets" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"company_id" uuid NOT NULL,
|
|
4
|
+
"provider" text NOT NULL,
|
|
5
|
+
"object_key" text NOT NULL,
|
|
6
|
+
"content_type" text NOT NULL,
|
|
7
|
+
"byte_size" integer NOT NULL,
|
|
8
|
+
"sha256" text NOT NULL,
|
|
9
|
+
"original_filename" text,
|
|
10
|
+
"created_by_agent_id" uuid,
|
|
11
|
+
"created_by_user_id" text,
|
|
12
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
13
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
14
|
+
);
|
|
15
|
+
--> statement-breakpoint
|
|
16
|
+
CREATE TABLE "issue_attachments" (
|
|
17
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
18
|
+
"company_id" uuid NOT NULL,
|
|
19
|
+
"issue_id" uuid NOT NULL,
|
|
20
|
+
"asset_id" uuid NOT NULL,
|
|
21
|
+
"issue_comment_id" uuid,
|
|
22
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
23
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
24
|
+
);
|
|
25
|
+
--> statement-breakpoint
|
|
26
|
+
ALTER TABLE "assets" ADD CONSTRAINT "assets_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
27
|
+
ALTER TABLE "assets" ADD CONSTRAINT "assets_created_by_agent_id_agents_id_fk" FOREIGN KEY ("created_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
28
|
+
ALTER TABLE "issue_attachments" ADD CONSTRAINT "issue_attachments_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
29
|
+
ALTER TABLE "issue_attachments" ADD CONSTRAINT "issue_attachments_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
30
|
+
ALTER TABLE "issue_attachments" ADD CONSTRAINT "issue_attachments_asset_id_assets_id_fk" FOREIGN KEY ("asset_id") REFERENCES "public"."assets"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
31
|
+
ALTER TABLE "issue_attachments" ADD CONSTRAINT "issue_attachments_issue_comment_id_issue_comments_id_fk" FOREIGN KEY ("issue_comment_id") REFERENCES "public"."issue_comments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
32
|
+
CREATE INDEX "assets_company_created_idx" ON "assets" USING btree ("company_id","created_at");--> statement-breakpoint
|
|
33
|
+
CREATE INDEX "assets_company_provider_idx" ON "assets" USING btree ("company_id","provider");--> statement-breakpoint
|
|
34
|
+
CREATE UNIQUE INDEX "assets_company_object_key_uq" ON "assets" USING btree ("company_id","object_key");--> statement-breakpoint
|
|
35
|
+
CREATE INDEX "issue_attachments_company_issue_idx" ON "issue_attachments" USING btree ("company_id","issue_id");--> statement-breakpoint
|
|
36
|
+
CREATE INDEX "issue_attachments_issue_comment_idx" ON "issue_attachments" USING btree ("issue_comment_id");--> statement-breakpoint
|
|
37
|
+
CREATE UNIQUE INDEX "issue_attachments_asset_uq" ON "issue_attachments" USING btree ("asset_id");
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
CREATE TABLE "project_goals" (
|
|
2
|
+
"project_id" uuid NOT NULL,
|
|
3
|
+
"goal_id" uuid NOT NULL,
|
|
4
|
+
"company_id" uuid NOT NULL,
|
|
5
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
6
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
7
|
+
CONSTRAINT "project_goals_project_id_goal_id_pk" PRIMARY KEY("project_id","goal_id")
|
|
8
|
+
);
|
|
9
|
+
--> statement-breakpoint
|
|
10
|
+
ALTER TABLE "project_goals" ADD CONSTRAINT "project_goals_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
11
|
+
ALTER TABLE "project_goals" ADD CONSTRAINT "project_goals_goal_id_goals_id_fk" FOREIGN KEY ("goal_id") REFERENCES "public"."goals"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
12
|
+
ALTER TABLE "project_goals" ADD CONSTRAINT "project_goals_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
13
|
+
CREATE INDEX "project_goals_project_idx" ON "project_goals" USING btree ("project_id");--> statement-breakpoint
|
|
14
|
+
CREATE INDEX "project_goals_goal_idx" ON "project_goals" USING btree ("goal_id");--> statement-breakpoint
|
|
15
|
+
CREATE INDEX "project_goals_company_idx" ON "project_goals" USING btree ("company_id");--> statement-breakpoint
|
|
16
|
+
INSERT INTO "project_goals" ("project_id", "goal_id", "company_id")
|
|
17
|
+
SELECT "id", "goal_id", "company_id" FROM "projects" WHERE "goal_id" IS NOT NULL
|
|
18
|
+
ON CONFLICT DO NOTHING;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
ALTER TABLE "issues" ADD COLUMN "checkout_run_id" uuid;--> statement-breakpoint
|
|
2
|
+
ALTER TABLE "issues" ADD CONSTRAINT "issues_checkout_run_id_heartbeat_runs_id_fk" FOREIGN KEY ("checkout_run_id") REFERENCES "public"."heartbeat_runs"("id") ON DELETE set null ON UPDATE no action;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
ALTER TABLE "issues" ADD COLUMN "execution_run_id" uuid;--> statement-breakpoint
|
|
2
|
+
ALTER TABLE "issues" ADD COLUMN "execution_agent_name_key" text;--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "issues" ADD COLUMN "execution_locked_at" timestamp with time zone;--> statement-breakpoint
|
|
4
|
+
ALTER TABLE "issues" ADD CONSTRAINT "issues_execution_run_id_heartbeat_runs_id_fk" FOREIGN KEY ("execution_run_id") REFERENCES "public"."heartbeat_runs"("id") ON DELETE set null ON UPDATE no action;
|