text: ﻿-- <auto-generated>
  --   This code was generated by a tool.
  --   Changes to this file may cause incorrect behaviour and will be lost if the code is regenerated.
  -- </auto-generated>
  
  
  /*
   * TABLE: TenantStore.TENANT
   *
   * */
  
  -- USE <database-name>
  -- GO
  
  -- DROP TABLE [TenantStore].[TENANT]
  -- GO
  
  CREATE TABLE [TenantStore].[TENANT] (
        [ID] INT NOT NULL
      , [RING] INT NOT NULL
      , [NAME] VARCHAR(128) NOT NULL
      , [DISPLAYNAME] NVARCHAR(260) NOT NULL
      , [EMAIL] NVARCHAR(260) NOT NULL
      , [CULTURE] VARCHAR(10) NOT NULL
      , [MAILSERVER_ID] VARCHAR(50) NULL
      , [MAIL_FROM_ADDRESS] NVARCHAR(256) NULL
      , [MAIL_FROM_NAME] NVARCHAR(256) NULL
      , [DBSERVER_ID] VARCHAR(50) NULL
      , [DATABASENAME] VARCHAR(MAX) NULL
      , [DATABASEUSER] VARCHAR(MAX) NULL
      , [DATABASEPASS] VARCHAR(MAX) NULL
      , [PSTATE] VARCHAR(20) NOT NULL CONSTRAINT [CK_TENANT_PSTATE] CHECK ( PSTATE IN ('Pending', 'Provisioning', 'Failed', 'Provisioned') )
      , [SSTATE] VARCHAR(10) NOT NULL CONSTRAINT [CK_TENANT_SSTATE] CHECK ( SSTATE IN ('Active', 'Inactive', 'Trial') )
      , [SSTATECOMMENT] TEXT NULL
      , [TDURATIONDAYS] INT NULL
      , [TSTARTEDUTC] DATETIME NULL
      , [TENDSUTC] DATETIME NULL
      , CONSTRAINT [PK_TENANT] PRIMARY KEY NONCLUSTERED ( [ID] )
  )
  GO
  
  CREATE UNIQUE NONCLUSTERED INDEX [IX_TENANT_1] ON [TenantStore].[TENANT] (
      [NAME]
  )
  GO
  
  CREATE UNIQUE NONCLUSTERED INDEX [IX_TENANT_2] ON [TenantStore].[TENANT] (
      [DISPLAYNAME]
  )
  GO
  
  ALTER TABLE [TenantStore].[TENANT] ADD CONSTRAINT [FK_TENANT_1]
      FOREIGN KEY ( [MAILSERVER_ID] )
      REFERENCES [TenantStore].[MAILSERVER] ( [ID] )
          ON DELETE NO ACTION
          ON UPDATE NO ACTION
  GO
  
  ALTER TABLE [TenantStore].[TENANT] ADD CONSTRAINT [FK_TENANT_2]
      FOREIGN KEY ( [DBSERVER_ID] )
      REFERENCES [TenantStore].[DBSERVER] ( [ID] )
          ON DELETE NO ACTION
          ON UPDATE NO ACTION
  GO
  
  -- Tpl: DbSql-CreateTable-1.0.tt
  -- Src: Tenant.tbl
  