thinkwork-cli 0.12.15 → 0.12.17
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/{api-client-4VT3FWOH.js → api-client-JUBCQQDF.js} +1 -1
- package/dist/{chunk-H7AB42ES.js → chunk-STY44FQO.js} +13 -0
- package/dist/cli.js +1107 -10225
- package/dist/commands/enterprise/templates/deploy-repo/docs/runbook.md +3 -8
- package/dist/commands/enterprise/templates/deploy-repo/terraform/main.tf +1 -184
- package/dist/drizzle/0050_brain_v0_entity_subtype.sql +2 -2
- package/dist/drizzle/0051_brain_v0_tenant_entity_pages.sql +6 -6
- package/dist/drizzle/0052_brain_v0_external_refs.sql +2 -2
- package/dist/drizzle/0053_brain_v0_unresolved_mentions_subtype.sql +2 -2
- package/dist/drizzle/0145_knowledge_graph_thread_ingest.sql +14 -14
- package/dist/drizzle/0146_knowledge_graph_source_scope.sql +1 -1
- package/dist/drizzle/0157_knowledge_graph_observations_source.sql +2 -2
- package/dist/drizzle/0158_wiki_tenant_scope.sql +1 -1
- package/dist/drizzle/0165_plugin_premium_entitlements.sql +2 -2
- package/dist/drizzle/{0166_company_brain_substrate_contract.sql → 0166_brain_substrate_contract.sql} +9 -9
- package/dist/drizzle/{0167_company_brain_artifact_manifest_runtime.sql → 0167_brain_artifact_manifest_runtime.sql} +5 -5
- package/dist/drizzle/0168_eval_skill_gate.sql +1 -1
- package/dist/drizzle/0183_okf_artifact_manifests.sql +1 -1
- package/dist/drizzle/0197_rcm_context_columns.sql +28 -0
- package/dist/drizzle/0200_eval_results_execution_tier.sql +40 -0
- package/dist/drizzle/0201_brain_dream_runs.sql +72 -0
- package/dist/drizzle/0202_backfill_thread_participants_from_senders.sql +110 -0
- package/dist/drizzle/0203_threads_mode_override.sql +61 -0
- package/dist/drizzle/0204_thread_turns_triggering_message_id.sql +48 -0
- package/dist/drizzle/0205_routines_git_python.sql +185 -0
- package/dist/drizzle/0206_agent_loop_versions_routine_actions.sql +40 -0
- package/dist/drizzle/0207_tenant_credentials_github_repo_kind.sql +52 -0
- package/dist/drizzle/0208_knowledge_graph_neutral_identifiers.sql +253 -0
- package/dist/drizzle/0209_living_artifacts_schema.sql +109 -0
- package/dist/drizzle/0210_think137_automations_additive_schema.sql +113 -0
- package/dist/drizzle/0211_backfill_agent_loop_versions_target_spec.sql +120 -0
- package/dist/drizzle/0212_fold_webhooks_into_automations.sql +312 -0
- package/dist/drizzle/0213_agent_loop_versions_judge_evidence_nullable.sql +63 -0
- package/dist/drizzle/0214_think137_drop_judge_evidence_roi.sql +99 -0
- package/dist/drizzle/0215_agent_loop_versions_goal_worker_policy_nullable.sql +70 -0
- package/dist/drizzle/0216_drop_agent_loop_versions_goal_worker_policy.sql +81 -0
- package/dist/drizzle/0217_agents_capability_folder_dispatch.sql +12 -0
- package/dist/drizzle/0218_document_plates.sql +30 -0
- package/dist/drizzle/0219_document_section_waivers.sql +29 -0
- package/dist/drizzle/0220_artifacts_created_by_user.sql +21 -0
- package/dist/drizzle/0221_artifact_shares.sql +29 -0
- package/dist/drizzle/0221_workflow_interpreter_thin_slice.sql +71 -0
- package/dist/drizzle/0222_compliance_drainer_select_audit_events.sql +21 -0
- package/dist/drizzle/0223_document_conformance_reports.sql +38 -0
- package/dist/drizzle/0224_artifact_refresh_state.sql +11 -0
- package/dist/drizzle/0225_think216_agent_loop_convergence.sql +21 -0
- package/dist/drizzle/0226_drop_n8n_agent_step_runs.sql +6 -0
- package/dist/drizzle/0227_analyst_reader_role.sql +1055 -0
- package/dist/drizzle/0228_tenant_credentials_rds_iam_kind.sql +62 -0
- package/dist/drizzle/0229_analyst_reader_rds_iam_grant.sql +79 -0
- package/dist/drizzle/0230_analyst_rls.sql +1613 -0
- package/dist/drizzle/0231_cost_events_cache_write_enforcement_exempt.sql +11 -0
- package/dist/plugins/catalog/package.json +0 -1
- package/dist/plugins/catalog/src/__tests__/build-catalog.test.ts +0 -1
- package/dist/plugins/catalog/src/__tests__/catalog.test.ts +16 -8
- package/dist/plugins/catalog/src/__tests__/contracts.test.ts +56 -0
- package/dist/plugins/catalog/src/__tests__/plugin-package.test.ts +0 -2
- package/dist/plugins/catalog/src/__tests__/plugin-registry.test.ts +0 -5
- package/dist/plugins/catalog/src/contracts.ts +112 -0
- package/dist/plugins/catalog/src/registry/generated-first-party.ts +0 -6
- package/dist/plugins/n8n/README.md +4 -36
- package/dist/plugins/n8n/src/deployment/managed-app.ts +0 -17
- package/dist/plugins/n8n/src/manifest.ts +0 -5
- package/dist/plugins/n8n/terraform/n8n/main.tf +0 -26
- package/dist/plugins/n8n/terraform/n8n/outputs.tf +0 -5
- package/dist/plugins/n8n/terraform/n8n/variables.tf +0 -6
- package/dist/plugins/n8n/test/manifest.test.ts +0 -1
- package/dist/plugins/twenty/package.json +5 -0
- package/dist/plugins/twenty/scripts/lib/__tests__/load-records.test.ts +232 -0
- package/dist/plugins/twenty/scripts/lib/__tests__/mappers.test.ts +489 -0
- package/dist/plugins/twenty/scripts/lib/__tests__/members-ensure.test.ts +199 -0
- package/dist/plugins/twenty/scripts/lib/__tests__/provision-members-db.test.ts +43 -0
- package/dist/plugins/twenty/scripts/lib/__tests__/schema-ensure.test.ts +230 -0
- package/dist/plugins/twenty/scripts/lib/__tests__/twenty-client.test.ts +207 -0
- package/dist/plugins/twenty/scripts/lib/lastmile-reader.ts +282 -0
- package/dist/plugins/twenty/scripts/lib/load-attachments.ts +220 -0
- package/dist/plugins/twenty/scripts/lib/load-records.ts +680 -0
- package/dist/plugins/twenty/scripts/lib/mappers.ts +559 -0
- package/dist/plugins/twenty/scripts/lib/members-ensure.ts +381 -0
- package/dist/plugins/twenty/scripts/lib/provision-members-db.ts +191 -0
- package/dist/plugins/twenty/scripts/lib/schema-ensure.ts +425 -0
- package/dist/plugins/twenty/scripts/lib/twenty-client.ts +246 -0
- package/dist/plugins/twenty/scripts/migrate-lastmile.ts +610 -0
- package/dist/plugins/twenty/scripts/provision-twenty-members.ts +214 -0
- package/dist/plugins/twenty/src/manifest.ts +99 -0
- package/dist/plugins/twenty/terraform/twenty/README.md +1 -1
- package/dist/plugins/twenty/test/manifest.test.ts +12 -2
- package/dist/terraform/examples/greenfield/main.tf +90 -380
- package/dist/terraform/examples/greenfield/terraform.tfvars.example +0 -1
- package/dist/terraform/modules/app/agentcore-pi/README.md +1 -3
- package/dist/terraform/modules/app/agentcore-pi/main.tf +36 -32
- package/dist/terraform/modules/app/agentcore-pi/variables.tf +23 -15
- package/dist/terraform/modules/app/agentcore-runtime/main.tf +3 -3
- package/dist/terraform/modules/app/customer-domain/main.tf +16 -2
- package/dist/terraform/modules/app/deployment-control-plane/main.tf +5 -0
- package/dist/terraform/modules/app/deployment-control-plane/runner.py +85 -207
- package/dist/terraform/modules/app/deployment-control-plane/test_runner_bundle.py +56 -2
- package/dist/terraform/modules/app/hindsight-memory/main.tf +52 -4
- package/dist/terraform/modules/app/lambda-api/eval-fanout.tf +7 -0
- package/dist/terraform/modules/app/lambda-api/handlers.tf +493 -89
- package/dist/terraform/modules/app/lambda-api/iam-grouped.tf +215 -96
- package/dist/terraform/modules/app/lambda-api/main.tf +24 -5
- package/dist/terraform/modules/app/lambda-api/outputs.tf +19 -11
- package/dist/terraform/modules/app/lambda-api/variables.tf +94 -67
- package/dist/terraform/modules/app/ses-email/main.tf +14 -2
- package/dist/terraform/modules/app/workflow-interpreter-stepfunctions/main.tf +493 -0
- package/dist/terraform/modules/app/workflow-interpreter-stepfunctions/outputs.tf +34 -0
- package/dist/terraform/modules/app/workflow-interpreter-stepfunctions/variables.tf +32 -0
- package/dist/terraform/modules/data/aurora-postgres/main.tf +55 -0
- package/dist/terraform/modules/data/aurora-postgres/outputs.tf +15 -0
- package/dist/terraform/modules/data/s3-buckets/main.tf +26 -0
- package/dist/terraform/modules/thinkwork/README.md +0 -1
- package/dist/terraform/modules/thinkwork/main.tf +167 -446
- package/dist/terraform/modules/thinkwork/outputs.tf +2 -142
- package/dist/terraform/modules/thinkwork/variables.tf +55 -309
- package/dist/terraform/schema.graphql +4 -0
- package/dist/workspace-defaults/files/AGENTS.md +45 -31
- package/dist/workspace-defaults/files/CONTEXT.md +48 -4
- package/dist/workspace-defaults/files/GUARDRAILS.md +18 -0
- package/dist/workspace-defaults/files/MEMORY_GUIDE.md +32 -4
- package/dist/workspace-defaults/files/SPACE.md +34 -19
- package/dist/workspace-defaults/files/TOOLS.md +30 -0
- package/dist/workspace-defaults/files/skills/document-composer/SKILL.md +154 -0
- package/dist/workspace-defaults/files/skills/document-composer/references/authoring-rules.md +101 -0
- package/package.json +2 -1
- package/dist/plugins/company-brain/README.md +0 -37
- package/dist/plugins/company-brain/package.json +0 -33
- package/dist/plugins/company-brain/runtime/cognee/Dockerfile +0 -11
- package/dist/plugins/company-brain/smoke/cognee-managed-app-smoke.mjs +0 -458
- package/dist/plugins/company-brain/smoke/cognee-memory-cutover-smoke.mjs +0 -539
- package/dist/plugins/company-brain/smoke/company-brain-context-engine-smoke.mjs +0 -312
- package/dist/plugins/company-brain/smoke/company-brain-operations-smoke.mjs +0 -449
- package/dist/plugins/company-brain/smoke/company-brain-plugin-smoke.mjs +0 -655
- package/dist/plugins/company-brain/smoke/hindsight-memory-isolation-smoke.mjs +0 -474
- package/dist/plugins/company-brain/src/api/cognee-client.ts +0 -896
- package/dist/plugins/company-brain/src/api/cognee-cluster-identity.ts +0 -49
- package/dist/plugins/company-brain/src/api/cognee-memory-scope.ts +0 -84
- package/dist/plugins/company-brain/src/api/context-engine-provider.ts +0 -888
- package/dist/plugins/company-brain/src/api/migration.ts +0 -665
- package/dist/plugins/company-brain/src/deployment/cognee-managed-app.ts +0 -396
- package/dist/plugins/company-brain/src/index.ts +0 -62
- package/dist/plugins/company-brain/src/manifest.ts +0 -112
- package/dist/plugins/company-brain/terraform/cognee/README.md +0 -263
- package/dist/plugins/company-brain/terraform/cognee/main.tf +0 -766
- package/dist/plugins/company-brain/terraform/cognee/outputs.tf +0 -144
- package/dist/plugins/company-brain/terraform/cognee/variables.tf +0 -402
- package/dist/plugins/company-brain/test/api/cognee-client.test.ts +0 -562
- package/dist/plugins/company-brain/test/api/cognee-memory-scope.test.ts +0 -74
- package/dist/plugins/company-brain/test/api/context-engine-provider.test.ts +0 -447
- package/dist/plugins/company-brain/test/api/migration.test.ts +0 -465
- package/dist/plugins/company-brain/test/manifest.test.ts +0 -95
- package/dist/plugins/company-brain/tsconfig.json +0 -8
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
-- Dream-state audit ledger: per-bank staged plan → atomic apply → applied markers.
|
|
2
|
+
-- Plan: docs/plans/2026-07-03-001-feat-thinkwork-brain-memory-architecture-plan.md (U4, KTD-2).
|
|
3
|
+
--
|
|
4
|
+
-- creates: public.brain_dream_runs
|
|
5
|
+
-- creates: public.brain_dream_runs_dedupe_key_uidx
|
|
6
|
+
-- creates: public.brain_dream_runs_tenant_bank_idx
|
|
7
|
+
-- creates: public.brain_dream_runs_tenant_status_idx
|
|
8
|
+
-- creates: public.brain_dream_actions
|
|
9
|
+
-- creates: public.brain_dream_actions_run_ordinal_uidx
|
|
10
|
+
-- creates: public.brain_dream_actions_run_status_idx
|
|
11
|
+
-- creates-constraint: public.brain_dream_runs.brain_dream_runs_tenant_id_tenants_id_fk
|
|
12
|
+
-- creates-constraint: public.brain_dream_runs.brain_dream_runs_status_check
|
|
13
|
+
-- creates-constraint: public.brain_dream_actions.brain_dream_actions_run_id_brain_dream_runs_id_fk
|
|
14
|
+
-- creates-constraint: public.brain_dream_actions.brain_dream_actions_type_check
|
|
15
|
+
-- creates-constraint: public.brain_dream_actions.brain_dream_actions_status_check
|
|
16
|
+
|
|
17
|
+
DO $$
|
|
18
|
+
BEGIN
|
|
19
|
+
IF to_regclass('public.tenants') IS NULL THEN
|
|
20
|
+
RAISE EXCEPTION 'tenants not found; apply core tenant migrations first';
|
|
21
|
+
END IF;
|
|
22
|
+
END $$;
|
|
23
|
+
|
|
24
|
+
CREATE TABLE IF NOT EXISTS "brain_dream_runs" (
|
|
25
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
26
|
+
"tenant_id" uuid NOT NULL,
|
|
27
|
+
"bank_id" text NOT NULL,
|
|
28
|
+
"dedupe_key" text NOT NULL,
|
|
29
|
+
"status" text NOT NULL DEFAULT 'planned',
|
|
30
|
+
"planned_counts" jsonb,
|
|
31
|
+
"applied_counts" jsonb,
|
|
32
|
+
"error_message" text,
|
|
33
|
+
"started_at" timestamp with time zone,
|
|
34
|
+
"finished_at" timestamp with time zone,
|
|
35
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now(),
|
|
36
|
+
"updated_at" timestamp with time zone NOT NULL DEFAULT now(),
|
|
37
|
+
CONSTRAINT "brain_dream_runs_tenant_id_tenants_id_fk"
|
|
38
|
+
FOREIGN KEY ("tenant_id") REFERENCES "public"."tenants"("id") ON DELETE cascade,
|
|
39
|
+
CONSTRAINT "brain_dream_runs_status_check"
|
|
40
|
+
CHECK (status IN ('planned', 'applying', 'applied', 'failed', 'skipped'))
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "brain_dream_runs_dedupe_key_uidx"
|
|
44
|
+
ON "brain_dream_runs" ("dedupe_key");
|
|
45
|
+
CREATE INDEX IF NOT EXISTS "brain_dream_runs_tenant_bank_idx"
|
|
46
|
+
ON "brain_dream_runs" ("tenant_id", "bank_id", "created_at");
|
|
47
|
+
CREATE INDEX IF NOT EXISTS "brain_dream_runs_tenant_status_idx"
|
|
48
|
+
ON "brain_dream_runs" ("tenant_id", "status");
|
|
49
|
+
|
|
50
|
+
CREATE TABLE IF NOT EXISTS "brain_dream_actions" (
|
|
51
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
52
|
+
"run_id" uuid NOT NULL,
|
|
53
|
+
"ordinal" integer NOT NULL,
|
|
54
|
+
"action_type" text NOT NULL,
|
|
55
|
+
"status" text NOT NULL DEFAULT 'staged',
|
|
56
|
+
"target" jsonb,
|
|
57
|
+
"reason" text,
|
|
58
|
+
"applied_at" timestamp with time zone,
|
|
59
|
+
"error_message" text,
|
|
60
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now(),
|
|
61
|
+
CONSTRAINT "brain_dream_actions_run_id_brain_dream_runs_id_fk"
|
|
62
|
+
FOREIGN KEY ("run_id") REFERENCES "public"."brain_dream_runs"("id") ON DELETE cascade,
|
|
63
|
+
CONSTRAINT "brain_dream_actions_type_check"
|
|
64
|
+
CHECK (action_type IN ('quarantine', 'forget', 'consolidate')),
|
|
65
|
+
CONSTRAINT "brain_dream_actions_status_check"
|
|
66
|
+
CHECK (status IN ('staged', 'applied', 'skipped'))
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "brain_dream_actions_run_ordinal_uidx"
|
|
70
|
+
ON "brain_dream_actions" ("run_id", "ordinal");
|
|
71
|
+
CREATE INDEX IF NOT EXISTS "brain_dream_actions_run_status_idx"
|
|
72
|
+
ON "brain_dream_actions" ("run_id", "status");
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
-- Purpose: make thread_participants a truthful record of who is actually in a
|
|
2
|
+
-- thread, so Thread Mode derivation (plan 2026-07-03-003 U3) does not
|
|
3
|
+
-- misclassify already-multiplayer threads at ship time (R13, AE7), and so
|
|
4
|
+
-- non-space threads can carry participant rows at all (R14).
|
|
5
|
+
--
|
|
6
|
+
-- Two changes, applied atomically:
|
|
7
|
+
-- 1. Schema: make thread_participants.space_id NULLABLE. Non-space threads
|
|
8
|
+
-- (no owning Space) get participant rows whose space_id is null. This is
|
|
9
|
+
-- the ALTER matching src/schema/thread-participants.ts (space_id no longer
|
|
10
|
+
-- .notNull()). db:generate could not emit a journaled migration here — the
|
|
11
|
+
-- drizzle snapshot (meta/) is frozen ~180 migrations behind HEAD and every
|
|
12
|
+
-- recent schema change is a hand-rolled file + deploy.yml step, so this
|
|
13
|
+
-- follows that established convention.
|
|
14
|
+
-- 2. Data: backfill one participant row per (tenant, thread, distinct human
|
|
15
|
+
-- message sender) for existing threads, so reply-joiners who never got a
|
|
16
|
+
-- row are counted. Agent/system senders are excluded.
|
|
17
|
+
--
|
|
18
|
+
-- Idempotent: DROP NOT NULL is a no-op if already dropped; the INSERT uses
|
|
19
|
+
-- ON CONFLICT DO NOTHING against the partial unique index on
|
|
20
|
+
-- (tenant_id, thread_id, user_id). Re-running is safe.
|
|
21
|
+
--
|
|
22
|
+
-- Apply manually (verification pass before merge):
|
|
23
|
+
-- psql "$DATABASE_URL" -v ON_ERROR_STOP=1 --single-transaction \
|
|
24
|
+
-- -f packages/database-pg/drizzle/0202_backfill_thread_participants_from_senders.sql
|
|
25
|
+
--
|
|
26
|
+
-- creates: public.view_thread_participants_sender_backfilled
|
|
27
|
+
|
|
28
|
+
\set ON_ERROR_STOP on
|
|
29
|
+
|
|
30
|
+
BEGIN;
|
|
31
|
+
|
|
32
|
+
SELECT pg_advisory_xact_lock(hashtext('thread_participants_sender_backfill_0202'));
|
|
33
|
+
|
|
34
|
+
SET LOCAL lock_timeout = '5s';
|
|
35
|
+
SET LOCAL statement_timeout = '180s';
|
|
36
|
+
|
|
37
|
+
DO $$
|
|
38
|
+
BEGIN
|
|
39
|
+
IF to_regclass('public.thread_participants') IS NULL THEN
|
|
40
|
+
RAISE EXCEPTION 'pre-flight: public.thread_participants does not exist';
|
|
41
|
+
END IF;
|
|
42
|
+
IF to_regclass('public.threads') IS NULL THEN
|
|
43
|
+
RAISE EXCEPTION 'pre-flight: public.threads does not exist';
|
|
44
|
+
END IF;
|
|
45
|
+
IF to_regclass('public.messages') IS NULL THEN
|
|
46
|
+
RAISE EXCEPTION 'pre-flight: public.messages does not exist';
|
|
47
|
+
END IF;
|
|
48
|
+
END $$;
|
|
49
|
+
|
|
50
|
+
-- 1. Non-space participation (R14): drop the NOT NULL on space_id so non-space
|
|
51
|
+
-- threads can carry rows. Idempotent.
|
|
52
|
+
ALTER TABLE public.thread_participants
|
|
53
|
+
ALTER COLUMN space_id DROP NOT NULL;
|
|
54
|
+
|
|
55
|
+
-- 2. Backfill sender participation from distinct human message senders.
|
|
56
|
+
-- sender_type 'user'/'human' are the human sender labels; agent/system
|
|
57
|
+
-- senders are excluded so they never become participants. Joining users
|
|
58
|
+
-- guards the FK (thread_participants.user_id -> users.id) against any
|
|
59
|
+
-- orphaned sender_id. space_id rides from the thread and is null for
|
|
60
|
+
-- non-space threads.
|
|
61
|
+
INSERT INTO public.thread_participants (
|
|
62
|
+
tenant_id,
|
|
63
|
+
thread_id,
|
|
64
|
+
space_id,
|
|
65
|
+
participant_type,
|
|
66
|
+
user_id,
|
|
67
|
+
role,
|
|
68
|
+
source,
|
|
69
|
+
notification_preference,
|
|
70
|
+
created_at,
|
|
71
|
+
updated_at
|
|
72
|
+
)
|
|
73
|
+
SELECT
|
|
74
|
+
m.tenant_id,
|
|
75
|
+
m.thread_id,
|
|
76
|
+
t.space_id,
|
|
77
|
+
'user',
|
|
78
|
+
m.sender_id,
|
|
79
|
+
'member',
|
|
80
|
+
'sender',
|
|
81
|
+
'subscribed',
|
|
82
|
+
MIN(m.created_at),
|
|
83
|
+
now()
|
|
84
|
+
FROM public.messages m
|
|
85
|
+
JOIN public.threads t
|
|
86
|
+
ON t.id = m.thread_id
|
|
87
|
+
AND t.tenant_id = m.tenant_id
|
|
88
|
+
JOIN public.users u
|
|
89
|
+
ON u.id = m.sender_id
|
|
90
|
+
AND u.tenant_id = m.tenant_id
|
|
91
|
+
WHERE m.sender_type IN ('user', 'human')
|
|
92
|
+
AND m.sender_id IS NOT NULL
|
|
93
|
+
GROUP BY m.tenant_id, m.thread_id, t.space_id, m.sender_id
|
|
94
|
+
ON CONFLICT (tenant_id, thread_id, user_id)
|
|
95
|
+
WHERE user_id IS NOT NULL
|
|
96
|
+
DO NOTHING;
|
|
97
|
+
|
|
98
|
+
-- Drift marker + summary. Its presence is what the drift reporter probes; the
|
|
99
|
+
-- view only exists if the whole transaction (ALTER + backfill) committed.
|
|
100
|
+
CREATE OR REPLACE VIEW public.view_thread_participants_sender_backfilled AS
|
|
101
|
+
SELECT
|
|
102
|
+
COUNT(*) FILTER (WHERE source = 'sender')::int AS sender_backfill_rows,
|
|
103
|
+
COUNT(*) FILTER (WHERE space_id IS NULL)::int AS non_space_rows,
|
|
104
|
+
now() AS checked_at
|
|
105
|
+
FROM public.thread_participants;
|
|
106
|
+
|
|
107
|
+
COMMENT ON VIEW public.view_thread_participants_sender_backfilled IS
|
|
108
|
+
'Drift marker and summary for 0202_backfill_thread_participants_from_senders.sql.';
|
|
109
|
+
|
|
110
|
+
COMMIT;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
-- Purpose: add the per-thread Thread Mode override column that backs
|
|
2
|
+
-- server-authoritative Thread Mode (plan 2026-07-03-003 U3, R3). NULL means the
|
|
3
|
+
-- mode is derived from human participant count (0–1 → agent, 2+ →
|
|
4
|
+
-- multiplayer); a non-null value pins the mode for every participant until
|
|
5
|
+
-- changed. Set from the thread info panel via updateThread(modeOverride).
|
|
6
|
+
--
|
|
7
|
+
-- Schema-only change matching src/schema/threads.ts (threads.mode_override
|
|
8
|
+
-- text, CHECK IN ('agent','multiplayer')). db:generate could not emit a
|
|
9
|
+
-- journaled migration here — the drizzle snapshot (meta/) is frozen ~180
|
|
10
|
+
-- migrations behind HEAD and every recent schema change is a hand-rolled file
|
|
11
|
+
-- plus a deploy.yml step, so this follows that established convention
|
|
12
|
+
-- (precedent: 0202_backfill_thread_participants_from_senders.sql).
|
|
13
|
+
--
|
|
14
|
+
-- Idempotent: ADD COLUMN IF NOT EXISTS is a no-op if the column exists; the
|
|
15
|
+
-- CHECK constraint is added only when absent (guarded by pg_constraint). Safe
|
|
16
|
+
-- to re-run.
|
|
17
|
+
--
|
|
18
|
+
-- Apply manually (verification pass before merge):
|
|
19
|
+
-- psql "$DATABASE_URL" -v ON_ERROR_STOP=1 --single-transaction \
|
|
20
|
+
-- -f packages/database-pg/drizzle/0203_threads_mode_override.sql
|
|
21
|
+
--
|
|
22
|
+
-- creates-column: public.threads.mode_override
|
|
23
|
+
|
|
24
|
+
\set ON_ERROR_STOP on
|
|
25
|
+
|
|
26
|
+
BEGIN;
|
|
27
|
+
|
|
28
|
+
SELECT pg_advisory_xact_lock(hashtext('threads_mode_override_0203'));
|
|
29
|
+
|
|
30
|
+
SET LOCAL lock_timeout = '5s';
|
|
31
|
+
SET LOCAL statement_timeout = '60s';
|
|
32
|
+
|
|
33
|
+
DO $$
|
|
34
|
+
BEGIN
|
|
35
|
+
IF to_regclass('public.threads') IS NULL THEN
|
|
36
|
+
RAISE EXCEPTION 'pre-flight: public.threads does not exist';
|
|
37
|
+
END IF;
|
|
38
|
+
END $$;
|
|
39
|
+
|
|
40
|
+
-- 1. Add the nullable override column. Idempotent.
|
|
41
|
+
ALTER TABLE public.threads
|
|
42
|
+
ADD COLUMN IF NOT EXISTS mode_override text;
|
|
43
|
+
|
|
44
|
+
-- 2. Constrain the allowed values. NULL is permitted (derived mode); non-null
|
|
45
|
+
-- must be one of the two modes. Added only when the named constraint does
|
|
46
|
+
-- not already exist so re-runs are no-ops.
|
|
47
|
+
DO $$
|
|
48
|
+
BEGIN
|
|
49
|
+
IF NOT EXISTS (
|
|
50
|
+
SELECT 1
|
|
51
|
+
FROM pg_constraint
|
|
52
|
+
WHERE conname = 'threads_mode_override_allowed'
|
|
53
|
+
AND conrelid = 'public.threads'::regclass
|
|
54
|
+
) THEN
|
|
55
|
+
ALTER TABLE public.threads
|
|
56
|
+
ADD CONSTRAINT threads_mode_override_allowed
|
|
57
|
+
CHECK (mode_override IS NULL OR mode_override IN ('agent','multiplayer'));
|
|
58
|
+
END IF;
|
|
59
|
+
END $$;
|
|
60
|
+
|
|
61
|
+
COMMIT;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
-- Purpose: add the durable turn→triggering-message link that backs the
|
|
2
|
+
-- per-message dispatch indicator (plan 2026-07-03-003 U6, R6/R7, KTD3). A
|
|
3
|
+
-- non-null value is the id of the USER message whose send dispatched this
|
|
4
|
+
-- turn; the web UI pairs turns to messages by this id and falls back to
|
|
5
|
+
-- today's timestamp pairing for legacy (null) rows. Stamped by BOTH dispatch
|
|
6
|
+
-- handlers — chat-agent-invoke (direct invoke) and wakeup-processor (fallback
|
|
7
|
+
-- / mention / resume) — from the messageId already carried on every dispatch
|
|
8
|
+
-- payload.
|
|
9
|
+
--
|
|
10
|
+
-- Schema-only change matching src/schema/scheduled-jobs.ts
|
|
11
|
+
-- (thread_turns.triggering_message_id uuid, nullable). NO foreign key: turns
|
|
12
|
+
-- may outlive the message row, and the sibling thread_id column on this table
|
|
13
|
+
-- is likewise an un-referenced uuid — matched here. db:generate could not emit
|
|
14
|
+
-- a journaled migration (the drizzle snapshot in meta/ is frozen ~180
|
|
15
|
+
-- migrations behind HEAD; every recent schema change is a hand-rolled file
|
|
16
|
+
-- plus a deploy.yml step), so this follows that established convention
|
|
17
|
+
-- (precedent: 0203_threads_mode_override.sql).
|
|
18
|
+
--
|
|
19
|
+
-- Idempotent: ADD COLUMN IF NOT EXISTS is a no-op if the column exists. Safe
|
|
20
|
+
-- to re-run.
|
|
21
|
+
--
|
|
22
|
+
-- Apply manually (verification pass before merge):
|
|
23
|
+
-- psql "$DATABASE_URL" -v ON_ERROR_STOP=1 --single-transaction \
|
|
24
|
+
-- -f packages/database-pg/drizzle/0204_thread_turns_triggering_message_id.sql
|
|
25
|
+
--
|
|
26
|
+
-- creates-column: public.thread_turns.triggering_message_id
|
|
27
|
+
|
|
28
|
+
\set ON_ERROR_STOP on
|
|
29
|
+
|
|
30
|
+
BEGIN;
|
|
31
|
+
|
|
32
|
+
SELECT pg_advisory_xact_lock(hashtext('thread_turns_triggering_message_id_0204'));
|
|
33
|
+
|
|
34
|
+
SET LOCAL lock_timeout = '5s';
|
|
35
|
+
SET LOCAL statement_timeout = '60s';
|
|
36
|
+
|
|
37
|
+
DO $$
|
|
38
|
+
BEGIN
|
|
39
|
+
IF to_regclass('public.thread_turns') IS NULL THEN
|
|
40
|
+
RAISE EXCEPTION 'pre-flight: public.thread_turns does not exist';
|
|
41
|
+
END IF;
|
|
42
|
+
END $$;
|
|
43
|
+
|
|
44
|
+
-- Add the nullable triggering-message link. Idempotent.
|
|
45
|
+
ALTER TABLE public.thread_turns
|
|
46
|
+
ADD COLUMN IF NOT EXISTS triggering_message_id uuid;
|
|
47
|
+
|
|
48
|
+
COMMIT;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
-- Purpose: schema substrate for deterministic git-backed routines
|
|
2
|
+
-- (plan 2026-07-03-004 U1, KTD-1/KTD-7/KTD-11).
|
|
3
|
+
--
|
|
4
|
+
-- 1. routines.engine CHECK gains 'git_python'.
|
|
5
|
+
-- 2. routines gains git_python-only pointer columns (module_path,
|
|
6
|
+
-- fixture_paths, credential_refs, validated_sha, disabled_reason).
|
|
7
|
+
-- Code itself never lives in the DB (R1) — the tenant GitHub repo is
|
|
8
|
+
-- the single source of truth.
|
|
9
|
+
-- 3. routine_executions gains commit_sha / validated_sha / cache_served
|
|
10
|
+
-- (every git run answers "what exactly ran?", R4/R6) and relaxes
|
|
11
|
+
-- state_machine_arn + sfn_execution_arn to nullable — git_python
|
|
12
|
+
-- executions have no Step Functions involvement. The unique index on
|
|
13
|
+
-- sfn_execution_arn is NULL-tolerant in Postgres.
|
|
14
|
+
-- 4. New routine_code_cache table — DB index over the S3 read-through
|
|
15
|
+
-- code cache keyed by commit SHA; authoritative for "validated SHA
|
|
16
|
+
-- per routine".
|
|
17
|
+
-- 5. New routine_repair_events table — durable repair-ladder history
|
|
18
|
+
-- backing the visible repair log.
|
|
19
|
+
--
|
|
20
|
+
-- Schema-only change matching src/schema/{routines,routine-executions,
|
|
21
|
+
-- routine-code-cache,routine-repair-events}.ts. db:generate cannot emit a
|
|
22
|
+
-- journaled migration (the drizzle snapshot in meta/ is frozen ~180
|
|
23
|
+
-- migrations behind HEAD); hand-rolled per convention
|
|
24
|
+
-- (precedent: 0203_threads_mode_override.sql).
|
|
25
|
+
--
|
|
26
|
+
-- Idempotent: ADD COLUMN IF NOT EXISTS / CREATE TABLE IF NOT EXISTS /
|
|
27
|
+
-- CREATE INDEX IF NOT EXISTS; constraint changes guarded by pg_constraint
|
|
28
|
+
-- lookups; DROP NOT NULL is a no-op when already nullable. Safe to re-run.
|
|
29
|
+
--
|
|
30
|
+
-- Apply manually (verification pass before merge):
|
|
31
|
+
-- psql "$DATABASE_URL" -v ON_ERROR_STOP=1 --single-transaction \
|
|
32
|
+
-- -f packages/database-pg/drizzle/0205_routines_git_python.sql
|
|
33
|
+
--
|
|
34
|
+
-- creates-column: public.routines.module_path
|
|
35
|
+
-- creates-column: public.routines.fixture_paths
|
|
36
|
+
-- creates-column: public.routines.credential_refs
|
|
37
|
+
-- creates-column: public.routines.validated_sha
|
|
38
|
+
-- creates-column: public.routines.disabled_reason
|
|
39
|
+
-- creates-column: public.routine_executions.commit_sha
|
|
40
|
+
-- creates-column: public.routine_executions.validated_sha
|
|
41
|
+
-- creates-column: public.routine_executions.cache_served
|
|
42
|
+
-- creates: public.routine_code_cache
|
|
43
|
+
-- creates: public.routine_repair_events
|
|
44
|
+
-- creates: public.idx_routine_code_cache_routine_sha
|
|
45
|
+
-- creates: public.idx_routine_code_cache_tenant
|
|
46
|
+
-- creates: public.idx_routine_repair_events_routine_created
|
|
47
|
+
-- creates: public.idx_routine_repair_events_tenant
|
|
48
|
+
-- creates-constraint: public.routine_code_cache.routine_code_cache_fixture_status_enum
|
|
49
|
+
-- creates-constraint: public.routine_repair_events.routine_repair_events_event_type_enum
|
|
50
|
+
|
|
51
|
+
\set ON_ERROR_STOP on
|
|
52
|
+
|
|
53
|
+
BEGIN;
|
|
54
|
+
|
|
55
|
+
SELECT pg_advisory_xact_lock(hashtext('routines_git_python_0205'));
|
|
56
|
+
|
|
57
|
+
SET LOCAL lock_timeout = '5s';
|
|
58
|
+
SET LOCAL statement_timeout = '60s';
|
|
59
|
+
|
|
60
|
+
DO $$
|
|
61
|
+
BEGIN
|
|
62
|
+
IF to_regclass('public.routines') IS NULL THEN
|
|
63
|
+
RAISE EXCEPTION 'pre-flight: public.routines does not exist';
|
|
64
|
+
END IF;
|
|
65
|
+
IF to_regclass('public.routine_executions') IS NULL THEN
|
|
66
|
+
RAISE EXCEPTION 'pre-flight: public.routine_executions does not exist';
|
|
67
|
+
END IF;
|
|
68
|
+
END $$;
|
|
69
|
+
|
|
70
|
+
-- 1. Extend the engine CHECK to admit 'git_python'. Drop + re-add under
|
|
71
|
+
-- the same name; guarded so re-runs are no-ops once the new definition
|
|
72
|
+
-- is in place.
|
|
73
|
+
DO $$
|
|
74
|
+
BEGIN
|
|
75
|
+
IF EXISTS (
|
|
76
|
+
SELECT 1
|
|
77
|
+
FROM pg_constraint
|
|
78
|
+
WHERE conname = 'routines_engine_enum'
|
|
79
|
+
AND conrelid = 'public.routines'::regclass
|
|
80
|
+
AND pg_get_constraintdef(oid) NOT LIKE '%git_python%'
|
|
81
|
+
) THEN
|
|
82
|
+
ALTER TABLE public.routines DROP CONSTRAINT routines_engine_enum;
|
|
83
|
+
END IF;
|
|
84
|
+
|
|
85
|
+
IF NOT EXISTS (
|
|
86
|
+
SELECT 1
|
|
87
|
+
FROM pg_constraint
|
|
88
|
+
WHERE conname = 'routines_engine_enum'
|
|
89
|
+
AND conrelid = 'public.routines'::regclass
|
|
90
|
+
) THEN
|
|
91
|
+
ALTER TABLE public.routines
|
|
92
|
+
ADD CONSTRAINT routines_engine_enum
|
|
93
|
+
CHECK (engine IN ('legacy_python', 'step_functions', 'git_python'));
|
|
94
|
+
END IF;
|
|
95
|
+
END $$;
|
|
96
|
+
|
|
97
|
+
-- 2. git_python pointer columns on routines. All nullable (null on
|
|
98
|
+
-- legacy_python / step_functions rows).
|
|
99
|
+
ALTER TABLE public.routines
|
|
100
|
+
ADD COLUMN IF NOT EXISTS module_path text,
|
|
101
|
+
ADD COLUMN IF NOT EXISTS fixture_paths jsonb,
|
|
102
|
+
ADD COLUMN IF NOT EXISTS credential_refs jsonb,
|
|
103
|
+
ADD COLUMN IF NOT EXISTS validated_sha text,
|
|
104
|
+
ADD COLUMN IF NOT EXISTS disabled_reason text;
|
|
105
|
+
|
|
106
|
+
-- 3. git_python execution columns + relax SFN-only NOT NULLs.
|
|
107
|
+
ALTER TABLE public.routine_executions
|
|
108
|
+
ADD COLUMN IF NOT EXISTS commit_sha text,
|
|
109
|
+
ADD COLUMN IF NOT EXISTS validated_sha text,
|
|
110
|
+
ADD COLUMN IF NOT EXISTS cache_served boolean;
|
|
111
|
+
|
|
112
|
+
ALTER TABLE public.routine_executions
|
|
113
|
+
ALTER COLUMN state_machine_arn DROP NOT NULL,
|
|
114
|
+
ALTER COLUMN sfn_execution_arn DROP NOT NULL;
|
|
115
|
+
|
|
116
|
+
-- 4. routine_code_cache — S3 SHA-cache index (S3 canonical, DB derived).
|
|
117
|
+
CREATE TABLE IF NOT EXISTS public.routine_code_cache (
|
|
118
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
119
|
+
tenant_id uuid NOT NULL REFERENCES public.tenants(id),
|
|
120
|
+
routine_id uuid NOT NULL REFERENCES public.routines(id),
|
|
121
|
+
sha text NOT NULL,
|
|
122
|
+
s3_key text NOT NULL,
|
|
123
|
+
fixture_status text NOT NULL DEFAULT 'pending',
|
|
124
|
+
fixture_result_json text,
|
|
125
|
+
fetched_at timestamptz NOT NULL DEFAULT now(),
|
|
126
|
+
validated_at timestamptz,
|
|
127
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_routine_code_cache_routine_sha
|
|
131
|
+
ON public.routine_code_cache (routine_id, sha);
|
|
132
|
+
CREATE INDEX IF NOT EXISTS idx_routine_code_cache_tenant
|
|
133
|
+
ON public.routine_code_cache (tenant_id);
|
|
134
|
+
|
|
135
|
+
DO $$
|
|
136
|
+
BEGIN
|
|
137
|
+
IF NOT EXISTS (
|
|
138
|
+
SELECT 1
|
|
139
|
+
FROM pg_constraint
|
|
140
|
+
WHERE conname = 'routine_code_cache_fixture_status_enum'
|
|
141
|
+
AND conrelid = 'public.routine_code_cache'::regclass
|
|
142
|
+
) THEN
|
|
143
|
+
ALTER TABLE public.routine_code_cache
|
|
144
|
+
ADD CONSTRAINT routine_code_cache_fixture_status_enum
|
|
145
|
+
CHECK (fixture_status IN ('pending', 'green', 'red'));
|
|
146
|
+
END IF;
|
|
147
|
+
END $$;
|
|
148
|
+
|
|
149
|
+
-- 5. routine_repair_events — repair-ladder history (visible repair log).
|
|
150
|
+
CREATE TABLE IF NOT EXISTS public.routine_repair_events (
|
|
151
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
152
|
+
tenant_id uuid NOT NULL REFERENCES public.tenants(id),
|
|
153
|
+
routine_id uuid NOT NULL REFERENCES public.routines(id),
|
|
154
|
+
execution_id uuid REFERENCES public.routine_executions(id),
|
|
155
|
+
event_type text NOT NULL,
|
|
156
|
+
thread_ref text,
|
|
157
|
+
from_sha text,
|
|
158
|
+
to_sha text,
|
|
159
|
+
gate_result text,
|
|
160
|
+
envelope_verdict text,
|
|
161
|
+
budget_snapshot integer,
|
|
162
|
+
detail_json jsonb,
|
|
163
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
CREATE INDEX IF NOT EXISTS idx_routine_repair_events_routine_created
|
|
167
|
+
ON public.routine_repair_events (routine_id, created_at);
|
|
168
|
+
CREATE INDEX IF NOT EXISTS idx_routine_repair_events_tenant
|
|
169
|
+
ON public.routine_repair_events (tenant_id);
|
|
170
|
+
|
|
171
|
+
DO $$
|
|
172
|
+
BEGIN
|
|
173
|
+
IF NOT EXISTS (
|
|
174
|
+
SELECT 1
|
|
175
|
+
FROM pg_constraint
|
|
176
|
+
WHERE conname = 'routine_repair_events_event_type_enum'
|
|
177
|
+
AND conrelid = 'public.routine_repair_events'::regclass
|
|
178
|
+
) THEN
|
|
179
|
+
ALTER TABLE public.routine_repair_events
|
|
180
|
+
ADD CONSTRAINT routine_repair_events_event_type_enum
|
|
181
|
+
CHECK (event_type IN ('retry', 'revert', 'repair_attempt', 'pending_commit', 'disabled', 'infra_failure'));
|
|
182
|
+
END IF;
|
|
183
|
+
END $$;
|
|
184
|
+
|
|
185
|
+
COMMIT;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
-- Purpose: add the routine-actions field to Automation versions
|
|
2
|
+
-- (deterministic routines v1, plan 2026-07-03-004 U5, R7). Null on
|
|
3
|
+
-- versions without routine actions; otherwise a jsonb
|
|
4
|
+
-- {actions: [{routineId, input?, label?}], agentTurn: boolean} where
|
|
5
|
+
-- agentTurn=false marks a routine-only Automation (run completes with
|
|
6
|
+
-- zero agent turns / no wakeup).
|
|
7
|
+
--
|
|
8
|
+
-- Schema-only change matching src/schema/agent-loops.ts
|
|
9
|
+
-- (agent_loop_versions.routine_actions_spec jsonb). Hand-rolled per
|
|
10
|
+
-- convention — the drizzle snapshot in meta/ is frozen
|
|
11
|
+
-- (precedent: 0205_routines_git_python.sql).
|
|
12
|
+
--
|
|
13
|
+
-- Idempotent: ADD COLUMN IF NOT EXISTS. Safe to re-run.
|
|
14
|
+
--
|
|
15
|
+
-- Apply manually (verification pass before merge):
|
|
16
|
+
-- psql "$DATABASE_URL" -v ON_ERROR_STOP=1 --single-transaction \
|
|
17
|
+
-- -f packages/database-pg/drizzle/0206_agent_loop_versions_routine_actions.sql
|
|
18
|
+
--
|
|
19
|
+
-- creates-column: public.agent_loop_versions.routine_actions_spec
|
|
20
|
+
|
|
21
|
+
\set ON_ERROR_STOP on
|
|
22
|
+
|
|
23
|
+
BEGIN;
|
|
24
|
+
|
|
25
|
+
SELECT pg_advisory_xact_lock(hashtext('agent_loop_versions_routine_actions_0206'));
|
|
26
|
+
|
|
27
|
+
SET LOCAL lock_timeout = '5s';
|
|
28
|
+
SET LOCAL statement_timeout = '60s';
|
|
29
|
+
|
|
30
|
+
DO $$
|
|
31
|
+
BEGIN
|
|
32
|
+
IF to_regclass('public.agent_loop_versions') IS NULL THEN
|
|
33
|
+
RAISE EXCEPTION 'pre-flight: public.agent_loop_versions does not exist';
|
|
34
|
+
END IF;
|
|
35
|
+
END $$;
|
|
36
|
+
|
|
37
|
+
ALTER TABLE public.agent_loop_versions
|
|
38
|
+
ADD COLUMN IF NOT EXISTS routine_actions_spec jsonb;
|
|
39
|
+
|
|
40
|
+
COMMIT;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
-- Purpose: admit 'github_repo' in the tenant_credentials kind CHECK
|
|
2
|
+
-- (deterministic routines v1, plan 2026-07-03-004 U2 follow-up). U2
|
|
3
|
+
-- (#3273) added the GraphQL enum value, REQUIRED_FIELDS entry, and
|
|
4
|
+
-- save-time connection validation but missed the DB CHECK — the first
|
|
5
|
+
-- real save of a routine-repo credential violated
|
|
6
|
+
-- tenant_credentials_kind_enum. Caught during the U9 acceptance sweep.
|
|
7
|
+
--
|
|
8
|
+
-- Hand-rolled per convention (drizzle snapshot frozen; precedent
|
|
9
|
+
-- 0205/0206). Drop + re-add under the same name, guarded so re-runs are
|
|
10
|
+
-- no-ops once the new definition is in place.
|
|
11
|
+
--
|
|
12
|
+
-- Apply manually (verification pass before merge):
|
|
13
|
+
-- psql "$DATABASE_URL" -v ON_ERROR_STOP=1 --single-transaction \
|
|
14
|
+
-- -f packages/database-pg/drizzle/0207_tenant_credentials_github_repo_kind.sql
|
|
15
|
+
--
|
|
16
|
+
-- creates-constraint: public.tenant_credentials.tenant_credentials_kind_enum
|
|
17
|
+
|
|
18
|
+
\set ON_ERROR_STOP on
|
|
19
|
+
|
|
20
|
+
BEGIN;
|
|
21
|
+
|
|
22
|
+
SELECT pg_advisory_xact_lock(hashtext('tenant_credentials_github_repo_0207'));
|
|
23
|
+
|
|
24
|
+
SET LOCAL lock_timeout = '5s';
|
|
25
|
+
SET LOCAL statement_timeout = '60s';
|
|
26
|
+
|
|
27
|
+
DO $$
|
|
28
|
+
BEGIN
|
|
29
|
+
IF EXISTS (
|
|
30
|
+
SELECT 1
|
|
31
|
+
FROM pg_constraint
|
|
32
|
+
WHERE conname = 'tenant_credentials_kind_enum'
|
|
33
|
+
AND conrelid = 'public.tenant_credentials'::regclass
|
|
34
|
+
AND pg_get_constraintdef(oid) NOT LIKE '%github_repo%'
|
|
35
|
+
) THEN
|
|
36
|
+
ALTER TABLE public.tenant_credentials
|
|
37
|
+
DROP CONSTRAINT tenant_credentials_kind_enum;
|
|
38
|
+
END IF;
|
|
39
|
+
|
|
40
|
+
IF NOT EXISTS (
|
|
41
|
+
SELECT 1
|
|
42
|
+
FROM pg_constraint
|
|
43
|
+
WHERE conname = 'tenant_credentials_kind_enum'
|
|
44
|
+
AND conrelid = 'public.tenant_credentials'::regclass
|
|
45
|
+
) THEN
|
|
46
|
+
ALTER TABLE public.tenant_credentials
|
|
47
|
+
ADD CONSTRAINT tenant_credentials_kind_enum
|
|
48
|
+
CHECK (kind IN ('api_key','bearer_token','basic_auth','soap_partner','webhook_signing_secret','json','github_repo'));
|
|
49
|
+
END IF;
|
|
50
|
+
END $$;
|
|
51
|
+
|
|
52
|
+
COMMIT;
|