Skip to content

FactoryCommercialService — DDL appendix

Generated from the architecture model

This page is rendered from model/**/*.yaml by tools/docs_model during mkdocs build. Edit the YAML, not this page; hand-written design lives on the linked service, platform and plane pages.

Dialect shown: SQL Server (nvarchar, uniqueidentifier, datetimeoffset). Migrations are authored as FluentMigrator classes in the service's DatabaseModel.Migrations project; the TenantId column and the NHibernate tenant filter follow canonical ADR-0100 in SharedDb mode.

dbo.FactorySubscriptions

Owner: FactorySubscription

CREATE TABLE [dbo].[FactorySubscriptions] (
    [SubscriptionId] uniqueidentifier NOT NULL,
    [TenantId] nvarchar(64) NOT NULL,
    [Edition] int NOT NULL,
    [EditionReleaseId] nvarchar(256) NOT NULL,
    [Seats] int NOT NULL,
    [State] int NOT NULL,
    [BillingModel] nvarchar(32) NOT NULL,
    [CurrentPeriodStart] datetimeoffset NOT NULL,
    [CurrentPeriodEnd] datetimeoffset NOT NULL,
    [Version] rowversion NOT NULL,
    CONSTRAINT [PK_FactorySubscriptions] PRIMARY KEY ([SubscriptionId])
);
CREATE UNIQUE INDEX [UX_FactorySubscriptions_Tenant_Active] ON [dbo].[FactorySubscriptions] ([TenantId]) WHERE State IN (0,1,2,3);
Column Type Null Key Description
SubscriptionId uniqueidentifier no PK
TenantId nvarchar(64) no
Edition int no
EditionReleaseId nvarchar(256) no
Seats int no
State int no
BillingModel nvarchar(32) no
CurrentPeriodStart datetimeoffset no
CurrentPeriodEnd datetimeoffset no
Version rowversion no

dbo.Invoices

Owner: Invoice · Retention: 7 years (D31)

CREATE TABLE [dbo].[Invoices] (
    [InvoiceId] uniqueidentifier NOT NULL,
    [SubscriptionId] uniqueidentifier NOT NULL,
    [TenantId] nvarchar(64) NOT NULL,
    [PeriodStart] datetimeoffset NOT NULL,
    [PeriodEnd] datetimeoffset NOT NULL,
    [TotalUsd] decimal(18,4) NOT NULL,
    [State] nvarchar(16) NOT NULL,
    [UsageSnapshotRef] nvarchar(512) NOT NULL,
    CONSTRAINT [PK_Invoices] PRIMARY KEY ([InvoiceId])
);
ALTER TABLE [dbo].[Invoices] ADD CONSTRAINT [FK_Invoices_FactorySubscriptions_SubscriptionId] FOREIGN KEY ([SubscriptionId]) REFERENCES [dbo].[FactorySubscriptions] ([SubscriptionId]);
Column Type Null Key Description
InvoiceId uniqueidentifier no PK
SubscriptionId uniqueidentifier no FK → FactorySubscriptions.SubscriptionId
TenantId nvarchar(64) no
PeriodStart datetimeoffset no
PeriodEnd datetimeoffset no
TotalUsd decimal(18,4) no
State nvarchar(16) no
UsageSnapshotRef nvarchar(512) no