Merge origin/master and renumber additive Speko migrations

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-09 15:45:59 -05:00
commit bf1ead3772
65 files changed
+5336 -56682

No files matched your search

@@ -55,6 +55,9 @@ describeEmbeddedPostgres("connections v3 schema core migration", () => {
// Managed-account observations are later consumers of the same connection key.
await sql`DROP TABLE IF EXISTS "tool_connection_app_syncs"`;
await sql`DROP TABLE IF EXISTS "tool_connection_app_snapshots"`;
// Subscription reporting adds a later grant binding; rewind the empty
// fixture table before recreating grants, preserving production FK checks.
await sql`DROP TABLE IF EXISTS "ai_subscription_connections"`;
await sql`DROP TABLE IF EXISTS "connection_grants"`;
await sql`DROP INDEX IF EXISTS "tool_connections_company_uid_uq"`;
await sql`ALTER TABLE "tool_connections" DROP CONSTRAINT IF EXISTS "tool_connections_company_id_uq"`;
@@ -0,0 +1,98 @@
CREATE TABLE IF NOT EXISTS "ai_subscription_connections" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"company_id" uuid NOT NULL,
"connection_id" uuid NOT NULL,
"grant_id" uuid NOT NULL,
"credential_key" text NOT NULL,
"subscription_id" uuid NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "ai_subscription_prices" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"company_id" uuid NOT NULL,
"subscription_id" uuid NOT NULL,
"revision" integer NOT NULL,
"plan" text NOT NULL,
"amount_cents" numeric(24, 7),
"currency" text DEFAULT 'USD' NOT NULL,
"cadence" text DEFAULT 'month' NOT NULL,
"status" text DEFAULT 'active' NOT NULL,
"source" text NOT NULL,
"source_url" text,
"effective_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "ai_subscription_prices_valid" CHECK (("ai_subscription_prices"."amount_cents" is null or "ai_subscription_prices"."amount_cents" >= 0) and "ai_subscription_prices"."cadence" in ('month','year') and "ai_subscription_prices"."status" in ('active','ended','excluded') and "ai_subscription_prices"."source" in ('catalog','user','unknown'))
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "ai_subscriptions" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"company_id" uuid NOT NULL,
"provider" text NOT NULL,
"account_key" text NOT NULL,
"identity_verified" boolean DEFAULT false NOT NULL,
"name" text NOT NULL,
"owner_user_ids" text[] DEFAULT '{}'::text[] NOT NULL,
"shared" boolean DEFAULT false NOT NULL,
"detected_plan" text,
"observed_at" timestamp with time zone,
"last_checked_at" timestamp with time zone,
"refresh_status" text,
"merged_into_id" uuid,
"revision" integer DEFAULT 0 NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "ai_subscriptions_no_self_merge" CHECK ("ai_subscriptions"."merged_into_id" is null or "ai_subscriptions"."merged_into_id" <> "ai_subscriptions"."id")
);
--> statement-breakpoint
ALTER TABLE "cost_events" ADD COLUMN IF NOT EXISTS "subscription_id" uuid;--> statement-breakpoint
DO $$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'ai_subscription_connections_company_id_companies_id_fk' AND conrelid = 'ai_subscription_connections'::regclass) THEN
ALTER TABLE "ai_subscription_connections" ADD CONSTRAINT "ai_subscription_connections_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE cascade ON UPDATE no action;
END IF;
END $$;--> statement-breakpoint
DO $$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'ai_subscription_connections_connection_id_tool_connections_id_fk' AND conrelid = 'ai_subscription_connections'::regclass) THEN
ALTER TABLE "ai_subscription_connections" ADD CONSTRAINT "ai_subscription_connections_connection_id_tool_connections_id_fk" FOREIGN KEY ("connection_id") REFERENCES "public"."tool_connections"("id") ON DELETE cascade ON UPDATE no action;
END IF;
END $$;--> statement-breakpoint
DO $$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'ai_subscription_connections_grant_id_connection_grants_id_fk' AND conrelid = 'ai_subscription_connections'::regclass) THEN
ALTER TABLE "ai_subscription_connections" ADD CONSTRAINT "ai_subscription_connections_grant_id_connection_grants_id_fk" FOREIGN KEY ("grant_id") REFERENCES "public"."connection_grants"("id") ON DELETE cascade ON UPDATE no action;
END IF;
END $$;--> statement-breakpoint
DO $$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'ai_subscription_connections_subscription_id_ai_subscriptions_id_fk' AND conrelid = 'ai_subscription_connections'::regclass) THEN
ALTER TABLE "ai_subscription_connections" ADD CONSTRAINT "ai_subscription_connections_subscription_id_ai_subscriptions_id_fk" FOREIGN KEY ("subscription_id") REFERENCES "public"."ai_subscriptions"("id") ON DELETE cascade ON UPDATE no action;
END IF;
END $$;--> statement-breakpoint
DO $$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'ai_subscription_prices_company_id_companies_id_fk' AND conrelid = 'ai_subscription_prices'::regclass) THEN
ALTER TABLE "ai_subscription_prices" ADD CONSTRAINT "ai_subscription_prices_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE cascade ON UPDATE no action;
END IF;
END $$;--> statement-breakpoint
DO $$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'ai_subscription_prices_subscription_id_ai_subscriptions_id_fk' AND conrelid = 'ai_subscription_prices'::regclass) THEN
ALTER TABLE "ai_subscription_prices" ADD CONSTRAINT "ai_subscription_prices_subscription_id_ai_subscriptions_id_fk" FOREIGN KEY ("subscription_id") REFERENCES "public"."ai_subscriptions"("id") ON DELETE cascade ON UPDATE no action;
END IF;
END $$;--> statement-breakpoint
DO $$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'ai_subscriptions_company_id_companies_id_fk' AND conrelid = 'ai_subscriptions'::regclass) THEN
ALTER TABLE "ai_subscriptions" ADD CONSTRAINT "ai_subscriptions_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE cascade ON UPDATE no action;
END IF;
END $$;--> statement-breakpoint
DO $$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'ai_subscriptions_merged_into_id_ai_subscriptions_id_fk' AND conrelid = 'ai_subscriptions'::regclass) THEN
ALTER TABLE "ai_subscriptions" ADD CONSTRAINT "ai_subscriptions_merged_into_id_ai_subscriptions_id_fk" FOREIGN KEY ("merged_into_id") REFERENCES "public"."ai_subscriptions"("id") ON DELETE no action ON UPDATE no action;
END IF;
END $$;--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "ai_subscription_connections_grant_idx" ON "ai_subscription_connections" USING btree ("company_id","grant_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "ai_subscription_connections_credential_idx" ON "ai_subscription_connections" USING btree ("company_id","credential_key");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "ai_subscription_connections_account_idx" ON "ai_subscription_connections" USING btree ("company_id","subscription_id");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "ai_subscription_prices_revision_idx" ON "ai_subscription_prices" USING btree ("subscription_id","revision");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "ai_subscription_prices_company_idx" ON "ai_subscription_prices" USING btree ("company_id");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "ai_subscriptions_identity_idx" ON "ai_subscriptions" USING btree ("company_id","provider","account_key");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "ai_subscriptions_company_idx" ON "ai_subscriptions" USING btree ("company_id");--> statement-breakpoint
DO $$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'cost_events_subscription_id_ai_subscriptions_id_fk' AND conrelid = 'cost_events'::regclass) THEN
ALTER TABLE "cost_events" ADD CONSTRAINT "cost_events_subscription_id_ai_subscriptions_id_fk" FOREIGN KEY ("subscription_id") REFERENCES "public"."ai_subscriptions"("id") ON DELETE no action ON UPDATE no action;
END IF;
END $$;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "cost_events_company_subscription_occurred_idx" ON "cost_events" USING btree ("company_id","subscription_id","occurred_at");
File diff suppressed because it is too large. Load diff
@@ -1,6 +1,6 @@
{
"id": "d8438290-9b05-4959-ab7f-2097cfdd6ce3",
"prevId": "2242ec8f-2d13-46d2-99ed-cf97a52466d2",
"id": "677c8c43-8767-4e2b-9cc4-35a76061e6df",
"prevId": "3a76c99a-51c4-41d7-b7e2-12b55d8c7d08",
"version": "7",
"dialect": "postgresql",
"tables": {
@@ -3914,6 +3914,45 @@
"notNull": true,
"default": "'idle'"
},
"lifecycle_state": {
"name": "lifecycle_state",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'ready'"
},
"lifecycle_required_plugin_ids": {
"name": "lifecycle_required_plugin_ids",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"lifecycle_holds": {
"name": "lifecycle_holds",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'[]'::jsonb"
},
"lifecycle_version": {
"name": "lifecycle_version",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"lifecycle_error": {
"name": "lifecycle_error",
"type": "text",
"primaryKey": false,
"notNull": false
},
"lifecycle_operation": {
"name": "lifecycle_operation",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"reports_to": {
"name": "reports_to",
"type": "uuid",
@@ -4026,6 +4065,33 @@
}
},
"indexes": {
"agents_lifecycle_work_idx": {
"name": "agents_lifecycle_work_idx",
"columns": [
{
"expression": "lifecycle_state",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "updated_at",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"agents_company_status_idx": {
"name": "agents_company_status_idx",
"columns": [
@@ -4744,6 +4810,516 @@
},
"isRLSEnabled": false
},
"public.ai_subscription_connections": {
"name": "ai_subscription_connections",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"company_id": {
"name": "company_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"connection_id": {
"name": "connection_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"grant_id": {
"name": "grant_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"credential_key": {
"name": "credential_key",
"type": "text",
"primaryKey": false,
"notNull": true
},
"subscription_id": {
"name": "subscription_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
}
},
"indexes": {
"ai_subscription_connections_grant_idx": {
"name": "ai_subscription_connections_grant_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "grant_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"ai_subscription_connections_credential_idx": {
"name": "ai_subscription_connections_credential_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "credential_key",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"ai_subscription_connections_account_idx": {
"name": "ai_subscription_connections_account_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "subscription_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"ai_subscription_connections_company_id_companies_id_fk": {
"name": "ai_subscription_connections_company_id_companies_id_fk",
"tableFrom": "ai_subscription_connections",
"tableTo": "companies",
"columnsFrom": [
"company_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"ai_subscription_connections_connection_id_tool_connections_id_fk": {
"name": "ai_subscription_connections_connection_id_tool_connections_id_fk",
"tableFrom": "ai_subscription_connections",
"tableTo": "tool_connections",
"columnsFrom": [
"connection_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"ai_subscription_connections_grant_id_connection_grants_id_fk": {
"name": "ai_subscription_connections_grant_id_connection_grants_id_fk",
"tableFrom": "ai_subscription_connections",
"tableTo": "connection_grants",
"columnsFrom": [
"grant_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"ai_subscription_connections_subscription_id_ai_subscriptions_id_fk": {
"name": "ai_subscription_connections_subscription_id_ai_subscriptions_id_fk",
"tableFrom": "ai_subscription_connections",
"tableTo": "ai_subscriptions",
"columnsFrom": [
"subscription_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.ai_subscription_prices": {
"name": "ai_subscription_prices",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"company_id": {
"name": "company_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"subscription_id": {
"name": "subscription_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"revision": {
"name": "revision",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"plan": {
"name": "plan",
"type": "text",
"primaryKey": false,
"notNull": true
},
"amount_cents": {
"name": "amount_cents",
"type": "numeric(24, 7)",
"primaryKey": false,
"notNull": false
},
"currency": {
"name": "currency",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'USD'"
},
"cadence": {
"name": "cadence",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'month'"
},
"status": {
"name": "status",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'active'"
},
"source": {
"name": "source",
"type": "text",
"primaryKey": false,
"notNull": true
},
"source_url": {
"name": "source_url",
"type": "text",
"primaryKey": false,
"notNull": false
},
"effective_at": {
"name": "effective_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"ai_subscription_prices_revision_idx": {
"name": "ai_subscription_prices_revision_idx",
"columns": [
{
"expression": "subscription_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "revision",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"ai_subscription_prices_company_idx": {
"name": "ai_subscription_prices_company_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"ai_subscription_prices_company_id_companies_id_fk": {
"name": "ai_subscription_prices_company_id_companies_id_fk",
"tableFrom": "ai_subscription_prices",
"tableTo": "companies",
"columnsFrom": [
"company_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"ai_subscription_prices_subscription_id_ai_subscriptions_id_fk": {
"name": "ai_subscription_prices_subscription_id_ai_subscriptions_id_fk",
"tableFrom": "ai_subscription_prices",
"tableTo": "ai_subscriptions",
"columnsFrom": [
"subscription_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {
"ai_subscription_prices_valid": {
"name": "ai_subscription_prices_valid",
"value": "(\"ai_subscription_prices\".\"amount_cents\" is null or \"ai_subscription_prices\".\"amount_cents\" >= 0) and \"ai_subscription_prices\".\"cadence\" in ('month','year') and \"ai_subscription_prices\".\"status\" in ('active','ended','excluded') and \"ai_subscription_prices\".\"source\" in ('catalog','user','unknown')"
}
},
"isRLSEnabled": false
},
"public.ai_subscriptions": {
"name": "ai_subscriptions",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"company_id": {
"name": "company_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"provider": {
"name": "provider",
"type": "text",
"primaryKey": false,
"notNull": true
},
"account_key": {
"name": "account_key",
"type": "text",
"primaryKey": false,
"notNull": true
},
"identity_verified": {
"name": "identity_verified",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"owner_user_ids": {
"name": "owner_user_ids",
"type": "text[]",
"primaryKey": false,
"notNull": true,
"default": "'{}'::text[]"
},
"shared": {
"name": "shared",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"detected_plan": {
"name": "detected_plan",
"type": "text",
"primaryKey": false,
"notNull": false
},
"observed_at": {
"name": "observed_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"last_checked_at": {
"name": "last_checked_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"refresh_status": {
"name": "refresh_status",
"type": "text",
"primaryKey": false,
"notNull": false
},
"merged_into_id": {
"name": "merged_into_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"revision": {
"name": "revision",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"ai_subscriptions_identity_idx": {
"name": "ai_subscriptions_identity_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "provider",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "account_key",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"ai_subscriptions_company_idx": {
"name": "ai_subscriptions_company_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"ai_subscriptions_company_id_companies_id_fk": {
"name": "ai_subscriptions_company_id_companies_id_fk",
"tableFrom": "ai_subscriptions",
"tableTo": "companies",
"columnsFrom": [
"company_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"ai_subscriptions_merged_into_id_ai_subscriptions_id_fk": {
"name": "ai_subscriptions_merged_into_id_ai_subscriptions_id_fk",
"tableFrom": "ai_subscriptions",
"tableTo": "ai_subscriptions",
"columnsFrom": [
"merged_into_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {
"ai_subscriptions_no_self_merge": {
"name": "ai_subscriptions_no_self_merge",
"value": "\"ai_subscriptions\".\"merged_into_id\" is null or \"ai_subscriptions\".\"merged_into_id\" <> \"ai_subscriptions\".\"id\""
}
},
"isRLSEnabled": false
},
"public.announcement_dismissals": {
"name": "announcement_dismissals",
"schema": "",
@@ -9480,6 +10056,13 @@
"notNull": true,
"default": true
},
"require_at_mention": {
"name": "require_at_mention",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"allow_group_chats": {
"name": "allow_group_chats",
"type": "boolean",
@@ -11776,6 +12359,139 @@
},
"isRLSEnabled": false
},
"public.chat_slack_registrations": {
"name": "chat_slack_registrations",
"schema": "",
"columns": {
"endpoint_id": {
"name": "endpoint_id",
"type": "uuid",
"primaryKey": true,
"notNull": true
},
"company_id": {
"name": "company_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"request_id": {
"name": "request_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"status": {
"name": "status",
"type": "text",
"primaryKey": false,
"notNull": true
},
"manifest": {
"name": "manifest",
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"manifest_hash": {
"name": "manifest_hash",
"type": "text",
"primaryKey": false,
"notNull": true
},
"callback_uri": {
"name": "callback_uri",
"type": "text",
"primaryKey": false,
"notNull": true
},
"app_id": {
"name": "app_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"client_id": {
"name": "client_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"secret_ids": {
"name": "secret_ids",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'{}'::jsonb"
},
"workspace_id": {
"name": "workspace_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"bot_user_id": {
"name": "bot_user_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"error_code": {
"name": "error_code",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_by_user_id": {
"name": "created_by_user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"chat_slack_registrations_company_id_endpoint_id_chat_endpoints_company_id_id_fk": {
"name": "chat_slack_registrations_company_id_endpoint_id_chat_endpoints_company_id_id_fk",
"tableFrom": "chat_slack_registrations",
"tableTo": "chat_endpoints",
"columnsFrom": [
"company_id",
"endpoint_id"
],
"columnsTo": [
"company_id",
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {
"chat_slack_registration_status_check": {
"name": "chat_slack_registration_status_check",
"value": "\"chat_slack_registrations\".\"status\" in ('creating', 'uncertain', 'failed', 'install', 'credentials_saved', 'configured', 'removed')"
}
},
"isRLSEnabled": false
},
"public.chat_teams_file_transfers": {
"name": "chat_teams_file_transfers",
"schema": "",
@@ -17354,6 +18070,12 @@
"primaryKey": false,
"notNull": false
},
"subscription_id": {
"name": "subscription_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"billing_code": {
"name": "billing_code",
"type": "text",
@@ -17589,6 +18311,33 @@
"method": "btree",
"with": {}
},
"cost_events_company_subscription_occurred_idx": {
"name": "cost_events_company_subscription_occurred_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "subscription_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "occurred_at",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"cost_events_company_agent_occurred_idx": {
"name": "cost_events_company_agent_occurred_idx",
"columns": [
@@ -17770,6 +18519,19 @@
],
"onDelete": "no action",
"onUpdate": "no action"
},
"cost_events_subscription_id_ai_subscriptions_id_fk": {
"name": "cost_events_subscription_id_ai_subscriptions_id_fk",
"tableFrom": "cost_events",
"tableTo": "ai_subscriptions",
"columnsFrom": [
"subscription_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
@@ -56121,7 +56883,7 @@
"name": "expires_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
"notNull": false
},
"created_at": {
"name": "created_at",
@@ -1,6 +1,6 @@
{
"id": "7b6b177a-6067-4d7b-bc90-0300919e490b",
"prevId": "3a76c99a-51c4-41d7-b7e2-12b55d8c7d08",
"id": "675883cf-dc12-4e9e-a191-a405a4b09788",
"prevId": "677c8c43-8767-4e2b-9cc4-35a76061e6df",
"version": "7",
"dialect": "postgresql",
"tables": {
@@ -4810,6 +4810,516 @@
},
"isRLSEnabled": false
},
"public.ai_subscription_connections": {
"name": "ai_subscription_connections",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"company_id": {
"name": "company_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"connection_id": {
"name": "connection_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"grant_id": {
"name": "grant_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"credential_key": {
"name": "credential_key",
"type": "text",
"primaryKey": false,
"notNull": true
},
"subscription_id": {
"name": "subscription_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
}
},
"indexes": {
"ai_subscription_connections_grant_idx": {
"name": "ai_subscription_connections_grant_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "grant_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"ai_subscription_connections_credential_idx": {
"name": "ai_subscription_connections_credential_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "credential_key",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"ai_subscription_connections_account_idx": {
"name": "ai_subscription_connections_account_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "subscription_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"ai_subscription_connections_company_id_companies_id_fk": {
"name": "ai_subscription_connections_company_id_companies_id_fk",
"tableFrom": "ai_subscription_connections",
"tableTo": "companies",
"columnsFrom": [
"company_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"ai_subscription_connections_connection_id_tool_connections_id_fk": {
"name": "ai_subscription_connections_connection_id_tool_connections_id_fk",
"tableFrom": "ai_subscription_connections",
"tableTo": "tool_connections",
"columnsFrom": [
"connection_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"ai_subscription_connections_grant_id_connection_grants_id_fk": {
"name": "ai_subscription_connections_grant_id_connection_grants_id_fk",
"tableFrom": "ai_subscription_connections",
"tableTo": "connection_grants",
"columnsFrom": [
"grant_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"ai_subscription_connections_subscription_id_ai_subscriptions_id_fk": {
"name": "ai_subscription_connections_subscription_id_ai_subscriptions_id_fk",
"tableFrom": "ai_subscription_connections",
"tableTo": "ai_subscriptions",
"columnsFrom": [
"subscription_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.ai_subscription_prices": {
"name": "ai_subscription_prices",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"company_id": {
"name": "company_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"subscription_id": {
"name": "subscription_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"revision": {
"name": "revision",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"plan": {
"name": "plan",
"type": "text",
"primaryKey": false,
"notNull": true
},
"amount_cents": {
"name": "amount_cents",
"type": "numeric(24, 7)",
"primaryKey": false,
"notNull": false
},
"currency": {
"name": "currency",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'USD'"
},
"cadence": {
"name": "cadence",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'month'"
},
"status": {
"name": "status",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'active'"
},
"source": {
"name": "source",
"type": "text",
"primaryKey": false,
"notNull": true
},
"source_url": {
"name": "source_url",
"type": "text",
"primaryKey": false,
"notNull": false
},
"effective_at": {
"name": "effective_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"ai_subscription_prices_revision_idx": {
"name": "ai_subscription_prices_revision_idx",
"columns": [
{
"expression": "subscription_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "revision",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"ai_subscription_prices_company_idx": {
"name": "ai_subscription_prices_company_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"ai_subscription_prices_company_id_companies_id_fk": {
"name": "ai_subscription_prices_company_id_companies_id_fk",
"tableFrom": "ai_subscription_prices",
"tableTo": "companies",
"columnsFrom": [
"company_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"ai_subscription_prices_subscription_id_ai_subscriptions_id_fk": {
"name": "ai_subscription_prices_subscription_id_ai_subscriptions_id_fk",
"tableFrom": "ai_subscription_prices",
"tableTo": "ai_subscriptions",
"columnsFrom": [
"subscription_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {
"ai_subscription_prices_valid": {
"name": "ai_subscription_prices_valid",
"value": "(\"ai_subscription_prices\".\"amount_cents\" is null or \"ai_subscription_prices\".\"amount_cents\" >= 0) and \"ai_subscription_prices\".\"cadence\" in ('month','year') and \"ai_subscription_prices\".\"status\" in ('active','ended','excluded') and \"ai_subscription_prices\".\"source\" in ('catalog','user','unknown')"
}
},
"isRLSEnabled": false
},
"public.ai_subscriptions": {
"name": "ai_subscriptions",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"company_id": {
"name": "company_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"provider": {
"name": "provider",
"type": "text",
"primaryKey": false,
"notNull": true
},
"account_key": {
"name": "account_key",
"type": "text",
"primaryKey": false,
"notNull": true
},
"identity_verified": {
"name": "identity_verified",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"owner_user_ids": {
"name": "owner_user_ids",
"type": "text[]",
"primaryKey": false,
"notNull": true,
"default": "'{}'::text[]"
},
"shared": {
"name": "shared",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"detected_plan": {
"name": "detected_plan",
"type": "text",
"primaryKey": false,
"notNull": false
},
"observed_at": {
"name": "observed_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"last_checked_at": {
"name": "last_checked_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"refresh_status": {
"name": "refresh_status",
"type": "text",
"primaryKey": false,
"notNull": false
},
"merged_into_id": {
"name": "merged_into_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"revision": {
"name": "revision",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"ai_subscriptions_identity_idx": {
"name": "ai_subscriptions_identity_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "provider",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "account_key",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"ai_subscriptions_company_idx": {
"name": "ai_subscriptions_company_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"ai_subscriptions_company_id_companies_id_fk": {
"name": "ai_subscriptions_company_id_companies_id_fk",
"tableFrom": "ai_subscriptions",
"tableTo": "companies",
"columnsFrom": [
"company_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"ai_subscriptions_merged_into_id_ai_subscriptions_id_fk": {
"name": "ai_subscriptions_merged_into_id_ai_subscriptions_id_fk",
"tableFrom": "ai_subscriptions",
"tableTo": "ai_subscriptions",
"columnsFrom": [
"merged_into_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {
"ai_subscriptions_no_self_merge": {
"name": "ai_subscriptions_no_self_merge",
"value": "\"ai_subscriptions\".\"merged_into_id\" is null or \"ai_subscriptions\".\"merged_into_id\" <> \"ai_subscriptions\".\"id\""
}
},
"isRLSEnabled": false
},
"public.announcement_dismissals": {
"name": "announcement_dismissals",
"schema": "",
@@ -18821,6 +19331,12 @@
"primaryKey": false,
"notNull": false
},
"subscription_id": {
"name": "subscription_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"billing_code": {
"name": "billing_code",
"type": "text",
@@ -19056,6 +19572,33 @@
"method": "btree",
"with": {}
},
"cost_events_company_subscription_occurred_idx": {
"name": "cost_events_company_subscription_occurred_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "subscription_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "occurred_at",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"cost_events_company_agent_occurred_idx": {
"name": "cost_events_company_agent_occurred_idx",
"columns": [
@@ -19237,6 +19780,19 @@
],
"onDelete": "no action",
"onUpdate": "no action"
},
"cost_events_subscription_id_ai_subscriptions_id_fk": {
"name": "cost_events_subscription_id_ai_subscriptions_id_fk",
"tableFrom": "cost_events",
"tableTo": "ai_subscriptions",
"columnsFrom": [
"subscription_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
+21 -14
View File
@@ -2245,50 +2245,57 @@
{
"idx": 322,
"version": "7",
"when": 1791568503478,
"tag": "0322_long_franklin_storm",
"when": 1791572660423,
"tag": "0322_reflective_kree",
"breakpoints": true
},
{
"idx": 323,
"version": "7",
"when": 1791568503479,
"tag": "0323_aberrant_machine_man",
"when": 1791572660424,
"tag": "0323_long_franklin_storm",
"breakpoints": true
},
{
"idx": 324,
"version": "7",
"when": 1791568503480,
"tag": "0324_blushing_screwball",
"when": 1791572660425,
"tag": "0324_aberrant_machine_man",
"breakpoints": true
},
{
"idx": 325,
"version": "7",
"when": 1791568503481,
"tag": "0325_sad_proteus",
"when": 1791572660426,
"tag": "0325_blushing_screwball",
"breakpoints": true
},
{
"idx": 326,
"version": "7",
"when": 1791568503482,
"tag": "0326_chunky_mentallo",
"when": 1791572660427,
"tag": "0326_sad_proteus",
"breakpoints": true
},
{
"idx": 327,
"version": "7",
"when": 1791568503483,
"tag": "0327_free_wolf_cub",
"when": 1791572660428,
"tag": "0327_chunky_mentallo",
"breakpoints": true
},
{
"idx": 328,
"version": "7",
"when": 1791568503484,
"tag": "0328_spooky_white_tiger",
"when": 1791572660429,
"tag": "0328_free_wolf_cub",
"breakpoints": true
},
{
"idx": 329,
"version": "7",
"when": 1791572660430,
"tag": "0329_spooky_white_tiger",
"breakpoints": true
}
]
@@ -0,0 +1,63 @@
import { sql } from "drizzle-orm";
import { pgTable, uuid, text, timestamp, boolean, integer, numeric, index, uniqueIndex, check, type AnyPgColumn } from "drizzle-orm/pg-core";
import { companies } from "./companies.js";
import { connectionGrants, toolConnections } from "./tool_access.js";
/** An estimate of a recurring account fee, deliberately separate from receipts. */
export const aiSubscriptions = pgTable("ai_subscriptions", {
id: uuid("id").primaryKey().defaultRandom(),
companyId: uuid("company_id").notNull().references(() => companies.id, { onDelete: "cascade" }),
provider: text("provider").notNull(),
// Company-scoped digest of provider account AND seat, or an unverified credential.
accountKey: text("account_key").notNull(),
identityVerified: boolean("identity_verified").notNull().default(false),
name: text("name").notNull(),
// A paid seat can be connected personally and shared. Retain all billing
// editors even after a connection is deleted; disconnecting is not cancellation.
ownerUserIds: text("owner_user_ids").array().notNull().default(sql`'{}'::text[]`),
shared: boolean("shared").notNull().default(false),
detectedPlan: text("detected_plan"),
observedAt: timestamp("observed_at", { withTimezone: true }),
lastCheckedAt: timestamp("last_checked_at", { withTimezone: true }),
refreshStatus: text("refresh_status").$type<"ok" | "unavailable">(),
mergedIntoId: uuid("merged_into_id").references((): AnyPgColumn => aiSubscriptions.id),
revision: integer("revision").notNull().default(0),
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
}, table => ({
identity: uniqueIndex("ai_subscriptions_identity_idx").on(table.companyId, table.provider, table.accountKey),
company: index("ai_subscriptions_company_idx").on(table.companyId),
noSelfMerge: check("ai_subscriptions_no_self_merge", sql`${table.mergedIntoId} is null or ${table.mergedIntoId} <> ${table.id}`),
}));
export const aiSubscriptionPrices = pgTable("ai_subscription_prices", {
id: uuid("id").primaryKey().defaultRandom(),
companyId: uuid("company_id").notNull().references(() => companies.id, { onDelete: "cascade" }),
subscriptionId: uuid("subscription_id").notNull().references(() => aiSubscriptions.id, { onDelete: "cascade" }),
revision: integer("revision").notNull(),
plan: text("plan").notNull(),
amountCents: numeric("amount_cents", { precision: 24, scale: 7 }),
currency: text("currency").notNull().default("USD"),
cadence: text("cadence").$type<"month" | "year">().notNull().default("month"),
status: text("status").$type<"active" | "ended" | "excluded">().notNull().default("active"),
source: text("source").$type<"catalog" | "user" | "unknown">().notNull(),
sourceUrl: text("source_url"),
effectiveAt: timestamp("effective_at", { withTimezone: true }).notNull().defaultNow(),
}, table => ({
version: uniqueIndex("ai_subscription_prices_revision_idx").on(table.subscriptionId, table.revision),
company: index("ai_subscription_prices_company_idx").on(table.companyId),
valid: check("ai_subscription_prices_valid", sql`(${table.amountCents} is null or ${table.amountCents} >= 0) and ${table.cadence} in ('month','year') and ${table.status} in ('active','ended','excluded') and ${table.source} in ('catalog','user','unknown')`),
}));
/** Current credential-to-account binding. Runs snapshot the subscription ID. */
export const aiSubscriptionConnections = pgTable("ai_subscription_connections", {
id: uuid("id").primaryKey().defaultRandom(),
companyId: uuid("company_id").notNull().references(() => companies.id, { onDelete: "cascade" }),
connectionId: uuid("connection_id").notNull().references(() => toolConnections.id, { onDelete: "cascade" }),
grantId: uuid("grant_id").notNull().references(() => connectionGrants.id, { onDelete: "cascade" }),
credentialKey: text("credential_key").notNull(),
subscriptionId: uuid("subscription_id").notNull().references(() => aiSubscriptions.id, { onDelete: "cascade" }),
}, table => ({
grant: uniqueIndex("ai_subscription_connections_grant_idx").on(table.companyId, table.grantId),
credential: index("ai_subscription_connections_credential_idx").on(table.companyId, table.credentialKey),
account: index("ai_subscription_connections_account_idx").on(table.companyId, table.subscriptionId),
}));
+3
View File
@@ -6,6 +6,7 @@ import { issues } from "./issues.js";
import { projects } from "./projects.js";
import { goals } from "./goals.js";
import { heartbeatRuns } from "./heartbeat_runs.js";
import { aiSubscriptions } from "./ai_subscriptions.js";
export const costEvents = pgTable(
"cost_events",
@@ -19,6 +20,7 @@ export const costEvents = pgTable(
projectId: uuid("project_id").references(() => projects.id),
goalId: uuid("goal_id").references(() => goals.id),
heartbeatRunId: uuid("heartbeat_run_id").references(() => heartbeatRuns.id),
subscriptionId: uuid("subscription_id").references(() => aiSubscriptions.id),
billingCode: text("billing_code"),
idempotencyKey: text("idempotency_key"),
receiptHash: text("receipt_hash"),
@@ -45,6 +47,7 @@ export const costEvents = pgTable(
companyProjectOccurredIdx: index("cost_events_company_project_occurred_idx").on(table.companyId, table.projectId, table.occurredAt),
unpricedIdx: index("cost_events_unpriced_idx").on(table.companyId, table.occurredAt, table.id).where(sql`${table.costStatus} = 'unpriced' and ${table.billingType} <> 'subscription_included'`),
companyOccurredIdx: index("cost_events_company_occurred_idx").on(table.companyId, table.occurredAt),
companySubscriptionOccurredIdx: index("cost_events_company_subscription_occurred_idx").on(table.companyId, table.subscriptionId, table.occurredAt),
companyAgentOccurredIdx: index("cost_events_company_agent_occurred_idx").on(
table.companyId,
table.agentId,
+1
View File
@@ -243,3 +243,4 @@ export { chatVoiceReports } from "./chat_voice_reports.js";
export { chatVoicePhoneLines, chatVoiceInboundCalls } from "./chat_voice_inbound.js";
export * from "./decision_models.js";
export { userCompanyPreferences } from "./user_company_preferences.js";
export { aiSubscriptions, aiSubscriptionPrices, aiSubscriptionConnections } from "./ai_subscriptions.js";
@@ -30,7 +30,7 @@ const support = await getEmbeddedPostgresTestSupport();
await sql.unsafe(`ALTER TABLE ${table} DROP CONSTRAINT ${name}`);
await sql.unsafe(`ALTER TABLE ${table} ADD CONSTRAINT ${name} CHECK (${definition})`);
}
for (const name of ["0322_long_franklin_storm.sql", "0323_aberrant_machine_man.sql", "0324_blushing_screwball.sql", "0325_sad_proteus.sql", "0326_chunky_mentallo.sql", "0327_free_wolf_cub.sql", "0328_spooky_white_tiger.sql"]) {
for (const name of ["0323_long_franklin_storm.sql", "0324_aberrant_machine_man.sql", "0325_blushing_screwball.sql", "0326_sad_proteus.sql", "0327_chunky_mentallo.sql", "0328_free_wolf_cub.sql", "0329_spooky_white_tiger.sql"]) {
const migration = await readFile(new URL(`./migrations/${name}`, import.meta.url), "utf8");
const hash = createHash("sha256").update(migration).digest("hex");
await sql`DELETE FROM drizzle.__drizzle_migrations WHERE hash = ${hash}`;
@@ -71,7 +71,7 @@ const support = await getEmbeddedPostgresTestSupport();
await applyPendingMigrations(database.connectionString);
// Existing installations have older migration hashes after renumbering.
// Force each stage to execute again while preserving the actual saved rows.
for (const name of ["0322_long_franklin_storm.sql", "0323_aberrant_machine_man.sql", "0324_blushing_screwball.sql", "0325_sad_proteus.sql", "0326_chunky_mentallo.sql", "0327_free_wolf_cub.sql", "0328_spooky_white_tiger.sql"]) {
for (const name of ["0323_long_franklin_storm.sql", "0324_aberrant_machine_man.sql", "0325_blushing_screwball.sql", "0326_sad_proteus.sql", "0327_chunky_mentallo.sql", "0328_free_wolf_cub.sql", "0329_spooky_white_tiger.sql"]) {
const migration = await readFile(new URL(`./migrations/${name}`, import.meta.url), "utf8");
const hash = createHash("sha256").update(migration).digest("hex");
await sql`DELETE FROM drizzle.__drizzle_migrations WHERE hash = ${hash}`;
+2
View File
@@ -144,6 +144,8 @@ export type AiConnectionUnavailableReason =
| "access_denied"
| "credential_missing";
export interface AiConnectionAttribution {
/** Billing account at execution time; never resolved again from mutable settings. */
subscriptionId?: string;
connectionId: string;
grantId: string;
provider: AiProvider;
+4
View File
@@ -1,3 +1,5 @@
import type { AgentLifecycleState } from "./types/agent-lifecycle.js";
/** JSON responses for the operator-owned Dot invitation flow. Pairing capabilities are transient. */
export interface DotBinding {
id: string;
@@ -17,6 +19,8 @@ export interface DotConnection {
enabled: boolean;
resourceUrl: string | null;
agentStatus: string;
agentLifecycleState: AgentLifecycleState;
canConfigureConnection: boolean;
binding: DotBinding | null;
}
export interface DotPairing { bindingId: string; pairingCode: string; expiresAt: string }
+1
View File
@@ -2811,6 +2811,7 @@ export * from "./agent-appearance.js";
export * from "./ai-connections.js";
export * from "./ai-connection-router.js";
export * from "./ai-connection-usage.js";
export * from "./subscriptions.js";
export * from "./types/email.js";
export * from "./validators/email.js";
export { configureRailwaySshSchema, type ConfigureRailwaySsh, type RailwaySshSetup } from "./railway-connection.js";
+112
View File
@@ -0,0 +1,112 @@
import { z } from "zod";
import { exactCentsSchema } from "./accounting.js";
import { centsToUnits, unitsToCents } from "./money.js";
export const SUBSCRIPTION_CURRENCIES = ["USD", "EUR", "GBP", "CAD", "AUD", "CHF"] as const;
export const subscriptionPriceSchema = z.object({
expectedRevision: z.number().int().nonnegative(),
plan: z.string().trim().min(1).max(100),
amountCents: exactCentsSchema.nullable(),
currency: z.enum(SUBSCRIPTION_CURRENCIES),
cadence: z.enum(["month", "year"]),
status: z.enum(["active", "ended", "excluded"]),
}).strict();
export type UpdateSubscriptionPrice = z.input<typeof subscriptionPriceSchema>;
export const mergeSubscriptionsSchema = z.object({
targetId: z.string().uuid(),
expectedRevision: z.number().int().nonnegative(),
targetRevision: z.number().int().nonnegative(),
}).strict();
export interface SubscriptionPlan {
id: string;
provider: string;
name: string;
monthlyCents: string;
currency: "USD";
sourceUrl: string;
checkedAt: string;
}
// Web list prices, before tax, assuming monthly billing. These are estimates,
// never invoices. Generic Pro/Max/team entitlements do not identify a price.
export const SUBSCRIPTION_PLANS: readonly SubscriptionPlan[] = [
["openai", "free", "ChatGPT Free", "0", "https://learn.chatgpt.com/docs/pricing"],
["openai", "go", "ChatGPT Go", "800", "https://learn.chatgpt.com/docs/pricing"],
["openai", "plus", "ChatGPT Plus", "2000", "https://learn.chatgpt.com/docs/pricing"],
["anthropic", "pro", "Claude Pro", "2000", "https://claude.com/pricing"],
["anthropic", "max_5x", "Claude Max 5x", "10000", "https://claude.com/pricing"],
["anthropic", "max_20x", "Claude Max 20x", "20000", "https://claude.com/pricing"],
["xai", "supergrok", "SuperGrok", "3000", "https://x.ai/pricing"],
["xai", "supergrok_plus", "SuperGrok Plus", "10000", "https://x.ai/pricing"],
].map(([provider, id, name, monthlyCents, sourceUrl]) => ({
provider, id, name, monthlyCents, sourceUrl, currency: "USD", checkedAt: "2026-10-08",
}));
export function subscriptionPlan(provider: string, plan: string | null): SubscriptionPlan | null {
const key = plan?.trim().toLowerCase().replaceAll(" ", "_");
return SUBSCRIPTION_PLANS.find(item => item.provider === provider && item.id === key) ?? null;
}
export function monthlySubscriptionCents(amount: string, cadence: "month" | "year"): string {
const units = centsToUnits(amount);
return unitsToCents(cadence === "year" ? (units + 6n) / 12n : units);
}
export interface SubscriptionPrice {
revision: number;
plan: string;
amountCents: string | null;
monthlyCents: string | null;
currency: string;
cadence: "month" | "year";
status: "active" | "ended" | "excluded";
source: "catalog" | "user" | "unknown";
sourceUrl: string | null;
effectiveAt: string;
}
export interface SubscriptionUsage {
inputTokens: number;
cachedInputTokens: number;
outputTokens: number;
costCents: string;
eventCount: number;
estimatedEventCount: number;
unpricedEventCount: number;
}
export interface SubscriptionAccountReport {
id: string;
provider: string;
name: string;
ownerUserId: string | null;
ownerName: string | null;
shared: boolean;
identityVerified: boolean;
detectedPlan: string | null;
observedAt: string | null;
lastCheckedAt: string | null;
refreshStatus: "ok" | "unavailable" | null;
canEdit: boolean;
price: SubscriptionPrice;
usage: SubscriptionUsage;
agents: { id: string; name: string }[];
}
export interface SubscriptionCostReport {
canRefresh: boolean;
/** Current monthly commitment for accounts visible to the caller;
* independent of the usage date filter. Aggregate run usage is company-wide. */
asOf: string;
accounts: SubscriptionAccountReport[];
monthlyTotals: { currency: string; amountCents: string; estimatedCount: number }[];
activeCount: number;
unknownPriceCount: number;
unidentifiedAccountCount: number;
api: SubscriptionUsage;
subscription: SubscriptionUsage;
/** Other billing types (credits, fixed, or unknown), outside API/subscription totals. */
unknown: SubscriptionUsage;
unattributedSubscription: SubscriptionUsage;
}
+4
View File
@@ -2,6 +2,7 @@ import type { AgentAppearance } from "../agent-appearance.js";
import type { BillingType, CostStatus } from "../constants.js";
export interface CostEvent {
subscriptionId?: string | null;
usageKind?: "agent" | "decision";
responsibleUserId?: string | null;
id: string;
@@ -174,6 +175,9 @@ export interface CostWindowSpendRow {
export interface CostByProject {
projectId: string | null;
projectName: string | null;
/** Ledger events in this project and selected date range, not distinct runs. */
eventCount: number;
estimatedEventCount: number;
costCents: number;
costCentsExact?: string;
inputTokens: number;