@intx/db 0.1.2 → 0.3.0
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/LICENSE +176 -0
- package/README.md +23 -4
- package/dist/approval-store.d.ts +52 -0
- package/dist/approval-store.js +79 -0
- package/dist/asset-resolution.d.ts +52 -0
- package/dist/asset-resolution.js +66 -0
- package/dist/catalog-resolution.d.ts +76 -0
- package/dist/catalog-resolution.js +151 -0
- package/dist/client.d.ts +19 -0
- package/dist/client.js +18 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.js +16 -0
- package/dist/connection.d.ts +3 -0
- package/dist/connection.js +26 -0
- package/dist/credential-resolution.d.ts +222 -0
- package/dist/credential-resolution.js +255 -0
- package/dist/grant-store.d.ts +3 -0
- package/dist/grant-store.js +59 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +20 -0
- package/dist/migrate.d.ts +36 -0
- package/dist/migrate.js +135 -0
- package/dist/model-source-resolution.d.ts +115 -0
- package/dist/model-source-resolution.js +291 -0
- package/dist/parse-row.d.ts +373 -0
- package/dist/parse-row.js +232 -0
- package/dist/pg-error.d.ts +3 -0
- package/dist/pg-error.js +19 -0
- package/dist/pricing.d.ts +15 -0
- package/dist/pricing.js +24 -0
- package/dist/rekey-credential-secrets.d.ts +13 -0
- package/dist/rekey-credential-secrets.js +61 -0
- package/dist/schema/approvals.d.ts +245 -0
- package/dist/schema/approvals.js +52 -0
- package/dist/schema/assets.d.ts +143 -0
- package/{src/schema/assets.ts → dist/schema/assets.js} +7 -16
- package/dist/schema/auth.d.ts +606 -0
- package/dist/schema/auth.js +47 -0
- package/dist/schema/catalog.d.ts +811 -0
- package/dist/schema/catalog.js +108 -0
- package/dist/schema/column-types.d.ts +26 -0
- package/dist/schema/column-types.js +15 -0
- package/dist/schema/credentials.d.ts +305 -0
- package/{src/schema/credentials.ts → dist/schema/credentials.js} +16 -22
- package/dist/schema/git-tokens.d.ts +256 -0
- package/{src/schema/git-tokens.ts → dist/schema/git-tokens.js} +16 -39
- package/dist/schema/grants.d.ts +211 -0
- package/dist/schema/grants.js +30 -0
- package/dist/schema/index.d.ts +25 -0
- package/dist/schema/index.js +25 -0
- package/dist/schema/messages.d.ts +414 -0
- package/dist/schema/messages.js +82 -0
- package/dist/schema/oauth-clients.d.ts +246 -0
- package/{src/schema/oauth-clients.ts → dist/schema/oauth-clients.js} +8 -14
- package/dist/schema/offerings.d.ts +160 -0
- package/dist/schema/offerings.js +24 -0
- package/dist/schema/principals.d.ts +128 -0
- package/dist/schema/principals.js +23 -0
- package/dist/schema/providers.d.ts +237 -0
- package/dist/schema/providers.js +22 -0
- package/dist/schema/roles.d.ts +242 -0
- package/dist/schema/roles.js +37 -0
- package/dist/schema/session-assets.d.ts +92 -0
- package/dist/schema/session-assets.js +45 -0
- package/dist/schema/sessions.d.ts +143 -0
- package/dist/schema/sessions.js +29 -0
- package/dist/schema/sidecar-allocation.d.ts +406 -0
- package/dist/schema/sidecar-allocation.js +57 -0
- package/dist/schema/sidecar.d.ts +145 -0
- package/dist/schema/sidecar.js +28 -0
- package/dist/schema/signal-correlations.d.ts +177 -0
- package/dist/schema/signal-correlations.js +31 -0
- package/dist/schema/tenants.d.ts +235 -0
- package/{src/schema/tenants.ts → dist/schema/tenants.js} +10 -27
- package/dist/schema/wallets.d.ts +354 -0
- package/dist/schema/wallets.js +43 -0
- package/dist/schema/workflow-definitions.d.ts +371 -0
- package/dist/schema/workflow-definitions.js +97 -0
- package/dist/schema/workflow-run-dispatch.d.ts +328 -0
- package/dist/schema/workflow-run-dispatch.js +56 -0
- package/dist/schema/workflow-run-execution.d.ts +126 -0
- package/dist/schema/workflow-run-execution.js +48 -0
- package/dist/schema/workflow-run-launch-spec.d.ts +200 -0
- package/dist/schema/workflow-run-launch-spec.js +26 -0
- package/dist/schema/workflow-run.d.ts +230 -0
- package/dist/schema/workflow-run.js +102 -0
- package/dist/sidecar-allocation-store.d.ts +171 -0
- package/dist/sidecar-allocation-store.js +512 -0
- package/dist/signal-correlation-store.d.ts +36 -0
- package/dist/signal-correlation-store.js +63 -0
- package/dist/tenant-hierarchy.d.ts +23 -0
- package/dist/tenant-hierarchy.js +60 -0
- package/dist/workflow-definition-store.d.ts +55 -0
- package/dist/workflow-definition-store.js +93 -0
- package/dist/workflow-run-dispatch-store.d.ts +80 -0
- package/dist/workflow-run-dispatch-store.js +298 -0
- package/dist/workflow-run-launch-spec-store.d.ts +13 -0
- package/dist/workflow-run-launch-spec-store.js +30 -0
- package/dist/workflow-run-store.d.ts +54 -0
- package/dist/workflow-run-store.js +85 -0
- package/migrations/0029_loose_warlock.sql +1 -0
- package/migrations/0030_session_asset_audit_split.sql +5 -0
- package/migrations/0031_gigantic_nicolaos.sql +68 -0
- package/migrations/0032_lethal_misty_knight.sql +1 -0
- package/migrations/0033_old_payback.sql +1 -0
- package/migrations/0034_sleepy_songbird.sql +11 -0
- package/migrations/0035_violet_giant_man.sql +3 -0
- package/migrations/0036_sharp_the_executioner.sql +2 -0
- package/migrations/0037_credential_use_backfill.sql +39 -0
- package/migrations/0038_chilly_blacklash.sql +37 -0
- package/migrations/0039_quick_carnage.sql +2 -0
- package/migrations/0040_reshape_approval_origin.sql +24 -0
- package/migrations/0041_make_approval_timeout_at_nullable.sql +1 -0
- package/migrations/0042_youthful_mantis.sql +2 -0
- package/migrations/0043_signal_correlation_deployment_fk.sql +1 -0
- package/migrations/0044_model_offering_quirks.sql +1 -0
- package/migrations/0045_create_workflow_run.sql +13 -0
- package/migrations/0046_approval_signal_correlation_run_fk.sql +2 -0
- package/migrations/0047_create_workflow_definition.sql +30 -0
- package/migrations/0048_workflow_definition_origin_agent_id.sql +2 -0
- package/migrations/0049_curly_omega_flight.sql +2 -0
- package/migrations/0050_late_crystal.sql +10 -0
- package/migrations/0051_funny_madelyne_pryor.sql +1 -0
- package/migrations/0052_drop_inference_turn_instance_fk.sql +1 -0
- package/migrations/0053_session_mail_session_id_index.sql +1 -0
- package/migrations/0054_rekey_instance_grants_to_workflow_run.sql +10 -0
- package/migrations/0055_backfill_anchor_workflow_runs.sql +69 -0
- package/migrations/0056_repoint_deployment_fks_to_anchor_run.sql +32 -0
- package/migrations/0057_drop_workflow_deployment_projection.sql +22 -0
- package/migrations/0058_repoint_offering_fk_to_definition.sql +41 -0
- package/migrations/0059_repoint_transaction_fk_to_run.sql +10 -0
- package/migrations/0060_drop_session_mail_instance_fk.sql +6 -0
- package/migrations/0061_drop_session_asset_instance_fk.sql +7 -0
- package/migrations/0062_drop_agent_asset_table.sql +11 -0
- package/migrations/0063_repoint_agent_role_fk_to_definition.sql +39 -0
- package/migrations/0064_repoint_agent_session_fk_to_definition.sql +47 -0
- package/migrations/0065_add_workflow_definition_model_requirements.sql +37 -0
- package/migrations/0066_rekey_agent_definition_principals_to_workflow.sql +27 -0
- package/migrations/0067_add_workflow_definition_kind.sql +10 -0
- package/migrations/0068_drop_agent_tables_and_origin_agent_id.sql +31 -0
- package/migrations/0069_drop_workflow_definition_kind.sql +10 -0
- package/migrations/0070_flashy_proteus.sql +13 -0
- package/migrations/0072_add_workflow_definition_credential_bindings.sql +1 -0
- package/migrations/0073_grant_target_exactly_one_check.sql +13 -0
- package/migrations/0074_add_provider_api_base_url.sql +1 -0
- package/migrations/0075_workflow_run_launch_spec.sql +17 -0
- package/migrations/0076_sidecar_allocation.sql +40 -0
- package/migrations/0077_workflow_run_dispatch.sql +29 -0
- package/migrations/0078_workflow_run_dispatch_kind.sql +2 -0
- package/migrations/0079_rename_workflow_run_deployment_id_to_anchor_run_id.sql +4 -0
- package/migrations/0080_rename_correlation_approval_deployment_id_to_anchor_run_id.sql +9 -0
- package/migrations/0081_workflow_definition_content_hash_and_approved_wire_hash.sql +4 -0
- package/migrations/0082_blue_black_queen.sql +1 -0
- package/migrations/0083_replace_launch_spec_snapshot_with_frozen_bundle.sql +3 -0
- package/migrations/0084_delete_orphaned_credential_grants.sql +22 -0
- package/migrations/meta/0029_snapshot.json +2664 -0
- package/migrations/meta/0030_snapshot.json +2670 -0
- package/migrations/meta/0031_snapshot.json +3100 -0
- package/migrations/meta/0032_snapshot.json +3106 -0
- package/migrations/meta/0033_snapshot.json +3112 -0
- package/migrations/meta/0034_snapshot.json +3198 -0
- package/migrations/meta/0035_snapshot.json +3225 -0
- package/migrations/meta/0036_snapshot.json +3237 -0
- package/migrations/meta/0037_snapshot.json +3237 -0
- package/migrations/meta/0038_snapshot.json +3470 -0
- package/migrations/meta/0039_snapshot.json +3470 -0
- package/migrations/meta/0040_snapshot.json +3489 -0
- package/migrations/meta/0041_snapshot.json +3489 -0
- package/migrations/meta/0042_snapshot.json +3489 -0
- package/migrations/meta/0043_snapshot.json +3498 -0
- package/migrations/meta/0044_snapshot.json +3504 -0
- package/migrations/meta/0045_snapshot.json +3589 -0
- package/migrations/meta/0046_snapshot.json +3607 -0
- package/migrations/meta/0047_snapshot.json +3832 -0
- package/migrations/meta/0048_snapshot.json +3853 -0
- package/migrations/meta/0049_snapshot.json +3854 -0
- package/migrations/meta/0050_snapshot.json +3924 -0
- package/migrations/meta/0051_snapshot.json +3940 -0
- package/migrations/meta/0052_snapshot.json +3931 -0
- package/migrations/meta/0053_snapshot.json +3952 -0
- package/migrations/meta/0054_snapshot.json +3952 -0
- package/migrations/meta/0055_snapshot.json +3952 -0
- package/migrations/meta/0056_snapshot.json +3952 -0
- package/migrations/meta/0057_snapshot.json +3839 -0
- package/migrations/meta/0058_snapshot.json +3839 -0
- package/migrations/meta/0059_snapshot.json +3839 -0
- package/migrations/meta/0060_snapshot.json +3830 -0
- package/migrations/meta/0061_snapshot.json +3821 -0
- package/migrations/meta/0062_snapshot.json +3723 -0
- package/migrations/meta/0063_snapshot.json +3723 -0
- package/migrations/meta/0064_snapshot.json +3723 -0
- package/migrations/meta/0065_snapshot.json +3729 -0
- package/migrations/meta/0066_snapshot.json +3729 -0
- package/migrations/meta/0067_snapshot.json +3736 -0
- package/migrations/meta/0068_snapshot.json +3347 -0
- package/migrations/meta/0069_snapshot.json +3340 -0
- package/migrations/meta/0070_snapshot.json +3444 -0
- package/migrations/meta/0072_snapshot.json +3450 -0
- package/migrations/meta/0073_snapshot.json +3455 -0
- package/migrations/meta/0074_snapshot.json +3461 -0
- package/migrations/meta/0075_snapshot.json +3567 -0
- package/migrations/meta/0076_snapshot.json +3851 -0
- package/migrations/meta/0077_snapshot.json +4067 -0
- package/migrations/meta/0078_snapshot.json +4078 -0
- package/migrations/meta/0079_snapshot.json +4078 -0
- package/migrations/meta/0080_snapshot.json +4078 -0
- package/migrations/meta/0081_snapshot.json +4096 -0
- package/migrations/meta/0082_snapshot.json +4102 -0
- package/migrations/meta/0083_snapshot.json +4096 -0
- package/migrations/meta/0084_snapshot.json +4096 -0
- package/migrations/meta/_journal.json +385 -0
- package/package.json +25 -11
- package/drizzle.config.ts +0 -23
- package/src/client.ts +0 -24
- package/src/config.ts +0 -19
- package/src/connection.ts +0 -27
- package/src/credential-resolution.ts +0 -378
- package/src/grant-store.ts +0 -51
- package/src/index.ts +0 -32
- package/src/migrate.test.ts +0 -35
- package/src/migrate.ts +0 -168
- package/src/parse-row.test.ts +0 -113
- package/src/parse-row.ts +0 -185
- package/src/schema/agent-assets.ts +0 -21
- package/src/schema/agents.ts +0 -49
- package/src/schema/auth.ts +0 -51
- package/src/schema/grants.ts +0 -26
- package/src/schema/index.ts +0 -19
- package/src/schema/instances.ts +0 -36
- package/src/schema/messages.ts +0 -108
- package/src/schema/offerings.ts +0 -20
- package/src/schema/principals.ts +0 -28
- package/src/schema/providers.ts +0 -23
- package/src/schema/roles.ts +0 -51
- package/src/schema/session-assets.ts +0 -49
- package/src/schema/sessions.ts +0 -26
- package/src/schema/sidecar.ts +0 -14
- package/src/schema/wallets.ts +0 -44
- package/src/tenant-hierarchy.ts +0 -34
- package/tsconfig.json +0 -4
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
CREATE TABLE "approval" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"tenant_id" text NOT NULL,
|
|
4
|
+
"instance_id" text NOT NULL,
|
|
5
|
+
"agent_id" text NOT NULL,
|
|
6
|
+
"origin_principal_id" text NOT NULL,
|
|
7
|
+
"correlation_id" text NOT NULL,
|
|
8
|
+
"tool_definition" jsonb NOT NULL,
|
|
9
|
+
"tool_arguments" jsonb NOT NULL,
|
|
10
|
+
"scope" text,
|
|
11
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
12
|
+
"origin_kind" text NOT NULL,
|
|
13
|
+
"timeout_at" timestamp NOT NULL,
|
|
14
|
+
"resolved_at" timestamp,
|
|
15
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
16
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
17
|
+
CONSTRAINT "approval_correlation_id_unique" UNIQUE("correlation_id")
|
|
18
|
+
);
|
|
19
|
+
--> statement-breakpoint
|
|
20
|
+
CREATE TABLE "signal_correlation" (
|
|
21
|
+
"correlation_id" text PRIMARY KEY NOT NULL,
|
|
22
|
+
"tenant_id" text NOT NULL,
|
|
23
|
+
"deployment_id" text NOT NULL,
|
|
24
|
+
"agent_address" text NOT NULL,
|
|
25
|
+
"run_id" text NOT NULL,
|
|
26
|
+
"signal_name" text NOT NULL,
|
|
27
|
+
"kind" text NOT NULL,
|
|
28
|
+
"signal_id" text,
|
|
29
|
+
"resolved_at" timestamp,
|
|
30
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
31
|
+
);
|
|
32
|
+
--> statement-breakpoint
|
|
33
|
+
ALTER TABLE "approval" ADD CONSTRAINT "approval_tenant_id_tenant_id_fk" FOREIGN KEY ("tenant_id") REFERENCES "public"."tenant"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
34
|
+
ALTER TABLE "approval" ADD CONSTRAINT "approval_instance_id_agent_instance_id_fk" FOREIGN KEY ("instance_id") REFERENCES "public"."agent_instance"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
35
|
+
ALTER TABLE "approval" ADD CONSTRAINT "approval_agent_id_agent_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agent"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
36
|
+
ALTER TABLE "approval" ADD CONSTRAINT "approval_origin_principal_id_principal_id_fk" FOREIGN KEY ("origin_principal_id") REFERENCES "public"."principal"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
37
|
+
ALTER TABLE "signal_correlation" ADD CONSTRAINT "signal_correlation_tenant_id_tenant_id_fk" FOREIGN KEY ("tenant_id") REFERENCES "public"."tenant"("id") ON DELETE cascade ON UPDATE no action;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
-- Reshape `approval` so its origin is the workflow deployment it came from.
|
|
2
|
+
-- The dropped instance/agent/origin-principal FKs had no valid referent: a
|
|
3
|
+
-- workflow deployment has no agent_instance/agent row and its run principal is
|
|
4
|
+
-- a substrate principal, not a `principal`-table row. The three added columns
|
|
5
|
+
-- are NOT NULL with no default and no backfill; like the repo's other such
|
|
6
|
+
-- adds (e.g. 0014, `workflow_deployment.address`), this relies on the table
|
|
7
|
+
-- being empty when the migration runs. The table is unreleased -- the approval
|
|
8
|
+
-- routes are 501 stubs -- so no populated row predates these columns.
|
|
9
|
+
ALTER TABLE "approval" DROP CONSTRAINT "approval_instance_id_agent_instance_id_fk";
|
|
10
|
+
--> statement-breakpoint
|
|
11
|
+
ALTER TABLE "approval" DROP CONSTRAINT "approval_agent_id_agent_id_fk";
|
|
12
|
+
--> statement-breakpoint
|
|
13
|
+
ALTER TABLE "approval" DROP CONSTRAINT "approval_origin_principal_id_principal_id_fk";
|
|
14
|
+
--> statement-breakpoint
|
|
15
|
+
ALTER TABLE "approval" ADD COLUMN "deployment_id" text NOT NULL;--> statement-breakpoint
|
|
16
|
+
ALTER TABLE "approval" ADD COLUMN "run_id" text NOT NULL;--> statement-breakpoint
|
|
17
|
+
ALTER TABLE "approval" ADD COLUMN "agent_address" text NOT NULL;--> statement-breakpoint
|
|
18
|
+
ALTER TABLE "approval" ADD CONSTRAINT "approval_deployment_id_workflow_deployment_id_fk" FOREIGN KEY ("deployment_id") REFERENCES "public"."workflow_deployment"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
19
|
+
CREATE INDEX "approval_tenant_status_idx" ON "approval" USING btree ("tenant_id","status","created_at");--> statement-breakpoint
|
|
20
|
+
CREATE INDEX "approval_deployment_idx" ON "approval" USING btree ("deployment_id");--> statement-breakpoint
|
|
21
|
+
ALTER TABLE "approval" DROP COLUMN "instance_id";--> statement-breakpoint
|
|
22
|
+
ALTER TABLE "approval" DROP COLUMN "agent_id";--> statement-breakpoint
|
|
23
|
+
ALTER TABLE "approval" DROP COLUMN "origin_principal_id";--> statement-breakpoint
|
|
24
|
+
ALTER TABLE "approval" DROP COLUMN "origin_kind";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE "approval" ALTER COLUMN "timeout_at" DROP NOT NULL;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE "signal_correlation" ADD CONSTRAINT "signal_correlation_deployment_id_workflow_deployment_id_fk" FOREIGN KEY ("deployment_id") REFERENCES "public"."workflow_deployment"("id") ON DELETE cascade ON UPDATE no action;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE "model_offering" ADD COLUMN "quirks" jsonb;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
CREATE TABLE "workflow_run" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"deployment_id" text NOT NULL,
|
|
4
|
+
"tenant_id" text NOT NULL,
|
|
5
|
+
"principal_id" text,
|
|
6
|
+
"status" text DEFAULT 'running' NOT NULL,
|
|
7
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
8
|
+
"ended_at" timestamp
|
|
9
|
+
);
|
|
10
|
+
--> statement-breakpoint
|
|
11
|
+
ALTER TABLE "workflow_run" ADD CONSTRAINT "workflow_run_deployment_id_workflow_deployment_id_fk" FOREIGN KEY ("deployment_id") REFERENCES "public"."workflow_deployment"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
12
|
+
ALTER TABLE "workflow_run" ADD CONSTRAINT "workflow_run_tenant_id_tenant_id_fk" FOREIGN KEY ("tenant_id") REFERENCES "public"."tenant"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
13
|
+
ALTER TABLE "workflow_run" ADD CONSTRAINT "workflow_run_principal_id_principal_id_fk" FOREIGN KEY ("principal_id") REFERENCES "public"."principal"("id") ON DELETE set null ON UPDATE no action;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
ALTER TABLE "approval" ADD CONSTRAINT "approval_run_id_workflow_run_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."workflow_run"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
2
|
+
ALTER TABLE "signal_correlation" ADD CONSTRAINT "signal_correlation_run_id_workflow_run_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."workflow_run"("id") ON DELETE cascade ON UPDATE no action;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
CREATE TABLE "workflow_definition" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"tenant_id" text NOT NULL,
|
|
4
|
+
"creator_principal_id" text,
|
|
5
|
+
"asset_id" text,
|
|
6
|
+
"name" text NOT NULL,
|
|
7
|
+
"description" text,
|
|
8
|
+
"grant_requirements" jsonb,
|
|
9
|
+
"current_version" text DEFAULT '1' NOT NULL,
|
|
10
|
+
"status" text DEFAULT 'deployed' NOT NULL,
|
|
11
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
12
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
13
|
+
);
|
|
14
|
+
--> statement-breakpoint
|
|
15
|
+
CREATE TABLE "workflow_definition_version" (
|
|
16
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
17
|
+
"definition_id" text NOT NULL,
|
|
18
|
+
"version" text NOT NULL,
|
|
19
|
+
"status" text DEFAULT 'active' NOT NULL,
|
|
20
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
21
|
+
CONSTRAINT "workflow_definition_version_definition_version" UNIQUE("definition_id","version")
|
|
22
|
+
);
|
|
23
|
+
--> statement-breakpoint
|
|
24
|
+
ALTER TABLE "workflow_definition" ADD CONSTRAINT "workflow_definition_tenant_id_tenant_id_fk" FOREIGN KEY ("tenant_id") REFERENCES "public"."tenant"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
25
|
+
ALTER TABLE "workflow_definition" ADD CONSTRAINT "workflow_definition_creator_principal_id_principal_id_fk" FOREIGN KEY ("creator_principal_id") REFERENCES "public"."principal"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
26
|
+
ALTER TABLE "workflow_definition" ADD CONSTRAINT "workflow_definition_asset_id_asset_id_fk" FOREIGN KEY ("asset_id") REFERENCES "public"."asset"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
|
|
27
|
+
ALTER TABLE "workflow_definition_version" ADD CONSTRAINT "workflow_definition_version_definition_id_workflow_definition_id_fk" FOREIGN KEY ("definition_id") REFERENCES "public"."workflow_definition"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
28
|
+
CREATE INDEX "workflow_definition_tenant_idx" ON "workflow_definition" USING btree ("tenant_id","created_at");--> statement-breakpoint
|
|
29
|
+
CREATE UNIQUE INDEX "workflow_definition_asset_idx" ON "workflow_definition" USING btree ("asset_id");--> statement-breakpoint
|
|
30
|
+
CREATE INDEX "workflow_definition_version_definition_idx" ON "workflow_definition_version" USING btree ("definition_id");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
ALTER TABLE "workflow_run" ALTER COLUMN "deployment_id" DROP NOT NULL;--> statement-breakpoint
|
|
2
|
+
ALTER TABLE "workflow_run" ADD COLUMN "definition_id" text;--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "workflow_run" ADD COLUMN "address" text;--> statement-breakpoint
|
|
4
|
+
ALTER TABLE "workflow_run" ADD COLUMN "public_key" text;--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "workflow_run" ADD COLUMN "sidecar_id" text;--> statement-breakpoint
|
|
6
|
+
ALTER TABLE "workflow_run" ADD COLUMN "kernel_id" text;--> statement-breakpoint
|
|
7
|
+
ALTER TABLE "workflow_run" ADD COLUMN "model_preferences" jsonb;--> statement-breakpoint
|
|
8
|
+
ALTER TABLE "workflow_run" ADD CONSTRAINT "workflow_run_definition_id_workflow_definition_id_fk" FOREIGN KEY ("definition_id") REFERENCES "public"."workflow_definition"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
9
|
+
ALTER TABLE "workflow_run" ADD CONSTRAINT "workflow_run_sidecar_id_sidecar_id_fk" FOREIGN KEY ("sidecar_id") REFERENCES "public"."sidecar"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
10
|
+
CREATE INDEX "workflow_run_definition_idx" ON "workflow_run" USING btree ("definition_id");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
CREATE UNIQUE INDEX "workflow_run_address_idx" ON "workflow_run" USING btree ("address") WHERE "workflow_run"."address" is not null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE "inference_turn" DROP CONSTRAINT "inference_turn_instance_id_agent_instance_id_fk";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
CREATE INDEX "session_mail_session_id_created_at_idx" ON "session_mail" USING btree ("session_id","created_at");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- Re-key run-scoped grants onto the folded workflow-run resource. A folded run
|
|
2
|
+
-- shares the instance id space, so the rewrite is prefix-identity: the id after
|
|
3
|
+
-- the colon is unchanged, only the type name moves instance: -> workflow-run:
|
|
4
|
+
-- (carrying instance:* -> workflow-run:* too). The match is colon-delimited so
|
|
5
|
+
-- it never touches the unrelated agent-state: grants; there is no instance-state
|
|
6
|
+
-- sibling. Idempotent: after this runs no row matches instance:%, so a re-run is
|
|
7
|
+
-- a no-op.
|
|
8
|
+
UPDATE "grant"
|
|
9
|
+
SET resource = 'workflow-run:' || substr(resource, length('instance:') + 1)
|
|
10
|
+
WHERE resource LIKE 'instance:%';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
-- Reconstruct an anchor workflow_run for every deployment that predates the
|
|
2
|
+
-- runtime anchor insert. A deployment's routing address and reconnect key now
|
|
3
|
+
-- live on its anchor run (the workflow_run whose id equals the deployment id),
|
|
4
|
+
-- which new deploys create at runtime -- but deployments created earlier have a
|
|
5
|
+
-- workflow_deployment row and no anchor run, so the reconnect key lookup finds
|
|
6
|
+
-- no run for their address and their reconnect challenge fails closed. This
|
|
7
|
+
-- copies the deployment's identity onto a fresh anchor run so those deployments
|
|
8
|
+
-- reconnect exactly as ones deployed after the runtime anchor insert do.
|
|
9
|
+
--
|
|
10
|
+
-- A runtime-created anchor run also carries its definition -- deploy resolves
|
|
11
|
+
-- and writes definition_id -- so a reconstructed one must too; an anchor run
|
|
12
|
+
-- without a definition is only half the deployment's first-class stand-in. A
|
|
13
|
+
-- definition_id resolves from the deployment's asset, which the workflow-asset
|
|
14
|
+
-- fold populates. The guard below aborts the migration before it writes
|
|
15
|
+
-- anything if any deployment still needing an anchor run has no folded
|
|
16
|
+
-- definition, so the backfill reconstructs every anchor run completely or
|
|
17
|
+
-- writes nothing and tells the operator to run the fold first. The production
|
|
18
|
+
-- path applies migrations under `drizzle-kit migrate`, which wraps the pending
|
|
19
|
+
-- set in a transaction, and PostgreSQL DDL is transactional, so an aborting
|
|
20
|
+
-- guard rolls the whole set back -- there is no partial commit to re-run from
|
|
21
|
+
-- the top, so the guard is simply a clear up-front precondition.
|
|
22
|
+
DO $$
|
|
23
|
+
BEGIN
|
|
24
|
+
IF EXISTS (
|
|
25
|
+
SELECT 1
|
|
26
|
+
FROM "workflow_deployment" wd
|
|
27
|
+
WHERE NOT EXISTS (
|
|
28
|
+
SELECT 1 FROM "workflow_run" r WHERE r.id = wd.id
|
|
29
|
+
)
|
|
30
|
+
AND NOT EXISTS (
|
|
31
|
+
SELECT 1 FROM "workflow_definition" wdef
|
|
32
|
+
WHERE wdef.asset_id = wd.definition_asset_id
|
|
33
|
+
)
|
|
34
|
+
) THEN
|
|
35
|
+
RAISE EXCEPTION 'workflow-asset fold has not run: a deployment lacks a folded definition and its anchor run would be definition-less. The fold tooling has been retired; create the missing workflow_definition for the deployment asset by hand before applying this migration (see the agent-fold migration note in DEV.md).';
|
|
36
|
+
END IF;
|
|
37
|
+
END $$;
|
|
38
|
+
--> statement-breakpoint
|
|
39
|
+
-- public_key is copied from the deployment (its old deploy-ack key) so the
|
|
40
|
+
-- reconnect challenge resolves the same key it did before; created_at is copied
|
|
41
|
+
-- so listing order is stable; status is the anchor's live value; definition_id
|
|
42
|
+
-- resolves through the folded definition the guard above proved present. The
|
|
43
|
+
-- remaining columns match a runtime anchor insert: no principal, no runtime
|
|
44
|
+
-- bindings, not ended. NOT EXISTS on the id keeps it idempotent and skips
|
|
45
|
+
-- deployments that already have a runtime-created anchor run.
|
|
46
|
+
INSERT INTO "workflow_run" (
|
|
47
|
+
id,
|
|
48
|
+
tenant_id,
|
|
49
|
+
deployment_id,
|
|
50
|
+
definition_id,
|
|
51
|
+
address,
|
|
52
|
+
public_key,
|
|
53
|
+
status,
|
|
54
|
+
created_at
|
|
55
|
+
)
|
|
56
|
+
SELECT
|
|
57
|
+
wd.id,
|
|
58
|
+
wd.tenant_id,
|
|
59
|
+
wd.id,
|
|
60
|
+
wdef.id,
|
|
61
|
+
wd.address,
|
|
62
|
+
wd.public_key,
|
|
63
|
+
'running',
|
|
64
|
+
wd.created_at
|
|
65
|
+
FROM "workflow_deployment" wd
|
|
66
|
+
LEFT JOIN "workflow_definition" wdef ON wdef.asset_id = wd.definition_asset_id
|
|
67
|
+
WHERE NOT EXISTS (
|
|
68
|
+
SELECT 1 FROM "workflow_run" r WHERE r.id = wd.id
|
|
69
|
+
);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
-- Re-point the three deployment_id foreign keys from the workflow_deployment
|
|
2
|
+
-- projection onto the anchor run -- the workflow_run whose id equals the
|
|
3
|
+
-- deployment id -- leaving the projection unreferenced. Every deployment_id
|
|
4
|
+
-- value already equals an anchor run's id (migration 0055 backfilled one per
|
|
5
|
+
-- deployment), so each re-pointed constraint validates on add; a deployment
|
|
6
|
+
-- that somehow lacks its anchor run makes the ADD CONSTRAINT abort, a free
|
|
7
|
+
-- integrity check.
|
|
8
|
+
--
|
|
9
|
+
-- First, fill definition_id on the runs the projection still anchors, so every
|
|
10
|
+
-- run carries its definition -- the run anchors on the definition, not the
|
|
11
|
+
-- deployment. A pre-existing non-anchor run -- a folded or child run created
|
|
12
|
+
-- before this branch added the column -- has a null definition_id that only the
|
|
13
|
+
-- deployment -> asset -> definition join can resolve; migration 0055 fills the
|
|
14
|
+
-- anchor runs it inserts but never touches these existing rows, and
|
|
15
|
+
-- workflow_deployment is the only place their mapping survives. asset_id is
|
|
16
|
+
-- unique per definition, so the join matches at most one definition per run.
|
|
17
|
+
UPDATE "workflow_run" r
|
|
18
|
+
SET definition_id = wdef.id
|
|
19
|
+
FROM "workflow_deployment" wd
|
|
20
|
+
JOIN "workflow_definition" wdef ON wdef.asset_id = wd.definition_asset_id
|
|
21
|
+
WHERE r.deployment_id = wd.id
|
|
22
|
+
AND r.definition_id IS NULL;
|
|
23
|
+
--> statement-breakpoint
|
|
24
|
+
ALTER TABLE "approval" DROP CONSTRAINT "approval_deployment_id_workflow_deployment_id_fk";
|
|
25
|
+
--> statement-breakpoint
|
|
26
|
+
ALTER TABLE "signal_correlation" DROP CONSTRAINT "signal_correlation_deployment_id_workflow_deployment_id_fk";
|
|
27
|
+
--> statement-breakpoint
|
|
28
|
+
ALTER TABLE "workflow_run" DROP CONSTRAINT "workflow_run_deployment_id_workflow_deployment_id_fk";
|
|
29
|
+
--> statement-breakpoint
|
|
30
|
+
ALTER TABLE "approval" ADD CONSTRAINT "approval_deployment_id_workflow_run_id_fk" FOREIGN KEY ("deployment_id") REFERENCES "public"."workflow_run"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
31
|
+
ALTER TABLE "signal_correlation" ADD CONSTRAINT "signal_correlation_deployment_id_workflow_run_id_fk" FOREIGN KEY ("deployment_id") REFERENCES "public"."workflow_run"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
32
|
+
ALTER TABLE "workflow_run" ADD CONSTRAINT "workflow_run_deployment_id_workflow_run_id_fk" FOREIGN KEY ("deployment_id") REFERENCES "public"."workflow_run"("id") ON DELETE cascade ON UPDATE no action;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
-- Drop the workflow_deployment projection. Its routing identity, reconnect key,
|
|
2
|
+
-- and status now live on the anchor run, its foreign keys were re-pointed onto
|
|
3
|
+
-- the anchor run, and nothing reads or writes it. This is irreversible.
|
|
4
|
+
--
|
|
5
|
+
-- Promote workflow_run.definition_id to NOT NULL: every run now carries a
|
|
6
|
+
-- definition (set at birth for new runs, filled by 0056 for the rows the
|
|
7
|
+
-- projection anchored). The guard below aborts before writing anything if any
|
|
8
|
+
-- run is still null -- that means the workflow-asset fold has not run, and
|
|
9
|
+
-- dropping the projection would strand those rows with no way to resolve their
|
|
10
|
+
-- definition. A blunt IS NULL check catches every class, including a run with a
|
|
11
|
+
-- null deployment_id the deployment join could never reach. Abort loudly so the
|
|
12
|
+
-- operator runs the fold and retries.
|
|
13
|
+
DO $$
|
|
14
|
+
BEGIN
|
|
15
|
+
IF EXISTS (SELECT 1 FROM "workflow_run" WHERE definition_id IS NULL) THEN
|
|
16
|
+
RAISE EXCEPTION 'workflow_run rows without a definition remain; run the workflow-asset fold (bin/db-backfill) before applying this migration';
|
|
17
|
+
END IF;
|
|
18
|
+
END $$;
|
|
19
|
+
--> statement-breakpoint
|
|
20
|
+
ALTER TABLE "workflow_run" ALTER COLUMN "definition_id" SET NOT NULL;
|
|
21
|
+
--> statement-breakpoint
|
|
22
|
+
DROP TABLE "workflow_deployment";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
-- Re-point the offering foreign key off the agent onto the folded workflow
|
|
2
|
+
-- definition. The column keeps its agent_id name -- the offering API exposes
|
|
3
|
+
-- agentId -- but its values become workflow_definition ids: every agent was
|
|
4
|
+
-- folded to exactly one definition, linked by workflow_definition.origin_agent_id
|
|
5
|
+
-- (a partial unique index, so the join matches at most one definition).
|
|
6
|
+
--
|
|
7
|
+
-- The guard runs before any write. The production path applies migrations under
|
|
8
|
+
-- `drizzle-kit migrate`, which wraps the pending set in a transaction, and
|
|
9
|
+
-- PostgreSQL DDL is transactional, so an aborting guard rolls the whole set
|
|
10
|
+
-- back -- there is no partial commit to defend against. It aborts loudly if any
|
|
11
|
+
-- offering's agent has no folded definition, meaning the agent fold has not
|
|
12
|
+
-- run; the total fold makes that impossible in a folded database, so the guard
|
|
13
|
+
-- is a fail-loud assertion.
|
|
14
|
+
DO $$
|
|
15
|
+
BEGIN
|
|
16
|
+
IF EXISTS (
|
|
17
|
+
SELECT 1
|
|
18
|
+
FROM "offering" o
|
|
19
|
+
WHERE NOT EXISTS (
|
|
20
|
+
SELECT 1 FROM "workflow_definition" wd
|
|
21
|
+
WHERE wd.origin_agent_id = o.agent_id
|
|
22
|
+
)
|
|
23
|
+
) THEN
|
|
24
|
+
RAISE EXCEPTION 'offering(s) reference an agent with no folded definition; run the agent fold (bin/db-backfill) before applying this migration';
|
|
25
|
+
END IF;
|
|
26
|
+
END $$;
|
|
27
|
+
--> statement-breakpoint
|
|
28
|
+
-- Drop the old agent foreign key BEFORE rewriting the values: the rewrite sets
|
|
29
|
+
-- agent_id to a workflow_definition id, which is not an agent id, so it would
|
|
30
|
+
-- violate the still-active agent FK. The offering table was renamed from
|
|
31
|
+
-- `capability` (migration 0004); Postgres does not rename constraints on a
|
|
32
|
+
-- table rename, so its agent FK still carries the original `capability_`-
|
|
33
|
+
-- prefixed name, not the `offering_`-prefixed name drizzle's snapshot infers.
|
|
34
|
+
ALTER TABLE "offering" DROP CONSTRAINT "capability_agent_id_agent_id_fk";
|
|
35
|
+
--> statement-breakpoint
|
|
36
|
+
UPDATE "offering" o
|
|
37
|
+
SET agent_id = wd.id
|
|
38
|
+
FROM "workflow_definition" wd
|
|
39
|
+
WHERE wd.origin_agent_id = o.agent_id;
|
|
40
|
+
--> statement-breakpoint
|
|
41
|
+
ALTER TABLE "offering" ADD CONSTRAINT "offering_agent_id_workflow_definition_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."workflow_definition"("id") ON DELETE restrict ON UPDATE no action;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- Re-point the transaction ledger off the agent onto the run that incurs a
|
|
2
|
+
-- charge. The table is unwritten (no producer), so there is no data to migrate
|
|
3
|
+
-- and no contract to preserve: rename agent_id to run_id and reference
|
|
4
|
+
-- workflow_run, keeping the nullable set-null delete so ledger history survives
|
|
5
|
+
-- the deletion of the run it references.
|
|
6
|
+
ALTER TABLE "transaction" RENAME COLUMN "agent_id" TO "run_id";
|
|
7
|
+
--> statement-breakpoint
|
|
8
|
+
ALTER TABLE "transaction" DROP CONSTRAINT "transaction_agent_id_agent_id_fk";
|
|
9
|
+
--> statement-breakpoint
|
|
10
|
+
ALTER TABLE "transaction" ADD CONSTRAINT "transaction_run_id_workflow_run_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."workflow_run"("id") ON DELETE set null ON UPDATE no action;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- Drop session_mail's foreign key to agent_instance. instance_id becomes a
|
|
2
|
+
-- bare polymorphic column -- a legacy agent_instance id, or null for a folded
|
|
3
|
+
-- run -- mirroring inference_turn.instance_id (migration 0052). A folded run's
|
|
4
|
+
-- id comes from a shared id space that agent_instance does not contain, so no
|
|
5
|
+
-- single-table foreign key spans both.
|
|
6
|
+
ALTER TABLE "session_mail" DROP CONSTRAINT "session_mail_instance_id_agent_instance_id_fk";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- Drop session_asset's foreign key to agent_instance. instance_id becomes a
|
|
2
|
+
-- bare polymorphic column -- a legacy agent_instance id or a folded run id --
|
|
3
|
+
-- mirroring inference_turn.instance_id (migration 0052). A folded launch
|
|
4
|
+
-- already writes its workflow_run id here, which the agent_instance FK rejected,
|
|
5
|
+
-- so this also unblocks attaching assets to a folded run. instance_id stays NOT
|
|
6
|
+
-- NULL and part of the (instance_id, mount_path) primary key.
|
|
7
|
+
ALTER TABLE "session_asset" DROP CONSTRAINT "session_asset_instance_id_agent_instance_id_fk";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- Drop the agent_asset table. Manual attach-to-an-agent was never wired,
|
|
2
|
+
-- so the table has no writer and is empty, and the launch-time direct
|
|
3
|
+
-- attachment path that read it is gone. session_asset's agent_asset_id
|
|
4
|
+
-- foreign key and its source column only distinguished direct attachments
|
|
5
|
+
-- from resolver-derived materializations; with the direct path gone every
|
|
6
|
+
-- row is resolver-derived, so both are dead. Drop the two columns first --
|
|
7
|
+
-- dropping agent_asset_id takes its foreign key with it -- so the table
|
|
8
|
+
-- has no remaining dependents when it goes (no CASCADE needed).
|
|
9
|
+
ALTER TABLE "session_asset" DROP COLUMN "agent_asset_id";--> statement-breakpoint
|
|
10
|
+
ALTER TABLE "session_asset" DROP COLUMN "source";--> statement-breakpoint
|
|
11
|
+
DROP TABLE "agent_asset";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
-- Re-point the agent_role foreign key off the agent onto the folded workflow
|
|
2
|
+
-- definition. The column keeps its agent_id name, but its values become
|
|
3
|
+
-- workflow_definition ids: every agent was folded to exactly one definition,
|
|
4
|
+
-- linked by workflow_definition.origin_agent_id (a partial unique index, so
|
|
5
|
+
-- the join matches at most one definition). Role assignments follow the
|
|
6
|
+
-- definition so they survive the agent table's retirement.
|
|
7
|
+
--
|
|
8
|
+
-- The guard runs before any write. The production path applies migrations under
|
|
9
|
+
-- `drizzle-kit migrate`, which wraps the pending set in a transaction, and
|
|
10
|
+
-- PostgreSQL DDL is transactional, so an aborting guard rolls the whole set
|
|
11
|
+
-- back -- there is no partial commit to defend against. It aborts loudly if any
|
|
12
|
+
-- agent_role row references an agent with no folded definition, meaning the
|
|
13
|
+
-- agent fold has not run; the total fold makes that impossible in a folded
|
|
14
|
+
-- database, so the guard is a fail-loud assertion.
|
|
15
|
+
DO $$
|
|
16
|
+
BEGIN
|
|
17
|
+
IF EXISTS (
|
|
18
|
+
SELECT 1
|
|
19
|
+
FROM "agent_role" ar
|
|
20
|
+
WHERE NOT EXISTS (
|
|
21
|
+
SELECT 1 FROM "workflow_definition" wd
|
|
22
|
+
WHERE wd.origin_agent_id = ar.agent_id
|
|
23
|
+
)
|
|
24
|
+
) THEN
|
|
25
|
+
RAISE EXCEPTION 'agent_role row(s) reference an agent with no folded definition; run the agent fold (bin/db-backfill) before applying this migration';
|
|
26
|
+
END IF;
|
|
27
|
+
END $$;
|
|
28
|
+
--> statement-breakpoint
|
|
29
|
+
-- Drop the old agent foreign key BEFORE rewriting the values: the rewrite sets
|
|
30
|
+
-- agent_id to a workflow_definition id, which is not an agent id, so it would
|
|
31
|
+
-- violate the still-active agent FK.
|
|
32
|
+
ALTER TABLE "agent_role" DROP CONSTRAINT "agent_role_agent_id_agent_id_fk";
|
|
33
|
+
--> statement-breakpoint
|
|
34
|
+
UPDATE "agent_role" ar
|
|
35
|
+
SET agent_id = wd.id
|
|
36
|
+
FROM "workflow_definition" wd
|
|
37
|
+
WHERE wd.origin_agent_id = ar.agent_id;
|
|
38
|
+
--> statement-breakpoint
|
|
39
|
+
ALTER TABLE "agent_role" ADD CONSTRAINT "agent_role_agent_id_workflow_definition_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."workflow_definition"("id") ON DELETE cascade ON UPDATE no action;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
-- Re-point the agent_session foreign key off the agent onto the folded
|
|
2
|
+
-- workflow definition. The column keeps its agent_id name, but its values
|
|
3
|
+
-- become workflow_definition ids: a launched session is keyed to the folded
|
|
4
|
+
-- definition it runs, so it survives the agent table's retirement. The delete
|
|
5
|
+
-- rule also changes -- cascade (on agent, from 0008) becomes restrict: session
|
|
6
|
+
-- history is an audit record, so a definition with live sessions must not be
|
|
7
|
+
-- droppable out from under them.
|
|
8
|
+
--
|
|
9
|
+
-- The guard runs before any write. The production path applies migrations under
|
|
10
|
+
-- `drizzle-kit migrate`, which wraps the pending set in a transaction, and
|
|
11
|
+
-- PostgreSQL DDL is transactional, so an aborting guard rolls the whole set
|
|
12
|
+
-- back -- there is no partial commit to defend against.
|
|
13
|
+
-- Unlike the offering (0058) and agent_role (0063) re-points, it guards the
|
|
14
|
+
-- AGENT table, not agent_session: the launch handler writes a fresh
|
|
15
|
+
-- agent_session row at runtime for an agent that may have no existing sessions,
|
|
16
|
+
-- so a child-table guard would pass vacuously for a never-launched unfolded
|
|
17
|
+
-- agent and the writer would then explode on its undefined definition id.
|
|
18
|
+
-- Every agent folded implies every session's agent folded, covering both this
|
|
19
|
+
-- historical rewrite and the runtime writer.
|
|
20
|
+
DO $$
|
|
21
|
+
BEGIN
|
|
22
|
+
IF EXISTS (
|
|
23
|
+
SELECT 1
|
|
24
|
+
FROM "agent" a
|
|
25
|
+
WHERE NOT EXISTS (
|
|
26
|
+
SELECT 1 FROM "workflow_definition" wd
|
|
27
|
+
WHERE wd.origin_agent_id = a.id
|
|
28
|
+
)
|
|
29
|
+
) THEN
|
|
30
|
+
RAISE EXCEPTION 'agent(s) have no folded definition; run the agent fold (bin/db-backfill) before applying this migration';
|
|
31
|
+
END IF;
|
|
32
|
+
END $$;
|
|
33
|
+
--> statement-breakpoint
|
|
34
|
+
-- Drop the old agent foreign key BEFORE rewriting the values: the rewrite sets
|
|
35
|
+
-- agent_id to a workflow_definition id, which is not an agent id, so it would
|
|
36
|
+
-- violate the still-active agent FK. agent_session's agent FK was written as a
|
|
37
|
+
-- raw inline REFERENCES in 0008, so Postgres auto-named it
|
|
38
|
+
-- agent_session_agent_id_fkey -- not the drizzle-style
|
|
39
|
+
-- agent_session_agent_id_agent_id_fk the snapshot infers.
|
|
40
|
+
ALTER TABLE "agent_session" DROP CONSTRAINT "agent_session_agent_id_fkey";
|
|
41
|
+
--> statement-breakpoint
|
|
42
|
+
UPDATE "agent_session" s
|
|
43
|
+
SET agent_id = wd.id
|
|
44
|
+
FROM "workflow_definition" wd
|
|
45
|
+
WHERE wd.origin_agent_id = s.agent_id;
|
|
46
|
+
--> statement-breakpoint
|
|
47
|
+
ALTER TABLE "agent_session" ADD CONSTRAINT "agent_session_agent_id_workflow_definition_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."workflow_definition"("id") ON DELETE restrict ON UPDATE no action;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
-- Mirror each folded agent's model requirements onto its definition, so a
|
|
2
|
+
-- folded launch resolves its inference sources from the definition rather than
|
|
3
|
+
-- the agent row. The column is folded-only: null for a workflow-origin
|
|
4
|
+
-- definition, which carries no requirements manifest. A null/empty manifest is
|
|
5
|
+
-- legitimate -- it resolves to an unlaunchable empty source chain, exactly as
|
|
6
|
+
-- the agent field did -- so the copy preserves null verbatim and the column
|
|
7
|
+
-- takes no NOT NULL constraint.
|
|
8
|
+
--
|
|
9
|
+
-- Guard first: the backfill joins each folded definition to its agent over
|
|
10
|
+
-- origin_agent_id, a plain text column rather than an FK. If any folded
|
|
11
|
+
-- definition names an agent that does not exist, the join silently skips it and
|
|
12
|
+
-- its column stays null -- indistinguishable from a legitimately-null manifest.
|
|
13
|
+
-- Fail loud before writing so a broken back-reference surfaces here, not as a
|
|
14
|
+
-- mysteriously unlaunchable agent later. The production path applies migrations
|
|
15
|
+
-- under `drizzle-kit migrate`, which wraps the pending set in a transaction, and
|
|
16
|
+
-- PostgreSQL DDL is transactional, so an aborting guard rolls the whole set back
|
|
17
|
+
-- rather than leaving a half-applied backfill.
|
|
18
|
+
DO $$
|
|
19
|
+
BEGIN
|
|
20
|
+
IF EXISTS (
|
|
21
|
+
SELECT 1
|
|
22
|
+
FROM "workflow_definition" wd
|
|
23
|
+
WHERE wd.origin_agent_id IS NOT NULL
|
|
24
|
+
AND NOT EXISTS (
|
|
25
|
+
SELECT 1 FROM "agent" a WHERE a.id = wd.origin_agent_id
|
|
26
|
+
)
|
|
27
|
+
) THEN
|
|
28
|
+
RAISE EXCEPTION 'folded definition(s) reference a missing agent; cannot backfill workflow_definition.model_requirements';
|
|
29
|
+
END IF;
|
|
30
|
+
END $$;
|
|
31
|
+
--> statement-breakpoint
|
|
32
|
+
ALTER TABLE "workflow_definition" ADD COLUMN "model_requirements" jsonb;
|
|
33
|
+
--> statement-breakpoint
|
|
34
|
+
UPDATE "workflow_definition" wd
|
|
35
|
+
SET model_requirements = a.model_requirements
|
|
36
|
+
FROM "agent" a
|
|
37
|
+
WHERE wd.origin_agent_id = a.id;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- Re-key each folded agent's actor identity onto the workflow model. A
|
|
2
|
+
-- definition-level agent principal's ref_id is the legacy agent id; the fold
|
|
3
|
+
-- moved that agent onto a workflow_definition, so its principal moves too --
|
|
4
|
+
-- kind agent -> workflow, ref_id agent.id -> definition.id. Afterwards the
|
|
5
|
+
-- folded agent's stable identity is a workflow-kind principal keyed by the
|
|
6
|
+
-- definition, and any grants it owns ride along under the new key untouched.
|
|
7
|
+
--
|
|
8
|
+
-- The mapping is 1:1 per tenant, which is what keeps the rewrite from
|
|
9
|
+
-- colliding on principal's UNIQUE(tenant_id, kind, ref_id): the partial-unique
|
|
10
|
+
-- index on workflow_definition.origin_agent_id admits at most one definition
|
|
11
|
+
-- per agent id, so no two agent principals collapse onto the same workflow key.
|
|
12
|
+
-- Existing workflow principals key on a run id, never a definition id, so the
|
|
13
|
+
-- re-keyed rows cannot collide with them either. The tenant predicate holds the
|
|
14
|
+
-- rewrite inside a single tenant even though agent ids are globally unique.
|
|
15
|
+
--
|
|
16
|
+
-- Only the definition-level class re-keys. An instance-level agent principal's
|
|
17
|
+
-- ref_id is an agent_instance id, which matches no origin_agent_id (disjoint id
|
|
18
|
+
-- spaces), so the join leaves it kind agent -- it retires later with the
|
|
19
|
+
-- agent_instance table it depends on. Idempotent: kind = 'agent' guards the
|
|
20
|
+
-- rewrite, and once it runs no definition principal remains agent-kind, so a
|
|
21
|
+
-- re-run is a no-op.
|
|
22
|
+
UPDATE "principal" p
|
|
23
|
+
SET kind = 'workflow', ref_id = wd.id
|
|
24
|
+
FROM "workflow_definition" wd
|
|
25
|
+
WHERE p.kind = 'agent'
|
|
26
|
+
AND wd.origin_agent_id = p.ref_id
|
|
27
|
+
AND wd.tenant_id = p.tenant_id;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- Classify each definition as a single-instance launch target (`instance`) or a
|
|
2
|
+
-- multi-step workflow deploy target (`workflow`), so the launch route can gate
|
|
3
|
+
-- on `kind` instead of `origin_agent_id` -- letting that column be dropped
|
|
4
|
+
-- later. Every folded (agent-origin) definition is an instance; a native
|
|
5
|
+
-- workflow-origin definition is a workflow. ADD COLUMN with a `workflow`
|
|
6
|
+
-- default sets every existing row to `workflow`; the backfill then flips the
|
|
7
|
+
-- folded rows, identified by a non-null origin_agent_id, to `instance`.
|
|
8
|
+
ALTER TABLE "workflow_definition" ADD COLUMN "kind" text DEFAULT 'workflow' NOT NULL;
|
|
9
|
+
--> statement-breakpoint
|
|
10
|
+
UPDATE "workflow_definition" SET "kind" = 'instance' WHERE "origin_agent_id" IS NOT NULL;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
-- The fold onto workflow_definition/workflow_run is complete: nothing reads
|
|
2
|
+
-- the legacy agent tables or workflow_definition.origin_agent_id anymore. Drop
|
|
3
|
+
-- them. Child-first order (no CASCADE) so a bare DROP fails loudly if an
|
|
4
|
+
-- unmodelled dependent survives. The production path applies migrations under
|
|
5
|
+
-- `drizzle-kit migrate`, which wraps the pending set in a transaction, and
|
|
6
|
+
-- PostgreSQL DDL is transactional, so a guard's abort rolls the whole set back;
|
|
7
|
+
-- there is no partial-commit re-run-from-top mode. The IF EXISTS clauses keep
|
|
8
|
+
-- each drop tolerant of an already-absent relation regardless.
|
|
9
|
+
--
|
|
10
|
+
-- Guard first: agent_instance holds legacy routing, mail, and turn state that
|
|
11
|
+
-- the workflow-asset fold never converted into workflow_run (the fold projected
|
|
12
|
+
-- definitions from assets; it never migrated instances), and the fold tooling
|
|
13
|
+
-- has since been retired, so a bare DROP would destroy that state silently.
|
|
14
|
+
-- Abort while the table still holds rows so the loss is loud, not silent. The
|
|
15
|
+
-- to_regclass check keeps the file idempotent: on a re-run after the drop the
|
|
16
|
+
-- table is gone and the guard is skipped rather than erroring on a missing
|
|
17
|
+
-- relation.
|
|
18
|
+
DO $$
|
|
19
|
+
BEGIN
|
|
20
|
+
IF to_regclass('agent_instance') IS NOT NULL THEN
|
|
21
|
+
IF EXISTS (SELECT 1 FROM "agent_instance") THEN
|
|
22
|
+
RAISE EXCEPTION 'agent_instance still holds rows: dropping the agent tables would destroy legacy agent routing, mail, and turn state that was never folded into workflow_run and has no automated conversion (the fold tooling has been retired). Retire the remaining agent instances by hand before applying this migration (see the agent-fold migration note in DEV.md).';
|
|
23
|
+
END IF;
|
|
24
|
+
END IF;
|
|
25
|
+
END $$;
|
|
26
|
+
--> statement-breakpoint
|
|
27
|
+
DROP TABLE IF EXISTS "agent_instance";--> statement-breakpoint
|
|
28
|
+
DROP TABLE IF EXISTS "agent_version";--> statement-breakpoint
|
|
29
|
+
DROP TABLE IF EXISTS "agent";--> statement-breakpoint
|
|
30
|
+
DROP INDEX IF EXISTS "workflow_definition_origin_agent_idx";--> statement-breakpoint
|
|
31
|
+
ALTER TABLE "workflow_definition" DROP COLUMN IF EXISTS "origin_agent_id";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- The instance/workflow `kind` discriminator is redundant: a run already
|
|
2
|
+
-- classifies structurally (a plain routing address with a null deployment id is
|
|
3
|
+
-- an instance-shaped run; a deployment-anchored run carries its deployment id),
|
|
4
|
+
-- and the interactive-launch path gates on the presence of a model_requirements
|
|
5
|
+
-- manifest instead of kind. Drop the column. The production path applies
|
|
6
|
+
-- migrations under `drizzle-kit migrate`, which wraps the pending set in a
|
|
7
|
+
-- transaction, and PostgreSQL DDL is transactional, so an aborting migration
|
|
8
|
+
-- rolls back with no partial-commit re-run to defend against; the IF EXISTS
|
|
9
|
+
-- keeps the drop tolerant of an already-absent column regardless.
|
|
10
|
+
ALTER TABLE "workflow_definition" DROP COLUMN IF EXISTS "kind";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
CREATE TABLE "workflow_run_execution" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"run_id" text NOT NULL,
|
|
4
|
+
"message_id" text NOT NULL,
|
|
5
|
+
"status" text DEFAULT 'running' NOT NULL,
|
|
6
|
+
"started_at" timestamp DEFAULT now() NOT NULL,
|
|
7
|
+
"ended_at" timestamp,
|
|
8
|
+
"failure_reason" text
|
|
9
|
+
);
|
|
10
|
+
--> statement-breakpoint
|
|
11
|
+
ALTER TABLE "workflow_run_execution" ADD CONSTRAINT "workflow_run_execution_run_id_workflow_run_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."workflow_run"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
12
|
+
CREATE UNIQUE INDEX "workflow_run_execution_run_id_id_idx" ON "workflow_run_execution" USING btree ("run_id","id");--> statement-breakpoint
|
|
13
|
+
CREATE INDEX "workflow_run_execution_status_idx" ON "workflow_run_execution" USING btree ("status");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE "workflow_definition" ADD COLUMN "credential_bindings" jsonb;
|