From a58417d0928498fbee5eb7077264d10f15accacf Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 3 Mar 2026 21:22:02 -0800 Subject: [PATCH] fix: correct billing migration schema refs and testing mock TenantInfo - 005-create-billing-tables.sql: replace all `it0_shared.tenants` with `public.tenants` and all `tenant_id VARCHAR(20)` with `tenant_id UUID` to match the actual server DB schema (public schema, UUID primary key) - packages/shared/testing src/test-utils.ts: add new quota fields (maxServers, maxUsers, maxStandingOrders, maxAgentTokensPerMonth) to TEST_TENANT mock to satisfy the extended TenantInfo interface, fixing the @it0/testing TypeScript build error Co-Authored-By: Claude Sonnet 4.6 --- .../src/migrations/005-create-billing-tables.sql | 14 +++++++------- packages/shared/testing/src/test-utils.ts | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/shared/database/src/migrations/005-create-billing-tables.sql b/packages/shared/database/src/migrations/005-create-billing-tables.sql index 4af58c1..4de0c3f 100644 --- a/packages/shared/database/src/migrations/005-create-billing-tables.sql +++ b/packages/shared/database/src/migrations/005-create-billing-tables.sql @@ -26,7 +26,7 @@ CREATE TABLE IF NOT EXISTS billing_plans ( -- Subscriptions CREATE TABLE IF NOT EXISTS billing_subscriptions ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - tenant_id VARCHAR(20) NOT NULL REFERENCES it0_shared.tenants(id), + tenant_id UUID NOT NULL REFERENCES public.tenants(id), plan_id UUID NOT NULL REFERENCES billing_plans(id), status VARCHAR(20) NOT NULL DEFAULT 'trialing', current_period_start TIMESTAMPTZ NOT NULL, @@ -46,7 +46,7 @@ CREATE INDEX IF NOT EXISTS idx_billing_subs_period_end ON billing_subscriptions( -- Invoices CREATE TABLE IF NOT EXISTS billing_invoices ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - tenant_id VARCHAR(20) NOT NULL REFERENCES it0_shared.tenants(id), + tenant_id UUID NOT NULL REFERENCES public.tenants(id), subscription_id UUID REFERENCES billing_subscriptions(id), invoice_number VARCHAR(50) NOT NULL UNIQUE, status VARCHAR(20) NOT NULL DEFAULT 'open', -- open, paid, void, past_due, uncollectible @@ -84,7 +84,7 @@ CREATE INDEX IF NOT EXISTS idx_billing_items_invoice ON billing_invoice_items(in -- Payments CREATE TABLE IF NOT EXISTS billing_payments ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - tenant_id VARCHAR(20) NOT NULL REFERENCES it0_shared.tenants(id), + tenant_id UUID NOT NULL REFERENCES public.tenants(id), invoice_id UUID NOT NULL REFERENCES billing_invoices(id), provider VARCHAR(20) NOT NULL, -- stripe, alipay, wechat_pay, crypto provider_payment_id VARCHAR(255) NOT NULL UNIQUE, @@ -103,7 +103,7 @@ CREATE INDEX IF NOT EXISTS idx_billing_payments_provider_id ON billing_payments( -- Payment Methods CREATE TABLE IF NOT EXISTS billing_payment_methods ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - tenant_id VARCHAR(20) NOT NULL REFERENCES it0_shared.tenants(id), + tenant_id UUID NOT NULL REFERENCES public.tenants(id), provider VARCHAR(20) NOT NULL, display_name VARCHAR(200) NOT NULL, provider_customer_id VARCHAR(255), @@ -119,7 +119,7 @@ CREATE INDEX IF NOT EXISTS idx_billing_methods_tenant ON billing_payment_methods -- Monthly Usage Aggregates CREATE TABLE IF NOT EXISTS billing_usage_aggregates ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - tenant_id VARCHAR(20) NOT NULL REFERENCES it0_shared.tenants(id), + tenant_id UUID NOT NULL REFERENCES public.tenants(id), year INTEGER NOT NULL, month INTEGER NOT NULL, -- 1-12 period_start TIMESTAMPTZ NOT NULL, @@ -137,5 +137,5 @@ CREATE TABLE IF NOT EXISTS billing_usage_aggregates ( CREATE INDEX IF NOT EXISTS idx_billing_usage_tenant_period ON billing_usage_aggregates(tenant_id, year, month); -- Add max_standing_orders column to tenants if missing -ALTER TABLE it0_shared.tenants ADD COLUMN IF NOT EXISTS max_standing_orders INTEGER NOT NULL DEFAULT 10; -ALTER TABLE it0_shared.tenants ADD COLUMN IF NOT EXISTS max_agent_tokens_per_month BIGINT NOT NULL DEFAULT 100000; +ALTER TABLE public.tenants ADD COLUMN IF NOT EXISTS max_standing_orders INTEGER NOT NULL DEFAULT 10; +ALTER TABLE public.tenants ADD COLUMN IF NOT EXISTS max_agent_tokens_per_month BIGINT NOT NULL DEFAULT 100000; diff --git a/packages/shared/testing/src/test-utils.ts b/packages/shared/testing/src/test-utils.ts index 49a799b..87f4c69 100644 --- a/packages/shared/testing/src/test-utils.ts +++ b/packages/shared/testing/src/test-utils.ts @@ -6,6 +6,10 @@ export const TEST_TENANT: TenantInfo = { tenantName: 'Test Tenant', plan: 'enterprise', schemaName: 'it0_t_test', + maxServers: -1, + maxUsers: -1, + maxStandingOrders: -1, + maxAgentTokensPerMonth: -1, }; export function withTenant(fn: () => T, tenant: TenantInfo = TEST_TENANT): T {