Skip to content

GeneratedSaasFoundations — 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.ProductTenants

Owner: ProductTenant

CREATE TABLE [dbo].[ProductTenants] (
    [ProductTenantId] nvarchar(64) NOT NULL,
    [TenantId] nvarchar(64) NOT NULL,
    [CustomerTenantId] nvarchar(64) NOT NULL,
    [Name] nvarchar(128) NOT NULL,
    [IsolationMode] nvarchar(32) NOT NULL,
    [Region] nvarchar(32) NOT NULL,
    [State] int NOT NULL,
    [CreatedAt] datetimeoffset NOT NULL,
    CONSTRAINT [PK_ProductTenants] PRIMARY KEY ([ProductTenantId])
);
CREATE UNIQUE INDEX [UX_ProductTenants_Customer] ON [dbo].[ProductTenants] ([TenantId], [CustomerTenantId]);
Column Type Null Key Description
ProductTenantId nvarchar(64) no PK
TenantId nvarchar(64) no The Factory tenant (factoryTenantId).
CustomerTenantId nvarchar(64) no
Name nvarchar(128) no
IsolationMode nvarchar(32) no
Region nvarchar(32) no
State int no
CreatedAt datetimeoffset no

dbo.ProductSubscriptions

Owner: ProductSubscription

CREATE TABLE [dbo].[ProductSubscriptions] (
    [SubscriptionId] uniqueidentifier NOT NULL,
    [ProductTenantId] nvarchar(64) NOT NULL,
    [TenantId] nvarchar(64) NOT NULL,
    [Edition] nvarchar(32) NOT NULL,
    [EntitlementsJson] nvarchar(max) NOT NULL,
    [Seats] int NULL,
    [MeteringDimensionsJson] nvarchar(512) NOT NULL,
    [State] nvarchar(16) NOT NULL,
    [ChangedAt] datetimeoffset NOT NULL,
    CONSTRAINT [PK_ProductSubscriptions] PRIMARY KEY ([SubscriptionId])
);
ALTER TABLE [dbo].[ProductSubscriptions] ADD CONSTRAINT [FK_ProductSubscriptions_ProductTenants_ProductTenantId] FOREIGN KEY ([ProductTenantId]) REFERENCES [dbo].[ProductTenants] ([ProductTenantId]);
Column Type Null Key Description
SubscriptionId uniqueidentifier no PK
ProductTenantId nvarchar(64) no FK → ProductTenants.ProductTenantId
TenantId nvarchar(64) no
Edition nvarchar(32) no
EntitlementsJson nvarchar(max) no
Seats int yes
MeteringDimensionsJson nvarchar(512) no
State nvarchar(16) no
ChangedAt datetimeoffset no

dbo.ProductUsage

Owner: ProductSubscription

CREATE TABLE [dbo].[ProductUsage] (
    [SubscriptionId] uniqueidentifier NOT NULL,
    [Dimension] nvarchar(32) NOT NULL,
    [Period] nvarchar(16) NOT NULL,
    [TenantId] nvarchar(64) NOT NULL,
    [Quantity] decimal(18,4) NOT NULL,
    [ReconciledAt] datetimeoffset NULL,
    CONSTRAINT [PK_ProductUsage] PRIMARY KEY ([SubscriptionId], [Dimension], [Period])
);
ALTER TABLE [dbo].[ProductUsage] ADD CONSTRAINT [FK_ProductUsage_ProductSubscriptions_SubscriptionId] FOREIGN KEY ([SubscriptionId]) REFERENCES [dbo].[ProductSubscriptions] ([SubscriptionId]);
Column Type Null Key Description
SubscriptionId uniqueidentifier no PK FK → ProductSubscriptions.SubscriptionId
Dimension nvarchar(32) no PK
Period nvarchar(16) no PK
TenantId nvarchar(64) no
Quantity decimal(18,4) no
ReconciledAt datetimeoffset yes