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 <noreply@anthropic.com>
This commit is contained in:
parent
9ed80cd0bc
commit
a58417d092
|
|
@ -26,7 +26,7 @@ CREATE TABLE IF NOT EXISTS billing_plans (
|
||||||
-- Subscriptions
|
-- Subscriptions
|
||||||
CREATE TABLE IF NOT EXISTS billing_subscriptions (
|
CREATE TABLE IF NOT EXISTS billing_subscriptions (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
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),
|
plan_id UUID NOT NULL REFERENCES billing_plans(id),
|
||||||
status VARCHAR(20) NOT NULL DEFAULT 'trialing',
|
status VARCHAR(20) NOT NULL DEFAULT 'trialing',
|
||||||
current_period_start TIMESTAMPTZ NOT NULL,
|
current_period_start TIMESTAMPTZ NOT NULL,
|
||||||
|
|
@ -46,7 +46,7 @@ CREATE INDEX IF NOT EXISTS idx_billing_subs_period_end ON billing_subscriptions(
|
||||||
-- Invoices
|
-- Invoices
|
||||||
CREATE TABLE IF NOT EXISTS billing_invoices (
|
CREATE TABLE IF NOT EXISTS billing_invoices (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
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),
|
subscription_id UUID REFERENCES billing_subscriptions(id),
|
||||||
invoice_number VARCHAR(50) NOT NULL UNIQUE,
|
invoice_number VARCHAR(50) NOT NULL UNIQUE,
|
||||||
status VARCHAR(20) NOT NULL DEFAULT 'open', -- open, paid, void, past_due, uncollectible
|
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
|
-- Payments
|
||||||
CREATE TABLE IF NOT EXISTS billing_payments (
|
CREATE TABLE IF NOT EXISTS billing_payments (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
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),
|
invoice_id UUID NOT NULL REFERENCES billing_invoices(id),
|
||||||
provider VARCHAR(20) NOT NULL, -- stripe, alipay, wechat_pay, crypto
|
provider VARCHAR(20) NOT NULL, -- stripe, alipay, wechat_pay, crypto
|
||||||
provider_payment_id VARCHAR(255) NOT NULL UNIQUE,
|
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
|
-- Payment Methods
|
||||||
CREATE TABLE IF NOT EXISTS billing_payment_methods (
|
CREATE TABLE IF NOT EXISTS billing_payment_methods (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
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,
|
provider VARCHAR(20) NOT NULL,
|
||||||
display_name VARCHAR(200) NOT NULL,
|
display_name VARCHAR(200) NOT NULL,
|
||||||
provider_customer_id VARCHAR(255),
|
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
|
-- Monthly Usage Aggregates
|
||||||
CREATE TABLE IF NOT EXISTS billing_usage_aggregates (
|
CREATE TABLE IF NOT EXISTS billing_usage_aggregates (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
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,
|
year INTEGER NOT NULL,
|
||||||
month INTEGER NOT NULL, -- 1-12
|
month INTEGER NOT NULL, -- 1-12
|
||||||
period_start TIMESTAMPTZ NOT NULL,
|
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);
|
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
|
-- 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 public.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_agent_tokens_per_month BIGINT NOT NULL DEFAULT 100000;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,10 @@ export const TEST_TENANT: TenantInfo = {
|
||||||
tenantName: 'Test Tenant',
|
tenantName: 'Test Tenant',
|
||||||
plan: 'enterprise',
|
plan: 'enterprise',
|
||||||
schemaName: 'it0_t_test',
|
schemaName: 'it0_t_test',
|
||||||
|
maxServers: -1,
|
||||||
|
maxUsers: -1,
|
||||||
|
maxStandingOrders: -1,
|
||||||
|
maxAgentTokensPerMonth: -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function withTenant<T>(fn: () => T, tenant: TenantInfo = TEST_TENANT): T {
|
export function withTenant<T>(fn: () => T, tenant: TenantInfo = TEST_TENANT): T {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue