/****** Object:  Database [PluralBridgeChap2SafeSpine]    Script Date: 8/23/2026 5:59:55 PM ******/
CREATE DATABASE [PluralBridgeChap2SafeSpine]  (EDITION = 'Basic', SERVICE_OBJECTIVE = 'Basic', MAXSIZE = 2 GB) WITH CATALOG_COLLATION = SQL_Latin1_General_CP1_CI_AS, LEDGER = OFF;
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET COMPATIBILITY_LEVEL = 170
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET ARITHABORT OFF 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET ALLOW_SNAPSHOT_ISOLATION ON 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET READ_COMMITTED_SNAPSHOT ON 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET  MULTI_USER 
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET ENCRYPTION ON
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET QUERY_STORE = ON
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET QUERY_STORE (OPERATION_MODE = READ_WRITE, CLEANUP_POLICY = (STALE_QUERY_THRESHOLD_DAYS = 7), DATA_FLUSH_INTERVAL_SECONDS = 900, INTERVAL_LENGTH_MINUTES = 60, MAX_STORAGE_SIZE_MB = 10, QUERY_CAPTURE_MODE = AUTO, SIZE_BASED_CLEANUP_MODE = AUTO, MAX_PLANS_PER_QUERY = 200, WAIT_STATS_CAPTURE_MODE = ON)
GO
/*** The scripts of database scoped configurations in Azure should be executed inside the target database connection. ***/
GO
-- ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = 8;
GO
/****** Object:  Table [dbo].[pb_account_audit_events]    Script Date: 8/23/2026 5:59:55 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_account_audit_events](
	[AccountAuditEventId] [uniqueidentifier] NOT NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
	[EventName] [nvarchar](100) NOT NULL,
	[Outcome] [nvarchar](30) NOT NULL,
	[ReasonCode] [nvarchar](80) NOT NULL,
	[ActorAccountId] [uniqueidentifier] NULL,
	[TargetAccountId] [uniqueidentifier] NULL,
	[SystemId] [uniqueidentifier] NULL,
	[MembershipId] [uniqueidentifier] NULL,
	[CorrelationId] [nvarchar](100) NOT NULL,
	[Source] [nvarchar](30) NOT NULL,
	[SafeSubject] [nvarchar](100) NULL,
	[SafeDetailJson] [nvarchar](max) NULL,
	[SchemaVersion] [int] NOT NULL,
 CONSTRAINT [PK_pb_account_audit_events] PRIMARY KEY CLUSTERED 
(
	[AccountAuditEventId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_account_code_delivery_outbox]    Script Date: 8/23/2026 5:59:55 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_account_code_delivery_outbox](
	[OutboxId] [uniqueidentifier] NOT NULL,
	[CreatedAtUtc] [datetime2](7) NOT NULL,
	[AccountId] [uniqueidentifier] NOT NULL,
	[CodePurpose] [nvarchar](100) NOT NULL,
	[DestinationType] [nvarchar](50) NOT NULL,
	[DestinationNormalized] [nvarchar](320) NOT NULL,
	[PlaintextCode] [nvarchar](50) NOT NULL,
	[CorrelationId] [nvarchar](100) NOT NULL,
	[ConsumedForTestAtUtc] [datetime2](7) NULL,
 CONSTRAINT [PK_pb_account_code_delivery_outbox] PRIMARY KEY CLUSTERED 
(
	[OutboxId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_account_codes]    Script Date: 8/23/2026 5:59:55 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_account_codes](
	[AccountCodeId] [uniqueidentifier] NOT NULL,
	[AccountId] [uniqueidentifier] NULL,
	[CodePurpose] [nvarchar](50) NOT NULL,
	[DestinationType] [nvarchar](50) NOT NULL,
	[DestinationNormalized] [nvarchar](320) NOT NULL,
	[CodeHash] [varbinary](256) NOT NULL,
	[CodeHashAlgorithm] [nvarchar](50) NOT NULL,
	[CodeHashVersion] [int] NOT NULL,
	[ExpiresAtUtc] [datetime2](3) NOT NULL,
	[ConsumedAtUtc] [datetime2](3) NULL,
	[AttemptCount] [int] NOT NULL,
	[MaxAttempts] [int] NOT NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
	[IssuedAtUtc] [datetime2](3) NOT NULL,
	[LastAttemptAtUtc] [datetime2](3) NULL,
	[CorrelationId] [nvarchar](100) NOT NULL,
 CONSTRAINT [PK_pb_account_codes] PRIMARY KEY CLUSTERED 
(
	[AccountCodeId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_account_credentials]    Script Date: 8/23/2026 5:59:55 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_account_credentials](
	[AccountCredentialId] [uniqueidentifier] NOT NULL,
	[AccountId] [uniqueidentifier] NOT NULL,
	[PasswordHash] [varbinary](256) NOT NULL,
	[PasswordHashAlgorithm] [nvarchar](50) NOT NULL,
	[PasswordHashVersion] [int] NOT NULL,
	[PasswordChangedAtUtc] [datetime2](3) NOT NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
	[UpdatedAtUtc] [datetime2](3) NULL,
 CONSTRAINT [PK_pb_account_credentials] PRIMARY KEY CLUSTERED 
(
	[AccountCredentialId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_account_statuses]    Script Date: 8/23/2026 5:59:55 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_account_statuses](
	[AccountStatusId] [int] NOT NULL,
	[StatusName] [nvarchar](64) NOT NULL,
	[StatusDesc] [nvarchar](500) NOT NULL,
	[DisplayOrder] [int] NOT NULL,
	[IsActive] [bit] NOT NULL,
 CONSTRAINT [PK_pb_account_statuses] PRIMARY KEY CLUSTERED 
(
	[AccountStatusId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [UQ_pb_account_statuses_StatusName] UNIQUE NONCLUSTERED 
(
	[StatusName] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_accounts]    Script Date: 8/23/2026 5:59:55 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_accounts](
	[AccountId] [uniqueidentifier] NOT NULL,
	[Email] [nvarchar](320) NOT NULL,
	[DisplayName] [nvarchar](255) NULL,
	[AccountStatusId] [int] NOT NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
	[UpdatedAtUtc] [datetime2](3) NULL,
	[Username] [nvarchar](100) NULL,
	[NormalizedUsername] [nvarchar](100) NULL,
	[NormalizedEmail] [nvarchar](320) NULL,
	[IsEmailVerified] [bit] NOT NULL,
	[LastLoginAtUtc] [datetime2](3) NULL,
 CONSTRAINT [PK_pb_accounts] PRIMARY KEY CLUSTERED 
(
	[AccountId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [UQ_pb_accounts_Email] UNIQUE NONCLUSTERED 
(
	[Email] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_custom_fields]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_custom_fields](
	[CustomFieldId] [uniqueidentifier] NOT NULL,
	[SystemId] [uniqueidentifier] NOT NULL,
	[FieldName] [nvarchar](510) NOT NULL,
	[Description] [nvarchar](max) NULL,
	[FieldTypeCode] [int] NULL,
	[DisplayOrderText] [nvarchar](128) NULL,
	[SupportsMarkdown] [bit] NULL,
	[ImportedAtUtc] [datetime2](3) NOT NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
	[UpdatedAtUtc] [datetime2](3) NULL,
 CONSTRAINT [PK_pb_custom_fields] PRIMARY KEY CLUSTERED 
(
	[CustomFieldId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_front_history]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_front_history](
	[FrontHistoryId] [uniqueidentifier] NOT NULL,
	[SystemId] [uniqueidentifier] NOT NULL,
	[MemberId] [uniqueidentifier] NOT NULL,
	[StartTimeMs] [bigint] NOT NULL,
	[EndTimeMs] [bigint] NULL,
	[IsLive] [bit] NULL,
	[IsCustom] [bit] NULL,
	[CustomStatus] [nvarchar](510) NULL,
	[LastOperationTimeMs] [bigint] NULL,
	[ImportedAtUtc] [datetime2](3) NOT NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
	[UpdatedAtUtc] [datetime2](3) NULL,
 CONSTRAINT [PK_pb_front_history] PRIMARY KEY CLUSTERED 
(
	[FrontHistoryId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_group_members]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_group_members](
	[GroupMemberId] [uniqueidentifier] NOT NULL,
	[SystemId] [uniqueidentifier] NOT NULL,
	[GroupId] [uniqueidentifier] NOT NULL,
	[MemberId] [uniqueidentifier] NOT NULL,
	[SourceGroupId] [nvarchar](128) NULL,
	[SourceMemberId] [nvarchar](128) NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
 CONSTRAINT [PK_pb_group_members] PRIMARY KEY CLUSTERED 
(
	[GroupMemberId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [UQ_pb_group_members_SystemId_GroupId_MemberId] UNIQUE NONCLUSTERED 
(
	[SystemId] ASC,
	[GroupId] ASC,
	[MemberId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_groups]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_groups](
	[GroupId] [uniqueidentifier] NOT NULL,
	[SystemId] [uniqueidentifier] NOT NULL,
	[SourceGroupId] [nvarchar](128) NULL,
	[ParentGroupId] [uniqueidentifier] NULL,
	[ParentSourceGroupId] [nvarchar](128) NULL,
	[GroupName] [nvarchar](200) NOT NULL,
	[GroupColor] [nvarchar](32) NULL,
	[GroupDesc] [nvarchar](max) NULL,
	[GroupEmoji] [nvarchar](64) NULL,
	[SupportsDescMarkdown] [bit] NOT NULL,
	[SourceExists] [bit] NOT NULL,
	[LastOperationTimeUnixMs] [bigint] NULL,
	[LastOperationAtUtc] [datetime2](3) NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
	[UpdatedAtUtc] [datetime2](3) NOT NULL,
 CONSTRAINT [PK_pb_groups] PRIMARY KEY CLUSTERED 
(
	[GroupId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_import_batches]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_import_batches](
	[ImportBatchId] [uniqueidentifier] NOT NULL,
	[SourceSystemCode] [nvarchar](64) NOT NULL,
	[ImportStartedAtUtc] [datetime2](3) NOT NULL,
	[ImportCompletedAtUtc] [datetime2](3) NULL,
	[ImportToolName] [nvarchar](510) NULL,
	[ImportToolVersion] [nvarchar](128) NULL,
	[SourceExportName] [nvarchar](1000) NULL,
	[SourceExportSha256] [varbinary](32) NULL,
	[Notes] [nvarchar](max) NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
 CONSTRAINT [PK_pb_import_batches] PRIMARY KEY CLUSTERED 
(
	[ImportBatchId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_member_write_audit]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_member_write_audit](
	[MemberWriteAuditId] [uniqueidentifier] NOT NULL,
	[SystemId] [uniqueidentifier] NOT NULL,
	[AccountId] [uniqueidentifier] NOT NULL,
	[SystemMembershipId] [uniqueidentifier] NULL,
	[MemberId] [uniqueidentifier] NOT NULL,
	[Operation] [nvarchar](32) NOT NULL,
	[RequestTraceId] [nvarchar](100) NULL,
	[CreatedAtUtc] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_pb_member_write_audit] PRIMARY KEY CLUSTERED 
(
	[MemberWriteAuditId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_members]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_members](
	[MemberId] [uniqueidentifier] NOT NULL,
	[SystemId] [uniqueidentifier] NOT NULL,
	[DisplayName] [nvarchar](510) NOT NULL,
	[Pronouns] [nvarchar](510) NULL,
	[Description] [nvarchar](max) NULL,
	[Color] [nvarchar](64) NULL,
	[IsArchived] [bit] NULL,
	[ArchivedReason] [nvarchar](max) NULL,
	[IsPrivate] [bit] NULL,
	[PreventTrusted] [bit] NULL,
	[PreventsFrontNotifications] [bit] NULL,
	[ReceiveMessageBoardNotifications] [bit] NULL,
	[SupportsDescriptionMarkdown] [bit] NULL,
	[LastOperationTimeMs] [bigint] NULL,
	[ImportedAtUtc] [datetime2](3) NOT NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
	[UpdatedAtUtc] [datetime2](3) NULL,
 CONSTRAINT [PK_pb_members] PRIMARY KEY CLUSTERED 
(
	[MemberId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_privacy_buckets]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_privacy_buckets](
	[PrivacyBucketId] [uniqueidentifier] NOT NULL,
	[SystemId] [uniqueidentifier] NOT NULL,
	[BucketName] [nvarchar](510) NOT NULL,
	[Description] [nvarchar](max) NULL,
	[Color] [nvarchar](64) NULL,
	[Icon] [nvarchar](510) NULL,
	[RankText] [nvarchar](128) NULL,
	[ImportedAtUtc] [datetime2](3) NOT NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
	[UpdatedAtUtc] [datetime2](3) NULL,
 CONSTRAINT [PK_pb_privacy_buckets] PRIMARY KEY CLUSTERED 
(
	[PrivacyBucketId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_roles]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_roles](
	[RoleId] [int] NOT NULL,
	[RoleName] [nvarchar](64) NOT NULL,
	[RoleDesc] [nvarchar](500) NOT NULL,
	[DisplayOrder] [int] NOT NULL,
	[IsActive] [bit] NOT NULL,
 CONSTRAINT [PK_pb_roles] PRIMARY KEY CLUSTERED 
(
	[RoleId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [UQ_pb_roles_RoleName] UNIQUE NONCLUSTERED 
(
	[RoleName] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_source_id_map]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_source_id_map](
	[SourceIdMapId] [uniqueidentifier] NOT NULL,
	[SourceSystemCode] [nvarchar](64) NOT NULL,
	[SourceEntityTypeCode] [nvarchar](128) NOT NULL,
	[SourceId] [nvarchar](256) NOT NULL,
	[PluralBridgeEntityTypeCode] [nvarchar](128) NOT NULL,
	[PluralBridgeId] [uniqueidentifier] NOT NULL,
	[ImportBatchId] [uniqueidentifier] NOT NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
 CONSTRAINT [PK_pb_source_id_map] PRIMARY KEY CLUSTERED 
(
	[SourceIdMapId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [UQ_pb_source_id_map_SourceIdentity] UNIQUE NONCLUSTERED 
(
	[SourceSystemCode] ASC,
	[SourceEntityTypeCode] ASC,
	[SourceId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_source_records]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_source_records](
	[SourceRecordId] [uniqueidentifier] NOT NULL,
	[ImportBatchId] [uniqueidentifier] NOT NULL,
	[SourceSystemCode] [nvarchar](64) NOT NULL,
	[SourceEntityTypeCode] [nvarchar](128) NOT NULL,
	[SourceId] [nvarchar](256) NULL,
	[SourceEndpoint] [nvarchar](2000) NULL,
	[RawJson] [nvarchar](max) NULL,
	[RawJsonSha256] [varbinary](32) NULL,
	[ImportedAtUtc] [datetime2](3) NOT NULL,
 CONSTRAINT [PK_pb_source_records] PRIMARY KEY CLUSTERED 
(
	[SourceRecordId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_source_systems]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_source_systems](
	[SourceSystemCode] [nvarchar](64) NOT NULL,
	[DisplayName] [nvarchar](510) NOT NULL,
	[Description] [nvarchar](max) NULL,
	[ApiBaseUrl] [nvarchar](2000) NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
 CONSTRAINT [PK_pb_source_systems] PRIMARY KEY CLUSTERED 
(
	[SourceSystemCode] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_system_membership_roles]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_system_membership_roles](
	[SystemMembershipId] [uniqueidentifier] NOT NULL,
	[RoleId] [int] NOT NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
 CONSTRAINT [PK_pb_system_membership_roles] PRIMARY KEY CLUSTERED 
(
	[SystemMembershipId] ASC,
	[RoleId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_system_membership_statuses]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_system_membership_statuses](
	[MembershipStatusId] [int] NOT NULL,
	[StatusName] [nvarchar](64) NOT NULL,
	[StatusDesc] [nvarchar](500) NOT NULL,
	[DisplayOrder] [int] NOT NULL,
	[IsActive] [bit] NOT NULL,
 CONSTRAINT [PK_pb_system_membership_statuses] PRIMARY KEY CLUSTERED 
(
	[MembershipStatusId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [UQ_pb_system_membership_statuses_StatusName] UNIQUE NONCLUSTERED 
(
	[StatusName] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_system_memberships]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_system_memberships](
	[SystemMembershipId] [uniqueidentifier] NOT NULL,
	[AccountId] [uniqueidentifier] NOT NULL,
	[SystemId] [uniqueidentifier] NOT NULL,
	[MembershipStatusId] [int] NOT NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
	[UpdatedAtUtc] [datetime2](3) NULL,
 CONSTRAINT [PK_pb_system_memberships] PRIMARY KEY CLUSTERED 
(
	[SystemMembershipId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_system_relationships]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_system_relationships](
	[SystemRelationshipId] [uniqueidentifier] NOT NULL,
	[SystemId] [uniqueidentifier] NOT NULL,
	[ParentSystemId] [uniqueidentifier] NULL,
	[RelationshipRank] [int] NOT NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
	[UpdatedAtUtc] [datetime2](3) NOT NULL,
 CONSTRAINT [PK_pb_system_relationships] PRIMARY KEY CLUSTERED 
(
	[SystemRelationshipId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [UQ_pb_system_relationships_SystemId] UNIQUE NONCLUSTERED 
(
	[SystemId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_systems]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_systems](
	[SystemId] [uniqueidentifier] NOT NULL,
	[SystemName] [nvarchar](510) NULL,
	[Description] [nvarchar](max) NULL,
	[Color] [nvarchar](64) NULL,
	[AvatarUrl] [nvarchar](2000) NULL,
	[AvatarUuid] [nvarchar](128) NULL,
	[SourceCreatedAtMs] [bigint] NULL,
	[LastOperationTimeMs] [bigint] NULL,
	[ImportedAtUtc] [datetime2](3) NOT NULL,
	[CreatedAtUtc] [datetime2](3) NOT NULL,
	[UpdatedAtUtc] [datetime2](3) NULL,
 CONSTRAINT [PK_pb_systems] PRIMARY KEY CLUSTERED 
(
	[SystemId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_visibility_scope_members]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_visibility_scope_members](
	[VisibilityScopeMemberId] [uniqueidentifier] NOT NULL,
	[VisibilityScopeId] [uniqueidentifier] NOT NULL,
	[MemberId] [uniqueidentifier] NOT NULL,
	[CreatedAtUtc] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_pb_visibility_scope_members] PRIMARY KEY CLUSTERED 
(
	[VisibilityScopeMemberId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [UQ_pb_visibility_scope_members_ScopeId_MemberId] UNIQUE NONCLUSTERED 
(
	[VisibilityScopeId] ASC,
	[MemberId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[pb_visibility_scopes]    Script Date: 8/23/2026 5:59:56 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pb_visibility_scopes](
	[VisibilityScopeId] [uniqueidentifier] NOT NULL,
	[SystemId] [uniqueidentifier] NOT NULL,
	[ScopeName] [nvarchar](100) NOT NULL,
	[ScopeDesc] [nvarchar](500) NULL,
	[IsSystemDefault] [bit] NOT NULL,
	[IsActive] [bit] NOT NULL,
	[CreatedAtUtc] [datetime2](7) NOT NULL,
	[UpdatedAtUtc] [datetime2](7) NULL,
 CONSTRAINT [PK_pb_visibility_scopes] PRIMARY KEY CLUSTERED 
(
	[VisibilityScopeId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [UQ_pb_visibility_scopes_SystemId_ScopeName] UNIQUE NONCLUSTERED 
(
	[SystemId] ASC,
	[ScopeName] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Index [IX_pb_account_audit_events_ActorAccountId_CreatedAtUtc]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_account_audit_events_ActorAccountId_CreatedAtUtc] ON [dbo].[pb_account_audit_events]
(
	[ActorAccountId] ASC,
	[CreatedAtUtc] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IX_pb_account_audit_events_CorrelationId]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_account_audit_events_CorrelationId] ON [dbo].[pb_account_audit_events]
(
	[CorrelationId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object:  Index [IX_pb_account_audit_events_CreatedAtUtc]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_account_audit_events_CreatedAtUtc] ON [dbo].[pb_account_audit_events]
(
	[CreatedAtUtc] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IX_pb_account_audit_events_EventName_CreatedAtUtc]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_account_audit_events_EventName_CreatedAtUtc] ON [dbo].[pb_account_audit_events]
(
	[EventName] ASC,
	[CreatedAtUtc] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object:  Index [IX_pb_account_audit_events_TargetAccountId_CreatedAtUtc]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_account_audit_events_TargetAccountId_CreatedAtUtc] ON [dbo].[pb_account_audit_events]
(
	[TargetAccountId] ASC,
	[CreatedAtUtc] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object:  Index [IX_pb_account_code_delivery_outbox_AccountId]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_account_code_delivery_outbox_AccountId] ON [dbo].[pb_account_code_delivery_outbox]
(
	[AccountId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IX_pb_account_code_delivery_outbox_Destination]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_account_code_delivery_outbox_Destination] ON [dbo].[pb_account_code_delivery_outbox]
(
	[CodePurpose] ASC,
	[DestinationType] ASC,
	[DestinationNormalized] ASC,
	[CreatedAtUtc] DESC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IX_pb_account_codes_AccountId_CodePurpose]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_account_codes_AccountId_CodePurpose] ON [dbo].[pb_account_codes]
(
	[AccountId] ASC,
	[CodePurpose] ASC,
	[ConsumedAtUtc] ASC,
	[ExpiresAtUtc] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IX_pb_account_codes_CorrelationId]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_account_codes_CorrelationId] ON [dbo].[pb_account_codes]
(
	[CorrelationId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IX_pb_account_codes_DestinationNormalized_CodePurpose]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_account_codes_DestinationNormalized_CodePurpose] ON [dbo].[pb_account_codes]
(
	[DestinationNormalized] ASC,
	[CodePurpose] ASC,
	[CreatedAtUtc] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object:  Index [UX_pb_account_credentials_AccountId]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE UNIQUE NONCLUSTERED INDEX [UX_pb_account_credentials_AccountId] ON [dbo].[pb_account_credentials]
(
	[AccountId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object:  Index [IX_pb_accounts_AccountStatusId]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_accounts_AccountStatusId] ON [dbo].[pb_accounts]
(
	[AccountStatusId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [UX_pb_accounts_NormalizedEmail]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE UNIQUE NONCLUSTERED INDEX [UX_pb_accounts_NormalizedEmail] ON [dbo].[pb_accounts]
(
	[NormalizedEmail] ASC
)
WHERE ([NormalizedEmail] IS NOT NULL)
WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [UX_pb_accounts_NormalizedUsername]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE UNIQUE NONCLUSTERED INDEX [UX_pb_accounts_NormalizedUsername] ON [dbo].[pb_accounts]
(
	[NormalizedUsername] ASC
)
WHERE ([NormalizedUsername] IS NOT NULL)
WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object:  Index [IX_pb_member_write_audit_MemberId_CreatedAtUtc]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_member_write_audit_MemberId_CreatedAtUtc] ON [dbo].[pb_member_write_audit]
(
	[MemberId] ASC,
	[CreatedAtUtc] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object:  Index [IX_pb_member_write_audit_SystemId_CreatedAtUtc]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_member_write_audit_SystemId_CreatedAtUtc] ON [dbo].[pb_member_write_audit]
(
	[SystemId] ASC,
	[CreatedAtUtc] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object:  Index [IX_pb_system_membership_roles_RoleId]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_system_membership_roles_RoleId] ON [dbo].[pb_system_membership_roles]
(
	[RoleId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object:  Index [IX_pb_system_memberships_AccountId]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_system_memberships_AccountId] ON [dbo].[pb_system_memberships]
(
	[AccountId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object:  Index [IX_pb_system_memberships_SystemId]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE NONCLUSTERED INDEX [IX_pb_system_memberships_SystemId] ON [dbo].[pb_system_memberships]
(
	[SystemId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object:  Index [UX_pb_system_relationships_SingleRoot]    Script Date: 8/23/2026 5:59:56 PM ******/
CREATE UNIQUE NONCLUSTERED INDEX [UX_pb_system_relationships_SingleRoot] ON [dbo].[pb_system_relationships]
(
	[ParentSystemId] ASC
)
WHERE ([ParentSystemId] IS NULL)
WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
ALTER TABLE [dbo].[pb_account_audit_events] ADD  DEFAULT (newsequentialid()) FOR [AccountAuditEventId]
GO
ALTER TABLE [dbo].[pb_account_audit_events] ADD  CONSTRAINT [DF_pb_account_audit_events_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_account_audit_events] ADD  CONSTRAINT [DF_pb_account_audit_events_SchemaVersion]  DEFAULT ((1)) FOR [SchemaVersion]
GO
ALTER TABLE [dbo].[pb_account_code_delivery_outbox] ADD  CONSTRAINT [DF_pb_account_code_delivery_outbox_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_account_codes] ADD  DEFAULT (newsequentialid()) FOR [AccountCodeId]
GO
ALTER TABLE [dbo].[pb_account_codes] ADD  CONSTRAINT [DF_pb_account_codes_CodeHashVersion]  DEFAULT ((1)) FOR [CodeHashVersion]
GO
ALTER TABLE [dbo].[pb_account_codes] ADD  CONSTRAINT [DF_pb_account_codes_AttemptCount]  DEFAULT ((0)) FOR [AttemptCount]
GO
ALTER TABLE [dbo].[pb_account_codes] ADD  CONSTRAINT [DF_pb_account_codes_MaxAttempts]  DEFAULT ((5)) FOR [MaxAttempts]
GO
ALTER TABLE [dbo].[pb_account_codes] ADD  CONSTRAINT [DF_pb_account_codes_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_account_codes] ADD  CONSTRAINT [DF_pb_account_codes_IssuedAtUtc]  DEFAULT (sysutcdatetime()) FOR [IssuedAtUtc]
GO
ALTER TABLE [dbo].[pb_account_credentials] ADD  DEFAULT (newsequentialid()) FOR [AccountCredentialId]
GO
ALTER TABLE [dbo].[pb_account_credentials] ADD  CONSTRAINT [DF_pb_account_credentials_PasswordHashVersion]  DEFAULT ((1)) FOR [PasswordHashVersion]
GO
ALTER TABLE [dbo].[pb_account_credentials] ADD  CONSTRAINT [DF_pb_account_credentials_PasswordChangedAtUtc]  DEFAULT (sysutcdatetime()) FOR [PasswordChangedAtUtc]
GO
ALTER TABLE [dbo].[pb_account_credentials] ADD  CONSTRAINT [DF_pb_account_credentials_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_account_statuses] ADD  CONSTRAINT [DF_pb_account_statuses_IsActive]  DEFAULT ((1)) FOR [IsActive]
GO
ALTER TABLE [dbo].[pb_accounts] ADD  CONSTRAINT [DF_pb_accounts_AccountId]  DEFAULT (newsequentialid()) FOR [AccountId]
GO
ALTER TABLE [dbo].[pb_accounts] ADD  CONSTRAINT [DF_pb_accounts_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_accounts] ADD  CONSTRAINT [DF_pb_accounts_IsEmailVerified]  DEFAULT ((0)) FOR [IsEmailVerified]
GO
ALTER TABLE [dbo].[pb_custom_fields] ADD  CONSTRAINT [DF_pb_custom_fields_CustomFieldId]  DEFAULT (newsequentialid()) FOR [CustomFieldId]
GO
ALTER TABLE [dbo].[pb_custom_fields] ADD  CONSTRAINT [DF_pb_custom_fields_ImportedAtUtc]  DEFAULT (sysutcdatetime()) FOR [ImportedAtUtc]
GO
ALTER TABLE [dbo].[pb_custom_fields] ADD  CONSTRAINT [DF_pb_custom_fields_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_front_history] ADD  CONSTRAINT [DF_pb_front_history_FrontHistoryId]  DEFAULT (newsequentialid()) FOR [FrontHistoryId]
GO
ALTER TABLE [dbo].[pb_front_history] ADD  CONSTRAINT [DF_pb_front_history_ImportedAtUtc]  DEFAULT (sysutcdatetime()) FOR [ImportedAtUtc]
GO
ALTER TABLE [dbo].[pb_front_history] ADD  CONSTRAINT [DF_pb_front_history_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_group_members] ADD  CONSTRAINT [DF_pb_group_members_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_groups] ADD  CONSTRAINT [DF_pb_groups_SupportsDescMarkdown]  DEFAULT ((0)) FOR [SupportsDescMarkdown]
GO
ALTER TABLE [dbo].[pb_groups] ADD  CONSTRAINT [DF_pb_groups_SourceExists]  DEFAULT ((1)) FOR [SourceExists]
GO
ALTER TABLE [dbo].[pb_groups] ADD  CONSTRAINT [DF_pb_groups_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_groups] ADD  CONSTRAINT [DF_pb_groups_UpdatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [UpdatedAtUtc]
GO
ALTER TABLE [dbo].[pb_import_batches] ADD  CONSTRAINT [DF_pb_import_batches_ImportBatchId]  DEFAULT (newsequentialid()) FOR [ImportBatchId]
GO
ALTER TABLE [dbo].[pb_import_batches] ADD  CONSTRAINT [DF_pb_import_batches_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_member_write_audit] ADD  CONSTRAINT [DF_pb_member_write_audit_MemberWriteAuditId]  DEFAULT (newid()) FOR [MemberWriteAuditId]
GO
ALTER TABLE [dbo].[pb_member_write_audit] ADD  CONSTRAINT [DF_pb_member_write_audit_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_members] ADD  CONSTRAINT [DF_pb_members_MemberId]  DEFAULT (newsequentialid()) FOR [MemberId]
GO
ALTER TABLE [dbo].[pb_members] ADD  CONSTRAINT [DF_pb_members_ImportedAtUtc]  DEFAULT (sysutcdatetime()) FOR [ImportedAtUtc]
GO
ALTER TABLE [dbo].[pb_members] ADD  CONSTRAINT [DF_pb_members_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_privacy_buckets] ADD  CONSTRAINT [DF_pb_privacy_buckets_PrivacyBucketId]  DEFAULT (newsequentialid()) FOR [PrivacyBucketId]
GO
ALTER TABLE [dbo].[pb_privacy_buckets] ADD  CONSTRAINT [DF_pb_privacy_buckets_ImportedAtUtc]  DEFAULT (sysutcdatetime()) FOR [ImportedAtUtc]
GO
ALTER TABLE [dbo].[pb_privacy_buckets] ADD  CONSTRAINT [DF_pb_privacy_buckets_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_roles] ADD  CONSTRAINT [DF_pb_roles_IsActive]  DEFAULT ((1)) FOR [IsActive]
GO
ALTER TABLE [dbo].[pb_source_id_map] ADD  CONSTRAINT [DF_pb_source_id_map_SourceIdMapId]  DEFAULT (newsequentialid()) FOR [SourceIdMapId]
GO
ALTER TABLE [dbo].[pb_source_id_map] ADD  CONSTRAINT [DF_pb_source_id_map_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_source_records] ADD  CONSTRAINT [DF_pb_source_records_SourceRecordId]  DEFAULT (newsequentialid()) FOR [SourceRecordId]
GO
ALTER TABLE [dbo].[pb_source_records] ADD  CONSTRAINT [DF_pb_source_records_ImportedAtUtc]  DEFAULT (sysutcdatetime()) FOR [ImportedAtUtc]
GO
ALTER TABLE [dbo].[pb_source_systems] ADD  CONSTRAINT [DF_pb_source_systems_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_system_membership_roles] ADD  CONSTRAINT [DF_pb_system_membership_roles_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_system_membership_statuses] ADD  CONSTRAINT [DF_pb_system_membership_statuses_IsActive]  DEFAULT ((1)) FOR [IsActive]
GO
ALTER TABLE [dbo].[pb_system_memberships] ADD  CONSTRAINT [DF_pb_system_memberships_SystemMembershipId]  DEFAULT (newsequentialid()) FOR [SystemMembershipId]
GO
ALTER TABLE [dbo].[pb_system_memberships] ADD  CONSTRAINT [DF_pb_system_memberships_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_system_relationships] ADD  CONSTRAINT [DF_pb_system_relationships_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_system_relationships] ADD  CONSTRAINT [DF_pb_system_relationships_UpdatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [UpdatedAtUtc]
GO
ALTER TABLE [dbo].[pb_systems] ADD  CONSTRAINT [DF_pb_systems_SystemId]  DEFAULT (newsequentialid()) FOR [SystemId]
GO
ALTER TABLE [dbo].[pb_systems] ADD  CONSTRAINT [DF_pb_systems_ImportedAtUtc]  DEFAULT (sysutcdatetime()) FOR [ImportedAtUtc]
GO
ALTER TABLE [dbo].[pb_systems] ADD  CONSTRAINT [DF_pb_systems_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_visibility_scope_members] ADD  CONSTRAINT [DF_pb_visibility_scope_members_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_visibility_scopes] ADD  CONSTRAINT [DF_pb_visibility_scopes_IsSystemDefault]  DEFAULT ((0)) FOR [IsSystemDefault]
GO
ALTER TABLE [dbo].[pb_visibility_scopes] ADD  CONSTRAINT [DF_pb_visibility_scopes_IsActive]  DEFAULT ((1)) FOR [IsActive]
GO
ALTER TABLE [dbo].[pb_visibility_scopes] ADD  CONSTRAINT [DF_pb_visibility_scopes_CreatedAtUtc]  DEFAULT (sysutcdatetime()) FOR [CreatedAtUtc]
GO
ALTER TABLE [dbo].[pb_account_audit_events]  WITH CHECK ADD  CONSTRAINT [FK_pb_account_audit_events_ActorAccount] FOREIGN KEY([ActorAccountId])
REFERENCES [dbo].[pb_accounts] ([AccountId])
GO
ALTER TABLE [dbo].[pb_account_audit_events] CHECK CONSTRAINT [FK_pb_account_audit_events_ActorAccount]
GO
ALTER TABLE [dbo].[pb_account_audit_events]  WITH CHECK ADD  CONSTRAINT [FK_pb_account_audit_events_TargetAccount] FOREIGN KEY([TargetAccountId])
REFERENCES [dbo].[pb_accounts] ([AccountId])
GO
ALTER TABLE [dbo].[pb_account_audit_events] CHECK CONSTRAINT [FK_pb_account_audit_events_TargetAccount]
GO
ALTER TABLE [dbo].[pb_account_codes]  WITH CHECK ADD  CONSTRAINT [FK_pb_account_codes_pb_accounts] FOREIGN KEY([AccountId])
REFERENCES [dbo].[pb_accounts] ([AccountId])
GO
ALTER TABLE [dbo].[pb_account_codes] CHECK CONSTRAINT [FK_pb_account_codes_pb_accounts]
GO
ALTER TABLE [dbo].[pb_account_credentials]  WITH CHECK ADD  CONSTRAINT [FK_pb_account_credentials_pb_accounts] FOREIGN KEY([AccountId])
REFERENCES [dbo].[pb_accounts] ([AccountId])
GO
ALTER TABLE [dbo].[pb_account_credentials] CHECK CONSTRAINT [FK_pb_account_credentials_pb_accounts]
GO
ALTER TABLE [dbo].[pb_accounts]  WITH CHECK ADD  CONSTRAINT [FK_pb_accounts_pb_account_statuses] FOREIGN KEY([AccountStatusId])
REFERENCES [dbo].[pb_account_statuses] ([AccountStatusId])
GO
ALTER TABLE [dbo].[pb_accounts] CHECK CONSTRAINT [FK_pb_accounts_pb_account_statuses]
GO
ALTER TABLE [dbo].[pb_custom_fields]  WITH CHECK ADD  CONSTRAINT [FK_pb_custom_fields_pb_systems] FOREIGN KEY([SystemId])
REFERENCES [dbo].[pb_systems] ([SystemId])
GO
ALTER TABLE [dbo].[pb_custom_fields] CHECK CONSTRAINT [FK_pb_custom_fields_pb_systems]
GO
ALTER TABLE [dbo].[pb_front_history]  WITH CHECK ADD  CONSTRAINT [FK_pb_front_history_pb_members] FOREIGN KEY([MemberId])
REFERENCES [dbo].[pb_members] ([MemberId])
GO
ALTER TABLE [dbo].[pb_front_history] CHECK CONSTRAINT [FK_pb_front_history_pb_members]
GO
ALTER TABLE [dbo].[pb_front_history]  WITH CHECK ADD  CONSTRAINT [FK_pb_front_history_pb_systems] FOREIGN KEY([SystemId])
REFERENCES [dbo].[pb_systems] ([SystemId])
GO
ALTER TABLE [dbo].[pb_front_history] CHECK CONSTRAINT [FK_pb_front_history_pb_systems]
GO
ALTER TABLE [dbo].[pb_group_members]  WITH CHECK ADD  CONSTRAINT [FK_pb_group_members_pb_groups_GroupId] FOREIGN KEY([GroupId])
REFERENCES [dbo].[pb_groups] ([GroupId])
GO
ALTER TABLE [dbo].[pb_group_members] CHECK CONSTRAINT [FK_pb_group_members_pb_groups_GroupId]
GO
ALTER TABLE [dbo].[pb_group_members]  WITH CHECK ADD  CONSTRAINT [FK_pb_group_members_pb_members_MemberId] FOREIGN KEY([MemberId])
REFERENCES [dbo].[pb_members] ([MemberId])
GO
ALTER TABLE [dbo].[pb_group_members] CHECK CONSTRAINT [FK_pb_group_members_pb_members_MemberId]
GO
ALTER TABLE [dbo].[pb_group_members]  WITH CHECK ADD  CONSTRAINT [FK_pb_group_members_pb_systems_SystemId] FOREIGN KEY([SystemId])
REFERENCES [dbo].[pb_systems] ([SystemId])
GO
ALTER TABLE [dbo].[pb_group_members] CHECK CONSTRAINT [FK_pb_group_members_pb_systems_SystemId]
GO
ALTER TABLE [dbo].[pb_groups]  WITH CHECK ADD  CONSTRAINT [FK_pb_groups_pb_groups_ParentGroupId] FOREIGN KEY([ParentGroupId])
REFERENCES [dbo].[pb_groups] ([GroupId])
GO
ALTER TABLE [dbo].[pb_groups] CHECK CONSTRAINT [FK_pb_groups_pb_groups_ParentGroupId]
GO
ALTER TABLE [dbo].[pb_groups]  WITH CHECK ADD  CONSTRAINT [FK_pb_groups_pb_systems_SystemId] FOREIGN KEY([SystemId])
REFERENCES [dbo].[pb_systems] ([SystemId])
GO
ALTER TABLE [dbo].[pb_groups] CHECK CONSTRAINT [FK_pb_groups_pb_systems_SystemId]
GO
ALTER TABLE [dbo].[pb_import_batches]  WITH CHECK ADD  CONSTRAINT [FK_pb_import_batches_pb_source_systems] FOREIGN KEY([SourceSystemCode])
REFERENCES [dbo].[pb_source_systems] ([SourceSystemCode])
GO
ALTER TABLE [dbo].[pb_import_batches] CHECK CONSTRAINT [FK_pb_import_batches_pb_source_systems]
GO
ALTER TABLE [dbo].[pb_member_write_audit]  WITH CHECK ADD  CONSTRAINT [FK_pb_member_write_audit_accounts] FOREIGN KEY([AccountId])
REFERENCES [dbo].[pb_accounts] ([AccountId])
GO
ALTER TABLE [dbo].[pb_member_write_audit] CHECK CONSTRAINT [FK_pb_member_write_audit_accounts]
GO
ALTER TABLE [dbo].[pb_member_write_audit]  WITH CHECK ADD  CONSTRAINT [FK_pb_member_write_audit_members] FOREIGN KEY([MemberId])
REFERENCES [dbo].[pb_members] ([MemberId])
GO
ALTER TABLE [dbo].[pb_member_write_audit] CHECK CONSTRAINT [FK_pb_member_write_audit_members]
GO
ALTER TABLE [dbo].[pb_member_write_audit]  WITH CHECK ADD  CONSTRAINT [FK_pb_member_write_audit_system_memberships] FOREIGN KEY([SystemMembershipId])
REFERENCES [dbo].[pb_system_memberships] ([SystemMembershipId])
GO
ALTER TABLE [dbo].[pb_member_write_audit] CHECK CONSTRAINT [FK_pb_member_write_audit_system_memberships]
GO
ALTER TABLE [dbo].[pb_member_write_audit]  WITH CHECK ADD  CONSTRAINT [FK_pb_member_write_audit_systems] FOREIGN KEY([SystemId])
REFERENCES [dbo].[pb_systems] ([SystemId])
GO
ALTER TABLE [dbo].[pb_member_write_audit] CHECK CONSTRAINT [FK_pb_member_write_audit_systems]
GO
ALTER TABLE [dbo].[pb_members]  WITH CHECK ADD  CONSTRAINT [FK_pb_members_pb_systems] FOREIGN KEY([SystemId])
REFERENCES [dbo].[pb_systems] ([SystemId])
GO
ALTER TABLE [dbo].[pb_members] CHECK CONSTRAINT [FK_pb_members_pb_systems]
GO
ALTER TABLE [dbo].[pb_privacy_buckets]  WITH CHECK ADD  CONSTRAINT [FK_pb_privacy_buckets_pb_systems] FOREIGN KEY([SystemId])
REFERENCES [dbo].[pb_systems] ([SystemId])
GO
ALTER TABLE [dbo].[pb_privacy_buckets] CHECK CONSTRAINT [FK_pb_privacy_buckets_pb_systems]
GO
ALTER TABLE [dbo].[pb_source_id_map]  WITH CHECK ADD  CONSTRAINT [FK_pb_source_id_map_pb_import_batches] FOREIGN KEY([ImportBatchId])
REFERENCES [dbo].[pb_import_batches] ([ImportBatchId])
GO
ALTER TABLE [dbo].[pb_source_id_map] CHECK CONSTRAINT [FK_pb_source_id_map_pb_import_batches]
GO
ALTER TABLE [dbo].[pb_source_id_map]  WITH CHECK ADD  CONSTRAINT [FK_pb_source_id_map_pb_source_systems] FOREIGN KEY([SourceSystemCode])
REFERENCES [dbo].[pb_source_systems] ([SourceSystemCode])
GO
ALTER TABLE [dbo].[pb_source_id_map] CHECK CONSTRAINT [FK_pb_source_id_map_pb_source_systems]
GO
ALTER TABLE [dbo].[pb_source_records]  WITH CHECK ADD  CONSTRAINT [FK_pb_source_records_pb_import_batches] FOREIGN KEY([ImportBatchId])
REFERENCES [dbo].[pb_import_batches] ([ImportBatchId])
GO
ALTER TABLE [dbo].[pb_source_records] CHECK CONSTRAINT [FK_pb_source_records_pb_import_batches]
GO
ALTER TABLE [dbo].[pb_source_records]  WITH CHECK ADD  CONSTRAINT [FK_pb_source_records_pb_source_systems] FOREIGN KEY([SourceSystemCode])
REFERENCES [dbo].[pb_source_systems] ([SourceSystemCode])
GO
ALTER TABLE [dbo].[pb_source_records] CHECK CONSTRAINT [FK_pb_source_records_pb_source_systems]
GO
ALTER TABLE [dbo].[pb_system_membership_roles]  WITH CHECK ADD  CONSTRAINT [FK_pb_system_membership_roles_pb_roles] FOREIGN KEY([RoleId])
REFERENCES [dbo].[pb_roles] ([RoleId])
GO
ALTER TABLE [dbo].[pb_system_membership_roles] CHECK CONSTRAINT [FK_pb_system_membership_roles_pb_roles]
GO
ALTER TABLE [dbo].[pb_system_membership_roles]  WITH CHECK ADD  CONSTRAINT [FK_pb_system_membership_roles_pb_system_memberships] FOREIGN KEY([SystemMembershipId])
REFERENCES [dbo].[pb_system_memberships] ([SystemMembershipId])
GO
ALTER TABLE [dbo].[pb_system_membership_roles] CHECK CONSTRAINT [FK_pb_system_membership_roles_pb_system_memberships]
GO
ALTER TABLE [dbo].[pb_system_memberships]  WITH CHECK ADD  CONSTRAINT [FK_pb_system_memberships_pb_accounts] FOREIGN KEY([AccountId])
REFERENCES [dbo].[pb_accounts] ([AccountId])
GO
ALTER TABLE [dbo].[pb_system_memberships] CHECK CONSTRAINT [FK_pb_system_memberships_pb_accounts]
GO
ALTER TABLE [dbo].[pb_system_memberships]  WITH CHECK ADD  CONSTRAINT [FK_pb_system_memberships_pb_system_membership_statuses] FOREIGN KEY([MembershipStatusId])
REFERENCES [dbo].[pb_system_membership_statuses] ([MembershipStatusId])
GO
ALTER TABLE [dbo].[pb_system_memberships] CHECK CONSTRAINT [FK_pb_system_memberships_pb_system_membership_statuses]
GO
ALTER TABLE [dbo].[pb_system_memberships]  WITH CHECK ADD  CONSTRAINT [FK_pb_system_memberships_pb_systems] FOREIGN KEY([SystemId])
REFERENCES [dbo].[pb_systems] ([SystemId])
GO
ALTER TABLE [dbo].[pb_system_memberships] CHECK CONSTRAINT [FK_pb_system_memberships_pb_systems]
GO
ALTER TABLE [dbo].[pb_system_relationships]  WITH CHECK ADD  CONSTRAINT [FK_pb_system_relationships_pb_systems_ParentSystemId] FOREIGN KEY([ParentSystemId])
REFERENCES [dbo].[pb_systems] ([SystemId])
GO
ALTER TABLE [dbo].[pb_system_relationships] CHECK CONSTRAINT [FK_pb_system_relationships_pb_systems_ParentSystemId]
GO
ALTER TABLE [dbo].[pb_system_relationships]  WITH CHECK ADD  CONSTRAINT [FK_pb_system_relationships_pb_systems_SystemId] FOREIGN KEY([SystemId])
REFERENCES [dbo].[pb_systems] ([SystemId])
GO
ALTER TABLE [dbo].[pb_system_relationships] CHECK CONSTRAINT [FK_pb_system_relationships_pb_systems_SystemId]
GO
ALTER TABLE [dbo].[pb_visibility_scope_members]  WITH CHECK ADD  CONSTRAINT [FK_pb_visibility_scope_members_pb_members] FOREIGN KEY([MemberId])
REFERENCES [dbo].[pb_members] ([MemberId])
GO
ALTER TABLE [dbo].[pb_visibility_scope_members] CHECK CONSTRAINT [FK_pb_visibility_scope_members_pb_members]
GO
ALTER TABLE [dbo].[pb_visibility_scope_members]  WITH CHECK ADD  CONSTRAINT [FK_pb_visibility_scope_members_pb_visibility_scopes] FOREIGN KEY([VisibilityScopeId])
REFERENCES [dbo].[pb_visibility_scopes] ([VisibilityScopeId])
GO
ALTER TABLE [dbo].[pb_visibility_scope_members] CHECK CONSTRAINT [FK_pb_visibility_scope_members_pb_visibility_scopes]
GO
ALTER TABLE [dbo].[pb_visibility_scopes]  WITH CHECK ADD  CONSTRAINT [FK_pb_visibility_scopes_pb_systems] FOREIGN KEY([SystemId])
REFERENCES [dbo].[pb_systems] ([SystemId])
GO
ALTER TABLE [dbo].[pb_visibility_scopes] CHECK CONSTRAINT [FK_pb_visibility_scopes_pb_systems]
GO
ALTER TABLE [dbo].[pb_account_audit_events]  WITH CHECK ADD  CONSTRAINT [CK_pb_account_audit_events_EventName] CHECK  (([EventName]=N'system.owned_status.rejected' OR [EventName]=N'system.owned_status.changed' OR [EventName]=N'system.owned_profile.rejected' OR [EventName]=N'system.owned_profile.updated' OR [EventName]=N'account.ownership.bootstrap_rejected' OR [EventName]=N'account.ownership.bootstrap_completed' OR [EventName]=N'account.ownership.role_assigned' OR [EventName]=N'account.ownership.membership_created' OR [EventName]=N'account.ownership.system_created' OR [EventName]=N'account.ownership.bootstrap_started' OR [EventName]=N'account.contact.rejected' OR [EventName]=N'account.contact.updated' OR [EventName]=N'account.profile.rejected' OR [EventName]=N'account.profile.updated' OR [EventName]=N'account.password_change.completed' OR [EventName]=N'account.password_change.rejected' OR [EventName]=N'account.password_change.requested' OR [EventName]=N'account.password_reset.completed' OR [EventName]=N'account.password_reset.rejected' OR [EventName]=N'account.password_reset.code_accepted' OR [EventName]=N'account.password_reset.issued' OR [EventName]=N'account.password_reset.requested' OR [EventName]=N'account.username_recovery.completed' OR [EventName]=N'account.username_recovery.rejected' OR [EventName]=N'account.username_recovery.issued' OR [EventName]=N'account.username_recovery.requested' OR [EventName]=N'account.session.rejected' OR [EventName]=N'account.logout.succeeded' OR [EventName]=N'account.login.rejected' OR [EventName]=N'account.login.succeeded' OR [EventName]=N'account.code.consumed' OR [EventName]=N'account.code.rejected' OR [EventName]=N'account.code.accepted' OR [EventName]=N'account.code.issued' OR [EventName]=N'account.registration.verification_rejected' OR [EventName]=N'account.registration.verified' OR [EventName]=N'account.registration.created' OR [EventName]=N'account.registration.rejected' OR [EventName]=N'account.registration.requested'))
GO
ALTER TABLE [dbo].[pb_account_audit_events] CHECK CONSTRAINT [CK_pb_account_audit_events_EventName]
GO
ALTER TABLE [dbo].[pb_account_audit_events]  WITH CHECK ADD  CONSTRAINT [CK_pb_account_audit_events_Outcome] CHECK  (([Outcome]=N'no_op' OR [Outcome]=N'failed' OR [Outcome]=N'blocked' OR [Outcome]=N'consumed' OR [Outcome]=N'expired' OR [Outcome]=N'denied' OR [Outcome]=N'rejected' OR [Outcome]=N'succeeded'))
GO
ALTER TABLE [dbo].[pb_account_audit_events] CHECK CONSTRAINT [CK_pb_account_audit_events_Outcome]
GO
ALTER TABLE [dbo].[pb_account_audit_events]  WITH CHECK ADD  CONSTRAINT [CK_pb_account_audit_events_ReasonCode] CHECK  (([ReasonCode]=N'unexpected_failure' OR [ReasonCode]=N'delivery_failed' OR [ReasonCode]=N'storage_failed' OR [ReasonCode]=N'validation_failed' OR [ReasonCode]=N'session_required' OR [ReasonCode]=N'csrf_rejected' OR [ReasonCode]=N'rate_limited' OR [ReasonCode]=N'system_unavailable' OR [ReasonCode]=N'role_required' OR [ReasonCode]=N'membership_required' OR [ReasonCode]=N'ownership_required' OR [ReasonCode]=N'contact_unavailable' OR [ReasonCode]=N'account_unavailable' OR [ReasonCode]=N'duplicate_account_identifier' OR [ReasonCode]=N'password_policy_failed' OR [ReasonCode]=N'purpose_mismatch' OR [ReasonCode]=N'consumed_code' OR [ReasonCode]=N'expired_code' OR [ReasonCode]=N'invalid_code' OR [ReasonCode]=N'invalid_credentials' OR [ReasonCode]=N'invalid_request' OR [ReasonCode]=N'none'))
GO
ALTER TABLE [dbo].[pb_account_audit_events] CHECK CONSTRAINT [CK_pb_account_audit_events_ReasonCode]
GO
ALTER TABLE [dbo].[pb_account_audit_events]  WITH CHECK ADD  CONSTRAINT [CK_pb_account_audit_events_SafeDetailJson] CHECK  (([SafeDetailJson] IS NULL OR isjson([SafeDetailJson])=(1)))
GO
ALTER TABLE [dbo].[pb_account_audit_events] CHECK CONSTRAINT [CK_pb_account_audit_events_SafeDetailJson]
GO
ALTER TABLE [dbo].[pb_account_audit_events]  WITH CHECK ADD  CONSTRAINT [CK_pb_account_audit_events_SchemaVersion] CHECK  (([SchemaVersion]=(1)))
GO
ALTER TABLE [dbo].[pb_account_audit_events] CHECK CONSTRAINT [CK_pb_account_audit_events_SchemaVersion]
GO
ALTER TABLE [dbo].[pb_account_audit_events]  WITH CHECK ADD  CONSTRAINT [CK_pb_account_audit_events_Source] CHECK  (([Source]=N'import' OR [Source]=N'system' OR [Source]=N'api' OR [Source]=N'browser'))
GO
ALTER TABLE [dbo].[pb_account_audit_events] CHECK CONSTRAINT [CK_pb_account_audit_events_Source]
GO
ALTER TABLE [dbo].[pb_account_codes]  WITH CHECK ADD  CONSTRAINT [CK_pb_account_codes_AttemptCount] CHECK  (([AttemptCount]>=(0)))
GO
ALTER TABLE [dbo].[pb_account_codes] CHECK CONSTRAINT [CK_pb_account_codes_AttemptCount]
GO
ALTER TABLE [dbo].[pb_account_codes]  WITH CHECK ADD  CONSTRAINT [CK_pb_account_codes_AttemptCountMaxAttempts] CHECK  (([AttemptCount]<=[MaxAttempts]))
GO
ALTER TABLE [dbo].[pb_account_codes] CHECK CONSTRAINT [CK_pb_account_codes_AttemptCountMaxAttempts]
GO
ALTER TABLE [dbo].[pb_account_codes]  WITH CHECK ADD  CONSTRAINT [CK_pb_account_codes_CodePurpose] CHECK  (([CodePurpose]=N'contact_verification' OR [CodePurpose]=N'password_reset' OR [CodePurpose]=N'username_recovery' OR [CodePurpose]=N'registration_verification'))
GO
ALTER TABLE [dbo].[pb_account_codes] CHECK CONSTRAINT [CK_pb_account_codes_CodePurpose]
GO
ALTER TABLE [dbo].[pb_account_codes]  WITH CHECK ADD  CONSTRAINT [CK_pb_account_codes_DestinationType] CHECK  (([DestinationType]=N'email'))
GO
ALTER TABLE [dbo].[pb_account_codes] CHECK CONSTRAINT [CK_pb_account_codes_DestinationType]
GO
ALTER TABLE [dbo].[pb_account_codes]  WITH CHECK ADD  CONSTRAINT [CK_pb_account_codes_MaxAttempts] CHECK  (([MaxAttempts]>(0)))
GO
ALTER TABLE [dbo].[pb_account_codes] CHECK CONSTRAINT [CK_pb_account_codes_MaxAttempts]
GO
ALTER TABLE [dbo].[pb_account_statuses]  WITH CHECK ADD  CONSTRAINT [CK_pb_account_statuses_DisplayOrder_Positive] CHECK  (([DisplayOrder]>(0)))
GO
ALTER TABLE [dbo].[pb_account_statuses] CHECK CONSTRAINT [CK_pb_account_statuses_DisplayOrder_Positive]
GO
ALTER TABLE [dbo].[pb_accounts]  WITH CHECK ADD  CONSTRAINT [CK_pb_accounts_Email_NotBlank] CHECK  ((len(ltrim(rtrim([Email])))>(0)))
GO
ALTER TABLE [dbo].[pb_accounts] CHECK CONSTRAINT [CK_pb_accounts_Email_NotBlank]
GO
ALTER TABLE [dbo].[pb_member_write_audit]  WITH CHECK ADD  CONSTRAINT [CK_pb_member_write_audit_operation] CHECK  (([Operation]=N'member.edit' OR [Operation]=N'member.add'))
GO
ALTER TABLE [dbo].[pb_member_write_audit] CHECK CONSTRAINT [CK_pb_member_write_audit_operation]
GO
ALTER TABLE [dbo].[pb_roles]  WITH CHECK ADD  CONSTRAINT [CK_pb_roles_DisplayOrder_Positive] CHECK  (([DisplayOrder]>(0)))
GO
ALTER TABLE [dbo].[pb_roles] CHECK CONSTRAINT [CK_pb_roles_DisplayOrder_Positive]
GO
ALTER TABLE [dbo].[pb_system_membership_statuses]  WITH CHECK ADD  CONSTRAINT [CK_pb_system_membership_statuses_DisplayOrder_Positive] CHECK  (([DisplayOrder]>(0)))
GO
ALTER TABLE [dbo].[pb_system_membership_statuses] CHECK CONSTRAINT [CK_pb_system_membership_statuses_DisplayOrder_Positive]
GO
ALTER TABLE [dbo].[pb_system_relationships]  WITH CHECK ADD  CONSTRAINT [CK_pb_system_relationships_NoSelfParent] CHECK  (([ParentSystemId] IS NULL OR [ParentSystemId]<>[SystemId]))
GO
ALTER TABLE [dbo].[pb_system_relationships] CHECK CONSTRAINT [CK_pb_system_relationships_NoSelfParent]
GO
ALTER TABLE [dbo].[pb_system_relationships]  WITH CHECK ADD  CONSTRAINT [CK_pb_system_relationships_RelationshipRank] CHECK  (([RelationshipRank]>=(1)))
GO
ALTER TABLE [dbo].[pb_system_relationships] CHECK CONSTRAINT [CK_pb_system_relationships_RelationshipRank]
GO
ALTER DATABASE [PluralBridgeChap2SafeSpine] SET  READ_WRITE 
GO
