Skip to main content

Azure Arc Citus Deployment

How to deploy Azure Arc

Basicly, this guide  provides almost all things required for deployment arc in EKS. There are some tips about this cluster creation

  1. Variables
    image.png
    TF_VAR_client_id: everywhere in description it is named as "Principal name" and if you will see the response of principal creation, it contains "name" field image.png
    But in fact in this variable you need to specify appId

  2. terraform apply
    image.png
    When I did that, this step was failed on deploying windows server VM with issue "file is locked". To avoid this you need to add an additional flag to the command. Result is:
    terraform apply --auto-approve --lock=false

How to create citus cluster and connect to it

  1. Connect via RDP to the machine with arc and open shell.
  2. Login to azdata: azdata login --namespace $env:ARC_DC_NAME
    2.1 It'll output a url with port number defined, this is what you'll use in step 4 for the Controller URL.
  3. Create postgreSQL cluster: azdata arc postgres server create -n postgres01 --workers 2.
  4. Open Azure Data Studio and expand the Connections pane and expand the Azure Arc Controllers are and Connect Controller.
    4.1. If you receive an error: Could not connect to controller https://x.x.x.x:30080 . Microsoft Privacy statement and Azure Data CLI license terms have not been accepted. Execute the command: Azure Data CLI: Accept EULA to accept EULA to enable the features that requires Azure Data CLI. execute azdata login --namespace $env:ARC_DC_NAME --accept-eula ACCEPT_EULA and restart Azure Data Studio
  5. Expand Azure Arc Controllers -> [Your Arc Controller] and select [Your PostgreSQL cluster].
  6. Click on Reset Password button and specify new password for your cluster.
  7. You can connect to your cluster via PgAdmin or any other app

How to create distributed database

  1. Create new database

  2. Add citus extension

  3. Add worker nodes SELECT * from master_add_node('[worker_address]', 5432);

  4. Execute InitialMigration.sql to create db schema on master node

    • InitialMigration.sql can be found here
  5. Execute SELECT * FROM run_command_on_workers($cmd$ [content of InitialMigration.sql] $cmd$); to create db schema on worker nodes. (Citus doesn't propagate CREATE command)

  6. Run the following command on the master node

SELECT * FROM run_command_on_workers($cmd$ 
									 
CREATE SCHEMA IF NOT EXISTS "workflow";
CREATE SCHEMA IF NOT EXISTS "public";
CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA public
									 
$cmd$);
  1. Run the following command on the master node
alter table public."DbAccessLinks" drop constraint "FK_DbAccounts";
alter table public."DbAccountFeatures" drop constraint "FK_DbAccounts";
alter table public."DbAccountSettings" drop constraint "FK_DbAccounts";
alter table public."DbAccountSettings" drop constraint "FK_DbEmailSettings";
alter table public."DbAccounts" drop constraint "FK_BrandingID";
alter table public."DbAuditLogs" drop constraint "FK_DbAccounts";
alter table public."DbAuditLogsToNodeDetails" drop constraint "FK_DbAccounts";
alter table public."DbAuditLogsToNodes" drop constraint "FK_DbAccounts";
alter table public."DbAuditLogsToRoleDetails" drop constraint "FK_DbAccounts";
alter table public."DbAuditLogsToRoles" drop constraint "FK_DbAccounts";
alter table public."DbDocumentRequests" drop constraint "FK_DbAccounts";
alter table public."DbESignatureTransactions" drop constraint "FK_DbAccount";
alter table public."DbEmailImportMappings" drop constraint "FK_AccountID";
alter table public."DbEmailImportMappings" drop constraint "FK_EmailSettingID";
alter table public."DbEmailQueue" drop constraint fk_accounts;
alter table public."DbEmailQueue" drop constraint fk_emailsettings;
alter table public."DbEmailSettingToAccounts" drop constraint fk_account;
alter table public."DbEmailSettingToAccounts" drop constraint fk_emailsetting;
alter table public."DbEmailSettingToUsers" drop constraint fk_emailsetting;
alter table public."DbEmailTemplateToPartner" drop constraint "FK_DbEmailTemplate";
alter table public."DbFileInfoes" drop constraint "FK_AccountID";
alter table public."DbFileQueue" drop constraint "FK_Account";
alter table public."DbNodeAnnotations" drop constraint fk_account;
alter table public."DbNodeClosures" drop constraint "fk_accountID";
alter table public."DbAccessLinksToDocumentRequests" drop constraint "FK_public.DbAccessLinksToDocumentRequests_public.DbAccessLinks_";
alter table public."DbAccessLinksToNodeAndTriggers" drop constraint "FK_public.DbAccessLinksToNodeAndTriggers_public.DbAccessLinks_A";
alter table public."DbAccessLinks" drop constraint "FK_public.DbAccessLinks_public.DbRoles_RoleID_AccountID";
alter table public."DbAccessLinksToDocumentRequests" drop constraint "FK_public.DbAccessLinksToDocumentRequests_public.DbDocumentRequ";
alter table public."DbAccountSettings" drop constraint "FK_public.DbAccountSettings_public.DbSecurityPolicies_DefaultGu";
alter table public."DbAccountSettings" drop constraint "FK_public.DbAccountSettings_public.DbSecurityPolicies_DefaultUs";
alter table public."DbEmailImportMappings" drop constraint "FK_public.DbEmailImportMappings_public.DbNodes_NodeID_AccountID";
alter table public."DbAccessLinksToNodeAndTriggers" drop constraint "FK_public.DbAccessLinksToNodeAndTriggers_public.DbNodes_NodeID_";
alter table public."DbAuditLogsToNodes" drop constraint "FK_public.DbAuditLogsToNodes_public.DbNodes_NodeID_AccountID";
alter table public."DbNodeShares" drop constraint fk_account;
alter table public."DbNodeToFileInfoes" drop constraint "FK_DbAccounts";
alter table public."DbNodes" drop constraint fk_account;
alter table public."DbNotifications" drop constraint "FK_DbAccounts";
alter table public."DbPartners" drop constraint "FK_BrandingID";
alter table public."DbPermissions" drop constraint fk_account;
alter table public."DbPortfolioToNodes" drop constraint "FK_DbPortfolios";
alter table public."DbPortfolioToUsers" drop constraint "FK_DbPortfolios";
alter table public."DbPresetValues" drop constraint "FK_Account";
alter table public."DbProfileItems" drop constraint fk_account;
alter table public."DbProfiles" drop constraint fk_account;
alter table public."DbRetentionChangeReason" drop constraint "FK_DbAccount";
alter table public."DbRoles" drop constraint "FK_DbAccounts";
alter table public."DbSamlConfigurations" drop constraint "FK_DbAccounts";
alter table public."DbSamlResponses" drop constraint "FK_DbAccounts";
alter table public."DbSearchCriteria" drop constraint "fk_parentUserSearchCriteria";
alter table public."DbSecurityPolicies" drop constraint "FK_DbAccounts";
alter table public."DbSfLinks" drop constraint "FK_DbAccounts";
alter table public."DbSfMappings" drop constraint "FK_DbAccounts";
alter table public."DbTriggerToSearchCriteria" drop constraint "FK_DbSearchCriteria";
alter table public."DbUserImageStamps" drop constraint "FK_DbAccounts";
alter table public."DbUserSearchToSearchCriteria" drop constraint "FK_DbSearchCriteria";
alter table public."DbUserSearchToSearchCriteria" drop constraint "FK_DbUserSearches";
alter table public."DbUserSettings" drop constraint "FK_DbEmailSettings";
alter table public."DbUserSettings" drop constraint "FK_DbPortfolios";
alter table public."DbUsers" drop constraint "FK_DbUserSettings";
alter table workflow."DbWorkflowInstanceHistoryRecords" drop constraint "FK_DbWorkflowInstanceHistoryRecordTypes_RecordTypeID";
alter table workflow."DbWorkflowSteps" drop constraint "FK_DbWorkflowStepTypes_TypeID";
alter table public."DbDocumentRequestContainers" drop constraint "DbFileRequestContainers_check";
alter table public."DbDocumentRequests" drop constraint "DbFileRequests_check";
alter table public."DbTimeTriggers" drop constraint "check_timeTrigger_preActionNotificationTimeSpanInDays";
alter table public."DbTimeTriggers" drop constraint "check_timeTrigger_timeSpanInSeconds";
alter table public."DbComponentStatusHistories" drop constraint "FK_public.DbComponentStatusHistories_public.DbComponentStatus_C";
alter table public."DbDocumentRequestAttachments" drop constraint "FK_public.DbDocumentRequestAttachments_public.DbNodes_Attachmen";
alter table public."DbDocumentRequestContainerNodes" drop constraint "FK_public.DbDocumentRequestContainerNodes_public.DbNodes_NodeID";
alter table public."DbDocumentRequests" drop constraint "FK_public.DbDocumentRequests_public.DbNodes_DestinationNodeID_A";
alter table public."DbEmailQueueAttachmentNodes" drop constraint "FK_public.DbEmailQueueAttachmentNodes_public.DbNodes_NodeID_Acc";
alter table public."DbESignatureNodeAssociations" drop constraint "FK_public.DbESignatureNodeAssociations_public.DbNodes_OriginalN";
alter table public."DbESignatureNodeAssociations" drop constraint "FK_public.DbESignatureNodeAssociations_public.DbNodes_SignedNod";
alter table public."DbESignatureTransactions" drop constraint "FK_public.DbESignatureTransactions_public.DbNodes_AuditTrailNod";
alter table public."DbESignatureTransactions" drop constraint "FK_public.DbESignatureTransactions_public.DbNodes_AuditTrailPar";
alter table public."DbESignatureTransactions" drop constraint "FK_public.DbESignatureTransactions_public.DbNodes_SignedDocumen";
alter table public."DbNodes" drop constraint "FK_public.DbNodes_public.DbFileInfoes_FileInfoID_AccountID";
alter table public."DbFileQueue" drop constraint "FK_public.DbFileQueue_public.DbNodes_NodeID_AccountID";
alter table public."DbLegacyNodeMappings" drop constraint "FK_public.DbLegacyNodeMappings_public.DbNodes_NodeId_AccountID";
alter table public."DbNodes" drop constraint "FK_public.DbNodes_public.DbNodes_ParentID_AccountID";
alter table public."DbNodeAnnotations" drop constraint "FK_public.DbNodeAnnotations_public.DbNodes_NodeID_AccountID";
alter table public."DbNodeClosures" drop constraint "FK_public.DbNodeClosures_public.DbNodes_ChildID_AccountID";
alter table public."DbRoleRelationships" drop constraint "Parent_Is_Group";
alter table public."DbAccessLinks" drop constraint "FK_public.DbAccessLinks_public.DbUsers_CreatedByUserID";
alter table public."DbAuditLogs" drop constraint "FK_public.DbAuditLogs_public.DbUsers_UserID";
alter table public."DbAuditLogs" drop constraint "FK_public.DbAuditLogs_public.DbUsers_GeneratedByUserID";
alter table public."DbDocumentRequests" drop constraint "FK_public.DbDocumentRequests_public.DbUsers_CreatedByUserID";
alter table public."DbEmailImportMappings" drop constraint "FK_public.DbEmailImportMappings_public.DbUsers_CreatedByUserID";
alter table public."DbESignatureTransactions" drop constraint "FK_public.DbESignatureTransactions_public.DbUsers_UserID";
alter table public."DbFileInfoes" drop constraint "FK_public.DbFileInfoes_public.DbUsers_CreatedByUserID";
alter table public."DbNodeComments" drop constraint "FK_public.DbNodeComments_public.DbUsers_LastModifiedByUserID";
alter table public."DbNodeComments" drop constraint "FK_public.DbNodeComments_public.DbUsers_CreatedByUserID";
alter table public."DbNodes" drop constraint "FK_public.DbNodes_public.DbUsers_CreatedByUserID";
alter table public."DbPortfolios" drop constraint "FK_public.DbPortfolios_public.DbUsers_OwnerUserID";
alter table public."DbPortfolioToNodes" drop constraint "FK_public.DbPortfolioToNodes_public.DbUsers_AddedByUserID";
alter table public."DbPortfolioToUsers" drop constraint "FK_public.DbPortfolioToUsers_public.DbUsers_UserID";
alter table public."DbResetPasswordRequests" drop constraint "FK_public.DbResetPasswordRequests_public.DbUsers_UserID";
alter table public."DbRightSignatureUsers" drop constraint "FK_public.DbRightSignatureUsers_public.DbUsers_UserID";
alter table public."DbRoles" drop constraint "FK_public.DbRoles_public.DbUsers_UserID";
alter table public."DbSamlConfigurations" drop constraint "FK_public.DbSamlConfigurations_public.DbUsers_CreatedByUserID";
alter table public."DbTriggers" drop constraint "FK_public.DbTriggers_public.DbUsers_CreatedByUserID";
alter table public."DbUserApplicationsMfa" drop constraint "FK_public.DbUserApplicationsMfa_public.DbUsers_UserID";
alter table public."DbUserExternalAuthentications" drop constraint "FK_public.DbUserExternalAuthentications_public.DbUsers_UserID";
alter table public."DbUserImageStamps" drop constraint "FK_public.DbUserImageStamps_public.DbUsers_UserID";
alter table public."DbUserPasswordHistories" drop constraint "FK_public.DbUserPasswordHistories_public.DbUsers_UserID";
alter table public."DbUserSearches" drop constraint "FK_public.DbUserSearches_public.DbUsers_UserID";
alter table public."DbUserSessions" drop constraint "FK_public.DbUserSessions_public.DbUsers_UserID";
alter table public."DbUserSessions" drop constraint "FK_public.DbUserSessions_public.DbUsers_GeneratedByUserID";
alter table public."DbEmailSettingToUsers" drop constraint "FK_public.DbEmailSettingToUsers_public.DbUsers_UserID";
alter table public."DbRightSignatureDocuments" drop constraint "FK_public.DbRightSignatureDocuments_public.DbRightSignatureUser";
alter table public."DbFormFillPendings" drop constraint "FK_public.DbFormFillPendings_public.DbUsers_UserID";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowSteps_Db";
alter table workflow."DbWorkflowInstances" drop constraint "FK_workflow.DbWorkflowInstances_workflow.DbWorkflowInstanceStat";
alter table workflow."DbStageApproveResults" drop constraint "FK_workflow.DbStageApproveResults_workflow.DbWorkflowStageInsta";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI1";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI2";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI3";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI4";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI5";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI6";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI7";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI8";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI9";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset10";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset11";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset12";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset14";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset15";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset16";
alter table workflow."DbWorkflowESignatureStepInstanceUserReferences" drop constraint "FK_workflow.DbWorkflowESignatureStepInstanceUserReferences_wor1";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset17";
alter table workflow."DbWorkflowESignatureStepInstanceTemplateDocuments" drop constraint "FK_workflow.DbWorkflowESignatureStepInstanceTemplateDocuments_1";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset18";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset19";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset20";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset21";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset22";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset23";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset24";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset25";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset26";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset27";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset28";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset29";
alter table workflow."DbWorkflowStepInstanceDocumentRequestContainers" drop constraint "FK_workflow.DbWorkflowStepInstanceDocumentRequestContainers_wo1";
alter table workflow."DbAssetInstanceNodeReferences" drop constraint "FK_workflow.DbAssetInstanceNodeReferences_workflow.DbWorkflowAs";
alter table workflow."DbWorkflowAssetsStagesInstances" drop constraint "FK_workflow.DbWorkflowAssetsStagesInstances_workflow.DbWorkflo1";
alter table workflow."DbWorkflowStepInstanceEmailUserGroups" drop constraint "FK_workflow.DbWorkflowStepInstanceEmailUserGroups_workflow.DbWo";
alter table workflow."DbWorkflowStepInstanceEmailUsers" drop constraint "FK_workflow.DbWorkflowStepInstanceEmailUsers_workflow.DbWorkflo";
alter table workflow."DbWorkflowESignatureStepInstanceUserReferences" drop constraint "FK_workflow.DbWorkflowESignatureStepInstanceUserReferences_wor2";
alter table workflow."DbWorkflowESignatureStepInstanceTemplateDocuments" drop constraint "FK_workflow.DbWorkflowESignatureStepInstanceTemplateDocuments_2";
alter table workflow."DbWorkflowSendMessageInstanceRecipients" drop constraint "FK_workflow.DbWorkflowSendMessageInstanceRecipients_workflow.Db";
alter table workflow."DbWorkflowStepInstanceUserGroups" drop constraint "FK_workflow.DbWorkflowStepInstanceUserGroups_workflow.DbWorkflo";
alter table workflow."DbWorkflowStepInstanceUsers" drop constraint "FK_workflow.DbWorkflowStepInstanceUsers_workflow.DbWorkflowStep";
alter table workflow."DbWorkflowSetProfileInstanceItems" drop constraint "FK_workflow.DbWorkflowSetProfileInstanceItems_workflow.DbWorkfl";
alter table workflow."DbWorkflowShareStepInstanceNewUserReferences" drop constraint "FK_workflow.DbWorkflowShareStepInstanceNewUserReferences_workfl";
alter table workflow."DbWorkflowStepInstanceGroupReferences" drop constraint "FK_workflow.DbWorkflowStepInstanceGroupReferences_workflow.DbWo";
alter table workflow."DbWorkflowStepInstanceUserReferences" drop constraint "FK_workflow.DbWorkflowStepInstanceUserReferences_workflow.DbWor";
alter table workflow."DbWorkflowInstanceHistoryRecords" drop constraint "FK_workflow.DbWorkflowInstanceHistoryRecords_workflow.DbWorkfl1";
alter table workflow."DbWorkflowStepInstanceDocumentRequestContainers" drop constraint "FK_workflow.DbWorkflowStepInstanceDocumentRequestContainers_wo2";
alter table workflow."DbWorkflowRequestFileExternalStepInstanceRecipientGroups" drop constraint "FK_workflow.DbWorkflowRequestFileExternalStepInstanceRecipientG";
alter table workflow."DbWorkflowRequestFileExternalStepInstanceNewUserReferences" drop constraint "FK_workflow.DbWorkflowRequestFileExternalStepInstanceNewUserRef";
alter table workflow."DbWorkflowRequestFileExternalStepInstanceRecipients" drop constraint "FK_workflow.DbWorkflowRequestFileExternalStepInstanceRecipients";
alter table workflow."DbWorkflowStepDocumentRequestContainers" drop constraint "FK_workflow.DbWorkflowStepDocumentRequestContainers_workflow.D1";
alter table workflow."DbWorkflowRequestFileExternalStepRecipientGroups" drop constraint "FK_workflow.DbWorkflowRequestFileExternalStepRecipientGroups_wo";
alter table workflow."DbWorkflowRequestFileExternalStepNewUserReferences" drop constraint "FK_workflow.DbWorkflowRequestFileExternalStepNewUserReferences_";
alter table workflow."DbWorkflowRequestFileExternalStepRecipients" drop constraint "FK_workflow.DbWorkflowRequestFileExternalStepRecipients_workflo";
alter table workflow."DbWorkflowAddTriggerStepEmailUserGroups" drop constraint "FK_workflow.DbWorkflowAddTriggerStepEmailUserGroups_workflow.Db";
alter table workflow."DbWorkflowAddTriggerStepEmailUsers" drop constraint "FK_workflow.DbWorkflowAddTriggerStepEmailUsers_workflow.DbWorkf";
alter table workflow."DbWorkflowESignatureStepUserReferences" drop constraint "FK_workflow.DbWorkflowESignatureStepUserReferences_workflow.DbW";
alter table workflow."DbWorkflowESignatureStepTemplateDocuments" drop constraint "FK_workflow.DbWorkflowESignatureStepTemplateDocuments_workflow1";
alter table workflow."DbWorkflowSendMessageRecipients" drop constraint "FK_workflow.DbWorkflowSendMessageRecipients_workflow.DbWorkflow";
alter table workflow."DbWorkflowSetPermissionsStepUserGroups" drop constraint "FK_workflow.DbWorkflowSetPermissionsStepUserGroups_workflow.DbW";
alter table workflow."DbWorkflowSetPermissionsStepUsers" drop constraint "FK_workflow.DbWorkflowSetPermissionsStepUsers_workflow.DbWorkfl";
alter table public."DbNodeClosures" drop constraint "FK_public.DbNodeClosures_public.DbNodes_ParentID_AccountID";
alter table public."DbTriggers" drop constraint "FK_public.DbTriggers_public.DbAccounts_AccountID";
alter table public."DbEmailContent" drop constraint "FK_public.DbEmailContent_public.DbAccounts_AccountID";
alter table public."DbEventTriggers" drop constraint "FK_public.DbEventTriggers_public.DbAccounts_AccountID";
alter table public."DbTimeTriggers" drop constraint "FK_public.DbTimeTriggers_public.DbAccounts_AccountID";
alter table public."DbTriggerInfoNodes" drop constraint "FK_public.DbTriggerInfoNodes_public.DbAccounts_AccountID";
alter table public."DbTriggerToNode" drop constraint "FK_public.DbTriggerToNode_public.DbAccounts_AccountID";
alter table public."DbTriggerToWorkflow" drop constraint "FK_public.DbTriggerToWorkflow_public.DbAccounts_AccountID";
alter table public."DbTriggerToRoles" drop constraint "FK_public.DbTriggerToRoles_public.DbAccounts_AccountID";
alter table public."DbTriggerToSearchCriteria" drop constraint "FK_public.DbTriggerToSearchCriteria_public.DbAccounts_AccountID";
alter table public."DbProfileValueNodes" drop constraint "FK_public.DbProfileValueNodes_public.DbAccounts_AccountID";
alter table public."DbProfileToProfileItems" drop constraint "FK_public.DbProfileToProfileItems_public.DbAccounts_AccountID";
alter table public."DbProfileValueRoles" drop constraint "FK_public.DbProfileValueRoles_public.DbAccounts_AccountID";
alter table public."DbRoleRelationships" drop constraint "FK_public.DbRoleRelationships_public.DbAccounts_AccountID";
alter table public."DbRoleToAccountFeatures" drop constraint "FK_public.DbRoleToAccountFeatures_public.DbAccounts_AccountID";
alter table public."DbSystemPermissions" drop constraint "FK_public.DbSystemPermissions_public.DbAccounts_AccountID";
alter table public."DbEmailQueueAttachmentNodes" drop constraint "FK_public.DbEmailQueueAttachmentNodes_public.DbAccounts_Account";
alter table public."DbTemplateNodeChangeLogs" drop constraint "FK_public.DbTemplateNodeChangeLogs_public.DbAccounts_AccountID";
alter table public."DbTemplateNodeLinks" drop constraint "FK_public.DbTemplateNodeLinks_public.DbAccounts_AccountID";
alter table public."DbWorkflowStageInstanceToNotifications" drop constraint "FK_public.DbWorkflowStageInstanceToNotifications_public.DbAccou";
alter table public."DbRoleClosures" drop constraint "FK_public.DbRoleClosures_public.DbAccounts_AccountID";
alter table public."DbAccessLinksToNodeAndTriggers" drop constraint "FK_public.DbAccessLinksToNodeAndTriggers_public.DbAccounts_Acco";
alter table public."DbDocumentRequestRoles" drop constraint "FK_public.DbDocumentRequestRoles_public.DbAccounts_AccountID";
alter table public."DbNodeComments" drop constraint "FK_public.DbNodeComments_public.DbNodes_NodeID_AccountID";
alter table public."DbNodeShares" drop constraint "FK_public.DbNodeShares_public.DbNodes_AccountWorkspaceNodeID_Ac";
alter table public."DbNodeShares" drop constraint "FK_public.DbNodeShares_public.DbNodes_SharedWorkspaceNodeID_Acc";
alter table public."DbNodeToFileInfoes" drop constraint "FK_public.DbNodeToFileInfoes_public.DbNodes_NodeID_AccountID";
alter table public."DbPermissions" drop constraint "FK_public.DbPermissions_public.DbNodes_NodeID_AccountID";
alter table public."DbNodes" drop constraint "FK_public.DbNodes_public.DbProfiles_ProfileID_AccountID";
alter table public."DbProfileValueNodes" drop constraint "FK_public.DbProfileValueNodes_public.DbNodes_NodeID_AccountID";
alter table public."DbRightSignatureDocuments" drop constraint "FK_public.DbRightSignatureDocuments_public.DbNodes_NodeID_Accou";
alter table public."DbSfLinks" drop constraint "FK_public.DbSfLinks_public.DbNodes_NodeID_AccountID";
alter table public."DbSfMappings" drop constraint "FK_public.DbSfMappings_public.DbNodes_ParentNodeID_AccountID";
alter table public."DbTemplateNodeChangeLogs" drop constraint "FK_public.DbTemplateNodeChangeLogs_public.DbNodes_TemplateNodeI";
alter table public."DbTemplateNodeLinks" drop constraint "FK_public.DbTemplateNodeLinks_public.DbNodes_AppliedNodeID_Acco";
alter table public."DbTemplateNodeLinks" drop constraint "FK_public.DbTemplateNodeLinks_public.DbNodes_TemplateNodeID_Acc";
alter table public."DbTriggerInfoNodes" drop constraint "FK_public.DbTriggerInfoNodes_public.DbNodes_NodeID_AccountID";
alter table public."DbTriggerToNode" drop constraint "FK_public.DbTriggerToNode_public.DbNodes_NodeID_AccountID";
alter table public."DbUserImageStamps" drop constraint "FK_public.DbUserImageStamps_public.DbNodes_NodeID_AccountID";
alter table public."DbAccessLinksToNodeAndTriggers" drop constraint "FK_public.DbAccessLinksToNodeAndTriggers_public.DbTriggers_Trig";
alter table public."DbTriggers" drop constraint "FK_public.DbTriggers_public.DbEmailContent_EmailContentID_Accou";
alter table public."DbEventTriggers" drop constraint "FK_public.DbEventTriggers_public.DbTriggers_TriggerID_AccountID";
alter table public."DbTimeTriggers" drop constraint "FK_public.DbTimeTriggers_public.DbTriggers_TriggerID_AccountID";
alter table public."DbTriggerInfoNodes" drop constraint "FK_public.DbTriggerInfoNodes_public.DbTriggers_TriggerID_Accoun";
alter table public."DbTriggerToApiCallouts" drop constraint "FK_public.DbTriggerToApiCallouts_public.DbTriggers_TriggerID_Ac";
alter table public."DbTriggerToNode" drop constraint "FK_public.DbTriggerToNode_public.DbTriggers_TriggerID_AccountID";
alter table public."DbTriggerToRoles" drop constraint "FK_public.DbTriggerToRoles_public.DbTriggers_TriggerID_AccountI";
alter table public."DbTriggerToSearchCriteria" drop constraint "FK_public.DbTriggerToSearchCriteria_public.DbTriggers_TriggerID";
alter table public."DbTriggerToWorkflow" drop constraint "FK_public.DbTriggerToWorkflow_public.DbTriggers_TriggerID_Accou";
alter table public."DbWatermarkTriggerInfo" drop constraint "FK_public.DbWatermarkTriggerInfo_public.DbTriggers_TriggerID_Ac";
alter table public."DbTriggerToRoles" drop constraint "FK_public.DbTriggerToRoles_public.DbRoles_RoleID_AccountID";
alter table public."DbAuditLogsToRoles" drop constraint "FK_public.DbAuditLogsToRoles_public.DbRoles_RoleID_AccountID";
alter table public."DbDocumentRequestRoles" drop constraint "FK_public.DbDocumentRequestRoles_public.DbRoles_RecipientRoleID";
alter table public."DbESignatureSigners" drop constraint "FK_public.DbESignatureSigners_public.DbRoles_RoleID_AccountID";
alter table public."DbFileInfoes" drop constraint "FK_public.DbFileInfoes_public.DbRoles_CheckedOutByRoleID_Accoun";
alter table public."DbNodeShares" drop constraint "FK_public.DbNodeShares_public.DbRoles_RoleID_AccountID";
alter table public."DbNotifications" drop constraint "FK_public.DbNotifications_public.DbRoles_RecipientRoleID_Accoun";
alter table public."DbPermissions" drop constraint "FK_public.DbPermissions_public.DbRoles_RoleID_AccountID";
alter table public."DbRoles" drop constraint "FK_public.DbRoles_public.DbProfiles_ProfileID_AccountID";
alter table public."DbProfileValueRoles" drop constraint "FK_public.DbProfileValueRoles_public.DbRoles_RoleID_AccountID";
alter table public."DbRoleClosures" drop constraint "FK_public.DbRoleClosures_public.DbRoles_ChildID_AccountID";
alter table public."DbRoleClosures" drop constraint "FK_public.DbRoleClosures_public.DbRoles_ParentID_AccountID";
alter table public."DbRoles" drop constraint "FK_public.DbRoles_public.DbRoles_RoleManagerID_AccountID";
alter table public."DbRoleRelationships" drop constraint "FK_public.DbRoleRelationships_public.DbRoles_ParentRoleID_Accou";
alter table public."DbRoleRelationships" drop constraint "FK_public.DbRoleRelationships_public.DbRoles_ChildRoleID_Accoun";
alter table public."DbRoleToAccountFeatures" drop constraint "FK_public.DbRoleToAccountFeatures_public.DbRoles_RoleID_Account";
alter table public."DbSamlConfigurations" drop constraint "FK_public.DbSamlConfigurations_public.DbRoles_DefaultGroupID_Ac";
alter table public."DbRoles" drop constraint "FK_public.DbRoles_public.DbSecurityPolicies_SecurityPolicyID_Ac";
alter table public."DbRoles" drop constraint "FK_public.DbRoles_public.DbSystemPermissions_SystemPermissionID";
alter table public."DbUserRolePreferences" drop constraint "FK_public.DbUserRolePreferences_public.DbRoles_RoleID_AccountID";
alter table public."DbUserSessions" drop constraint "FK_public.DbUserSessions_public.DbRoles_RoleID_AccountID";
alter table public."DbUserSessionToDbRoles" drop constraint "FK_public.DbUserSessionToDbRoles_public.DbRoles_RoleID_AccountI";
alter table public."DbAuditLogsToRoles" drop constraint "FK_public.DbAuditLogsToRoles_public.DbAuditLogs_AuditLogID_Acco";
alter table public."DbAuditLogsToRoleDetails" drop constraint "FK_public.DbAuditLogsToRoleDetails_public.DbAuditLogsToRoles_Au";
alter table public."DbAuditLogsToNodes" drop constraint "FK_public.DbAuditLogsToNodes_public.DbAuditLogs_AuditLogID_Acco";
alter table public."DbAuditLogsToNodeDetails" drop constraint "FK_public.DbAuditLogsToNodeDetails_public.DbAuditLogsToNodes_Au";
alter table public."DbDocumentRequestAttachments" drop constraint "FK_public.DbDocumentRequestAttachments_public.DbDocumentRequest";
alter table public."DbDocumentRequestContainers" drop constraint "FK_public.DbDocumentRequestContainers_public.DbDocumentRequests";
alter table public."DbDocumentRequestRoles" drop constraint "FK_public.DbDocumentRequestRoles_public.DbDocumentRequests_Docu";
alter table public."DbDocumentRequestToNotifications" drop constraint "FK_public.DbDocumentRequestToNotifications_public.DbDocumentReq";
alter table public."DbDocumentRequestContainerNodes" drop constraint "FK_public.DbDocumentRequestContainerNodes_public.DbDocumentRequ";
alter table public."DbDocumentRequestContainers" drop constraint "FK_public.DbDocumentRequestContainers_public.DbFileInfoes_FileI";
alter table public."DbDocumentRequestContainers" drop constraint "FK_public.DbDocumentRequestContainers_public.DbFormFillDefiniti";
alter table public."DbFileQueue" drop constraint "FK_public.DbFileQueue_public.DbFileInfoes_FileInfoID_AccountID";
alter table public."DbFileInfoes" drop constraint "FK_public.DbFileInfoes_public.DbFormFillDefinitions_FormFillDef";
alter table public."DbFileInfoes" drop constraint "FK_public.DbFileInfoes_public.DbNodeComments_NodeCommentID_Acco";
alter table public."DbNodeToFileInfoes" drop constraint "FK_public.DbNodeToFileInfoes_public.DbFileInfoes_FileInfoID_Acc";
alter table public."DbFileInfoes" drop constraint "FK_public.DbFileInfoes_public.DbFileInfoes_GeneratedFromFileInf";
alter table public."DbFormFillPendings" drop constraint "FK_public.DbFormFillPendings_public.DbFormFillDefinitions_FormF";
alter table public."DbFormFillToProfileItems" drop constraint "FK_public.DbFormFillToProfileItems_public.DbFormFillDefinitions";
alter table public."DbFormFillDefinitions" drop constraint "FK_public.DbFormFillDefinitions_public.DbProfiles_ProfileID_Acc";
alter table public."DbFormFillPendings" drop constraint "FK_public.DbFormFillPendings_public.DbFileInfoes_AppliedNodeFil";
alter table public."DbFormFillToProfileItems" drop constraint "FK_public.DbFormFillToProfileItems_public.DbProfileItems_Profil";
alter table public."DbPresetValues" drop constraint "FK_public.DbPresetValues_public.DbProfileItems_ProfileItemID_Ac";
alter table public."DbProfileToProfileItems" drop constraint "FK_public.DbProfileToProfileItems_public.DbProfileItems_Profile";
alter table public."DbProfileValueNodes" drop constraint "FK_public.DbProfileValueNodes_public.DbProfileItems_ProfileItem";
alter table public."DbProfileValueRoles" drop constraint "FK_public.DbProfileValueRoles_public.DbProfileItems_ProfileItem";
alter table public."DbProfileValueNodes" drop constraint "FK_public.DbProfileValueNodes_public.DbPresetValues_PresetValue";
alter table public."DbProfileValueRoles" drop constraint "FK_public.DbProfileValueRoles_public.DbPresetValues_PresetValue";
alter table public."DbProfileValueNodes" drop constraint "FK_public.DbProfileValueNodes_public.DbProfiles_ProfileID_Accou";
alter table public."DbProfileToProfileItems" drop constraint "FK_public.DbProfileToProfileItems_public.DbProfiles_ProfileID_A";
alter table public."DbProfileValueRoles" drop constraint "FK_public.DbProfileValueRoles_public.DbProfiles_ProfileID_Accou";
alter table public."DbDocumentRequestToNotifications" drop constraint "FK_public.DbDocumentRequestToNotifications_public.DbNotificatio";
alter table public."DbWorkflowStageInstanceToNotifications" drop constraint "FK_public.DbWorkflowStageInstanceToNotifications_public.DbNotif";
alter table public."DbESignatureNodeAssociations" drop constraint "FK_public.DbESignatureNodeAssociations_public.DbESignatureTrans";
alter table public."DbESignatureSigners" drop constraint "FK_public.DbESignatureSigners_public.DbESignatureTransactions_T";
alter table public."DbESignatureTransactions" drop constraint "FK_public.DbESignatureTransactions_public.DbESignatureTransacti";
alter table public."DbSamlResponses" drop constraint "FK_public.DbSamlResponses_public.DbSamlConfigurations_Configura";
alter table public."DbPermissions" drop constraint "FK_public.DbPermissions_public.DbPermissions_ChildPermissionId_";
alter table public."DbSecurityPolicyIpAddresses" drop constraint "FK_public.DbSecurityPolicyIpAddresses_public.DbSecurityPolicies";
alter table public."DbSecurityPolicyLoginTimes" drop constraint "FK_public.DbSecurityPolicyLoginTimes_public.DbSecurityPolicies_";
alter table public."DbEmailQueueAttachmentNodes" drop constraint "FK_public.DbEmailQueueAttachmentNodes_public.DbEmailQueue_Email";
alter table public."DbEmailRecipients" drop constraint "FK_public.DbEmailRecipients_public.DbEmailQueue_EmailQueueID_Ac";
alter table public."DbSfLinks" drop constraint "FK_public.DbSfLinks_public.DbSfMappings_SfMappingID_AccountID";
alter table public."DbSfMappings" drop constraint "FK_public.DbSfMappings_public.DbPermissions_GroupPermissionID_A";
alter table public."DbSfMappings" drop constraint "FK_public.DbSfMappings_public.DbPermissions_UserPermissionID_Ac";
alter table public."DbEmailTemplateToPartner" drop constraint "FK_public.DbEmailTemplateToPartner_public.DbPartners_PartnerID";
alter table public."DbUserSessionToDbRoles" drop constraint "FK_public.DbUserSessionToDbRoles_public.DbUserSessions_UserSess";
alter table workflow."DbWorkflowSetProfileItems" drop constraint "FK_workflow.DbWorkflowSetProfileItems_workflow.DbWorkflowSteps_";
alter table workflow."DbWorkflowShareStepNewUserReferences" drop constraint "FK_workflow.DbWorkflowShareStepNewUserReferences_workflow.DbWor";
alter table workflow."DbWorkflowStepGroupReferences" drop constraint "FK_workflow.DbWorkflowStepGroupReferences_workflow.DbWorkflowSt";
alter table workflow."DbWorkflowStepUserReferences" drop constraint "FK_workflow.DbWorkflowStepUserReferences_workflow.DbWorkflowSte";
alter table workflow."DbWorkflowAssetsStages" drop constraint "FK_workflow.DbWorkflowAssetsStages_workflow.DbWorkflowStages_St";
alter table workflow."DbWorkflowStageInstances" drop constraint "FK_workflow.DbWorkflowStageInstances_workflow.DbWorkflowStages_";
alter table workflow."DbWorkflowStageApproverGroups" drop constraint "FK_workflow.DbWorkflowStageApproverGroups_workflow.DbWorkflowSt";
alter table workflow."DbWorkflowStageApprovers" drop constraint "FK_workflow.DbWorkflowStageApprovers_workflow.DbWorkflowStages_";
alter table workflow."DbWorkflowStageAssigneeGroups" drop constraint "FK_workflow.DbWorkflowStageAssigneeGroups_workflow.DbWorkflowSt";
alter table workflow."DbWorkflowStageAssignees" drop constraint "FK_workflow.DbWorkflowStageAssignees_workflow.DbWorkflowStages_";
alter table workflow."DbProfileRoutingRules" drop constraint "FK_workflow.DbProfileRoutingRules_workflow.DbWorkflowStages_Sta";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowStages_StageID";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_requestF1";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_requestF2";
alter table workflow."DbWorkflowStepDocumentRequestContainers" drop constraint "FK_workflow.DbWorkflowStepDocumentRequestContainers_workflow.D2";
alter table workflow."DbAssetNodeReference" drop constraint "FK_workflow.DbAssetNodeReference_workflow.DbWorkflowAssets_Asse";
alter table workflow."DbWorkflowAssetsStages" drop constraint "FK_workflow.DbWorkflowAssetsStages_workflow.DbWorkflowAssets_As";
alter table workflow."DbWorkflowStages" drop constraint "FK_workflow.DbWorkflowStages_workflow.DbWorkflowAssets_Approval";
alter table workflow."DbProfileRoutingRules" drop constraint "FK_workflow.DbProfileRoutingRules_workflow.DbWorkflowAssets_Ass";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_addTrigg1";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_addTrigg2";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_applyTemp";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_comment_T";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_copy_Dest";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_copy_Resu";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_copy_Sour";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_createLo1";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_createLo2";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_delete_Ta";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_esignatu1";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_esignatu2";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_esignatu3";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_esignatu4";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_esignatu5";
alter table workflow."DbWorkflowESignatureStepTemplateDocuments" drop constraint "FK_workflow.DbWorkflowESignatureStepTemplateDocuments_workflow2";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_move_Dest";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_move_Sour";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_rename_Ta";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_sendMessa";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_setPermis";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_setProfil";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_setReten1";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_setReten2";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_share_Sou";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_upload_Re";
alter table workflow."DbWorkflowSteps" drop constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_upload_So";
alter table workflow."DbWorkflowAssetInstances" drop constraint "FK_workflow.DbWorkflowAssetInstances_workflow.DbWorkflowAssets_";
alter table workflow."DbWorkflowAssets" drop constraint "FK_workflow.DbWorkflowAssets_workflow.DbWorkflows_WorkflowID";
alter table workflow."DbWorkflowInstanceHistoryRecords" drop constraint "FK_workflow.DbWorkflowInstanceHistoryRecords_workflow.DbWorkfl2";
alter table workflow."DbWorkflowInstances" drop constraint "FK_workflow.DbWorkflowInstances_workflow.DbWorkflows_WorkflowID";
alter table workflow."DbWorkflowsAvailableStates" drop constraint "FK_workflow.DbWorkflowsAvailableStates_workflow.DbWorkflows_Wor";
alter table workflow."DbWorkflowNotificationConfigurations" drop constraint "FK_workflow.DbWorkflowNotificationConfigurations_workflow.DbWor";
alter table workflow."DbWorkflowOwnerGroups" drop constraint "FK_workflow.DbWorkflowOwnerGroups_workflow.DbWorkflows_Workflow";
alter table workflow."DbWorkflowOwners" drop constraint "FK_workflow.DbWorkflowOwners_workflow.DbWorkflows_WorkflowID";
alter table workflow."DbWorkflowScheduleConfigurations" drop constraint "FK_workflow.DbWorkflowScheduleConfigurations_workflow.DbWorkflo";
alter table workflow."DbWorkflowStages" drop constraint "FK_workflow.DbWorkflowStages_workflow.DbWorkflows_WorkflowID";
alter table workflow."DbWorkflowStarterGroups" drop constraint "FK_workflow.DbWorkflowStarterGroups_workflow.DbWorkflows_Workfl";
alter table workflow."DbWorkflowStarters" drop constraint "FK_workflow.DbWorkflowStarters_workflow.DbWorkflows_WorkflowID";
alter table workflow."DbWorkflowWatcherGroups" drop constraint "FK_workflow.DbWorkflowWatcherGroups_workflow.DbWorkflows_Workfl";
alter table workflow."DbWorkflowWatchers" drop constraint "FK_workflow.DbWorkflowWatchers_workflow.DbWorkflows_WorkflowID";
alter table workflow."DbWorkflowsAvailableStates" drop constraint "FK_workflow.DbWorkflowsAvailableStates_workflow.DbWorkflowInsta";
alter table workflow."DbWorkflowStages" drop constraint "FK_workflow.DbWorkflowStages_workflow.DbWorkflowInstanceStates1";
alter table workflow."DbWorkflowStages" drop constraint "FK_workflow.DbWorkflowStages_workflow.DbWorkflowInstanceStates2";
alter table workflow."DbWorkflowStages" drop constraint "FK_workflow.DbWorkflowStages_workflow.DbWorkflowInstanceStates3";
alter table workflow."DbProfileRoutingRules" drop constraint "FK_workflow.DbProfileRoutingRules_workflow.DbWorkflowInstanceSt";
alter table workflow."DbWorkflowStages" drop constraint "FK_workflow.DbWorkflowStages_workflow.DbWorkflowInstanceStates4";
alter table workflow."DbWorkflowAssetInstances" drop constraint "FK_workflow.DbWorkflowAssetInstances_workflow.DbWorkflowInstanc";
alter table workflow."DbWorkflowInstanceHistoryRecords" drop constraint "FK_workflow.DbWorkflowInstanceHistoryRecords_workflow.DbWorkfl3";
alter table workflow."DbWorkflowStageInstances" drop constraint "FK_workflow.DbWorkflowStageInstances_workflow.DbWorkflowInstanc";
alter table workflow."DbWorkflowInstanceHistoryRecords" drop constraint "FK_workflow.DbWorkflowInstanceHistoryRecords_workflow.DbWorkfl4";
alter table workflow."DbWorkflowStepInstances" drop constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowStageIns";
alter table workflow."DbWorkflowInstances" drop constraint "FK_workflow.DbWorkflowInstances_workflow.DbWorkflowStageInstanc";
alter table workflow."DbWorkflowAssetsStagesInstances" drop constraint "FK_workflow.DbWorkflowAssetsStagesInstances_workflow.DbWorkflo2";
alter table workflow."DbWorkflowSetProfileInstanceItemPresetValues" drop constraint "FK_workflow.DbWorkflowSetProfileInstanceItemPresetValues_workfl";
alter table workflow."DbWorkflowSetProfileItemPresetValues" drop constraint "FK_workflow.DbWorkflowSetProfileItemPresetValues_workflow.DbWor";
alter table public."DbWorkflowStageInstanceToNotifications" drop constraint "FK_DbWorkflowStageInstanceToNotifications_DbWorkflowStageInstan";
alter table public."DbRoles" drop constraint "CK_RoleManagerID";
alter table public."DbDocumentRequestAttachments" drop constraint "FK_public.DbDocumentRequestAttachments_public.DbAccounts_Accoun";
alter table public."DbFormFillDefinitions" drop constraint "FK_public.DbFormFillDefinitions_public.DbAccounts_AccountID";
alter table public."DbDocumentRequestContainers" drop constraint "FK_public.DbDocumentRequestContainers_public.DbAccounts_Account";
alter table public."DbDocumentRequestContainerNodes" drop constraint "FK_public.DbDocumentRequestContainerNodes_public.DbAccounts_Acc";
alter table public."DbFormFillPendings" drop constraint "FK_public.DbFormFillPendings_public.DbAccounts_AccountID";
alter table public."DbFormFillToProfileItems" drop constraint "FK_public.DbFormFillToProfileItems_public.DbAccounts_AccountID";
alter table public."DbNodeComments" drop constraint "FK_public.DbNodeComments_public.DbAccounts_AccountID";
alter table public."DbESignatureSigners" drop constraint "FK_public.DbESignatureSigners_public.DbAccounts_AccountID";
alter table public."DbESignatureNodeAssociations" drop constraint "FK_public.DbESignatureNodeAssociations_public.DbAccounts_Accoun";
alter table public."DbSecurityPolicyIpAddresses" drop constraint "FK_public.DbSecurityPolicyIpAddresses_public.DbAccounts_Account";
alter table public."DbSecurityPolicyLoginTimes" drop constraint "FK_public.DbSecurityPolicyLoginTimes_public.DbAccounts_AccountI";
alter table public."DbUserRolePreferences" drop constraint "FK_public.DbUserRolePreferences_public.DbAccounts_AccountID";
alter table public."DbTriggerToApiCallouts" drop constraint "FK_public.DbTriggerToApiCallouts_public.DbAccounts_AccountID";
alter table public."DbWatermarkTriggerInfo" drop constraint "FK_public.DbWatermarkTriggerInfo_public.DbAccounts_AccountID";
alter table public."DbLegacyNodeMappings" drop constraint "FK_public.DbLegacyNodeMappings_public.DbAccounts_AccountID";
alter table public."DbAccessLinksToDocumentRequests" drop constraint "FK_public.DbAccessLinksToDocumentRequests_public.DbAccounts_Acc";
alter table public."DbDocumentRequestToNotifications" drop constraint "FK_public.DbDocumentRequestToNotifications_public.DbAccounts_Ac";
alter table public."DbPermissions" drop constraint ck_permission;
DROP TRIGGER tr_dbnode_insert ON "public"."DbNodes";
DROP TRIGGER tr_dbnode_update ON "public"."DbNodes";
DROP TRIGGER tr_dbroleclosures_insert ON "public"."DbRoleClosures";
DROP TRIGGER tr_dbrole_insert ON "public"."DbRoles";
DROP TRIGGER tr_dbrole_delete ON "public"."DbRoles";
DROP TRIGGER tr_dbrolerelationships_insert ON "public"."DbRoleRelationships";
DROP TRIGGER tr_dbrolerelationships_delete ON "public"."DbRoleRelationships";
DROP TRIGGER tr_dbrolerelationships_update ON "public"."DbRoleRelationships";
SELECT create_reference_table('"workflow"."DbAssetInstanceNodeReferences"');
SELECT create_reference_table('"workflow"."DbAssetNodeReference"');
SELECT create_reference_table('"workflow"."DbEventServiceInstancesInfo"');
SELECT create_reference_table('"workflow"."DbProfileRoutingRules"');
SELECT create_reference_table('"workflow"."DbStageApproveResults"');
SELECT create_reference_table('"workflow"."DbWorkflowAccountEmailConfig"');
SELECT create_reference_table('"workflow"."DbWorkflowAddTriggerStepEmailUserGroups"');
SELECT create_reference_table('"workflow"."DbWorkflowAddTriggerStepEmailUsers"');
SELECT create_reference_table('"workflow"."DbWorkflowAssetInstances"');
SELECT create_reference_table('"workflow"."DbWorkflowAssets"');
SELECT create_reference_table('"workflow"."DbWorkflowAssetsStages"');
SELECT create_reference_table('"workflow"."DbWorkflowAssetsStagesInstances"');
SELECT create_reference_table('"workflow"."DbWorkflowESignatureStepInstanceTemplateDocuments"');
SELECT create_reference_table('"workflow"."DbWorkflowESignatureStepInstanceUserReferences"');
SELECT create_reference_table('"workflow"."DbWorkflowESignatureStepTemplateDocuments"');
SELECT create_reference_table('"workflow"."DbWorkflowESignatureStepUserReferences"');
SELECT create_reference_table('"workflow"."DbWorkflowInstanceHistoryRecordTypes"');
SELECT create_reference_table('"workflow"."DbWorkflowInstanceHistoryRecords"');
SELECT create_reference_table('"workflow"."DbWorkflowInstanceStates"');
SELECT create_reference_table('"workflow"."DbWorkflowInstances"');
SELECT create_reference_table('"workflow"."DbWorkflowJobsQueue"');
SELECT create_reference_table('"workflow"."DbWorkflowNotificationConfigurations"');
SELECT create_reference_table('"workflow"."DbWorkflowOwnerGroups"');
SELECT create_reference_table('"workflow"."DbWorkflowOwners"');
SELECT create_reference_table('"workflow"."DbWorkflowRequestFileExternalStepInstanceNewUserReferences"');
SELECT create_reference_table('"workflow"."DbWorkflowRequestFileExternalStepInstanceRecipientGroups"');
SELECT create_reference_table('"workflow"."DbWorkflowRequestFileExternalStepInstanceRecipients"');
SELECT create_reference_table('"workflow"."DbWorkflowRequestFileExternalStepNewUserReferences"');
SELECT create_reference_table('"workflow"."DbWorkflowRequestFileExternalStepRecipientGroups"');
SELECT create_reference_table('"workflow"."DbWorkflowRequestFileExternalStepRecipients"');
SELECT create_reference_table('"workflow"."DbWorkflowScheduleConfigurations"');
SELECT create_reference_table('"workflow"."DbWorkflowSendMessageInstanceRecipients"');
SELECT create_reference_table('"workflow"."DbWorkflowSendMessageRecipients"');
SELECT create_reference_table('"workflow"."DbWorkflowSetPermissionsStepUserGroups"');
SELECT create_reference_table('"workflow"."DbWorkflowSetPermissionsStepUsers"');
SELECT create_reference_table('"workflow"."DbWorkflowSetProfileInstanceItemPresetValues"');
SELECT create_reference_table('"workflow"."DbWorkflowSetProfileInstanceItems"');
SELECT create_reference_table('"workflow"."DbWorkflowSetProfileItemPresetValues"');
SELECT create_reference_table('"workflow"."DbWorkflowSetProfileItems"');
SELECT create_reference_table('"workflow"."DbWorkflowShareStepInstanceNewUserReferences"');
SELECT create_reference_table('"workflow"."DbWorkflowShareStepNewUserReferences"');
SELECT create_reference_table('"workflow"."DbWorkflowStageApproverGroups"');
SELECT create_reference_table('"workflow"."DbWorkflowStageApprovers"');
SELECT create_reference_table('"workflow"."DbWorkflowStageAssigneeGroups"');
SELECT create_reference_table('"workflow"."DbWorkflowStageAssignees"');
SELECT create_reference_table('"workflow"."DbWorkflowStageInstances"');
SELECT create_reference_table('"workflow"."DbWorkflowStages"');
SELECT create_reference_table('"workflow"."DbWorkflowStarterGroups"');
SELECT create_reference_table('"workflow"."DbWorkflowStarters"');
SELECT create_reference_table('"workflow"."DbWorkflowStepDocumentRequestContainers"');
SELECT create_reference_table('"workflow"."DbWorkflowStepGroupReferences"');
SELECT create_reference_table('"workflow"."DbWorkflowStepInstanceDocumentRequestContainers"');
SELECT create_reference_table('"workflow"."DbWorkflowStepInstanceEmailUserGroups"');
SELECT create_reference_table('"workflow"."DbWorkflowStepInstanceEmailUsers"');
SELECT create_reference_table('"workflow"."DbWorkflowStepInstanceGroupReferences"');
SELECT create_reference_table('"workflow"."DbWorkflowStepInstanceUserGroups"');
SELECT create_reference_table('"workflow"."DbWorkflowStepInstanceUserReferences"');
SELECT create_reference_table('"workflow"."DbWorkflowStepInstanceUsers"');
SELECT create_reference_table('"workflow"."DbWorkflowStepInstances"');
SELECT create_reference_table('"workflow"."DbWorkflowStepTypes"');
SELECT create_reference_table('"workflow"."DbWorkflowStepUserReferences"');
SELECT create_reference_table('"workflow"."DbWorkflowSteps"');
SELECT create_reference_table('"workflow"."DbWorkflowWatcherGroups"');
SELECT create_reference_table('"workflow"."DbWorkflowWatchers"');
SELECT create_reference_table('"workflow"."DbWorkflows"');
SELECT create_reference_table('"workflow"."DbWorkflowsAvailableStates"');
SELECT create_reference_table('"public"."DbBrandings"');
SELECT create_reference_table('"public"."DbClientApplications"');
SELECT create_reference_table('"public"."DbComponentStatus"');
SELECT create_reference_table('"public"."DbComponentStatusHistories"');
SELECT create_reference_table('"public"."DbEmailSettingToUsers"');
SELECT create_reference_table('"public"."DbEmailSettings"');
SELECT create_reference_table('"public"."DbEmailTemplateToPartner"');
SELECT create_reference_table('"public"."DbEmailTemplates"');
SELECT create_reference_table('"public"."DbInstanceSettings"');
SELECT create_reference_table('"public"."DbPartners"');
SELECT create_reference_table('"public"."DbPortfolioToNodes"');
SELECT create_reference_table('"public"."DbPortfolioToUsers"');
SELECT create_reference_table('"public"."DbPortfolios"');
SELECT create_reference_table('"public"."DbResetPasswordRequests"');
SELECT create_reference_table('"public"."DbRightSignatureUsers"');
SELECT create_reference_table('"public"."DbSearchCriteria"');
SELECT create_reference_table('"public"."DbUserApplicationsMfa"');
SELECT create_reference_table('"public"."DbUserExternalAuthentications"');
SELECT create_reference_table('"public"."DbUserPasswordHistories"');
SELECT create_reference_table('"public"."DbUserSearchToSearchCriteria"');
SELECT create_reference_table('"public"."DbUserSearches"');
SELECT create_reference_table('"public"."DbUserSettings"');
SELECT create_reference_table('"public"."DbUsers"');
SELECT create_reference_table('"public"."DbUserSessions"');
SELECT create_distributed_table('"public"."DbNodeClosures"', 'AccountID');
SELECT create_distributed_table('"public"."DbAccountFeatures"', 'AccountID');
SELECT create_distributed_table('"public"."DbSecurityPolicies"', 'AccountID');
SELECT create_distributed_table('"public"."DbAuditLogsToNodeDetails"', 'AccountID');
SELECT create_distributed_table('"public"."DbAuditLogsToNodes"', 'AccountID');
SELECT create_distributed_table('"public"."DbAuditLogsToRoleDetails"', 'AccountID');
SELECT create_distributed_table('"public"."DbDocumentRequestAttachments"', 'AccountID');
SELECT create_distributed_table('"public"."DbEmailQueue"', 'AccountID');
SELECT create_distributed_table('"public"."DbEmailSettingToAccounts"', 'AccountID');
SELECT create_distributed_table('"public"."DbFileQueue"', 'AccountID');
SELECT create_distributed_table('"public"."DbNodeAnnotations"', 'AccountID');
SELECT create_distributed_table('"public"."DbNodeToFileInfoes"', 'AccountID');
SELECT create_distributed_table('"public"."DbProfiles"', 'AccountID');
SELECT create_distributed_table('"public"."DbPresetValues"', 'AccountID');
SELECT create_distributed_table('"public"."DbProfileItems"', 'AccountID');
SELECT create_distributed_table('"public"."DbProfileToProfileItems"', 'AccountID');
SELECT create_distributed_table('"public"."DbRetentionChangeReason"', 'AccountID');
SELECT create_distributed_table('"public"."DbSamlResponses"', 'AccountID');
SELECT create_distributed_table('"public"."DbSfLinks"', 'AccountID');
SELECT create_distributed_table('"public"."DbTriggerToNode"', 'AccountID');
SELECT create_distributed_table('"public"."DbAccountSettings"', 'AccountID');
SELECT create_distributed_table('"public"."DbProfileValueNodes"', 'AccountID');
SELECT create_distributed_table('"public"."DbAccessLinks"', 'AccountID');
SELECT create_distributed_table('"public"."DbDocumentRequests"', 'AccountID');
SELECT create_distributed_table('"public"."DbEmailImportMappings"', 'AccountID');
SELECT create_distributed_table('"public"."DbNodes"', 'AccountID');
SELECT create_distributed_table('"public"."DbAuditLogs"', 'AccountID');
SELECT create_distributed_table('"public"."DbAuditLogsToRoles"', 'AccountID');
SELECT create_distributed_table('"public"."DbDocumentRequestRoles"', 'AccountID');
SELECT create_distributed_table('"public"."DbESignatureTransactions"', 'AccountID');
SELECT create_distributed_table('"public"."DbNodeShares"', 'AccountID');
SELECT create_distributed_table('"public"."DbNotifications"', 'AccountID');
SELECT create_distributed_table('"public"."DbProfileValueRoles"', 'AccountID');
SELECT create_distributed_table('"public"."DbRoleToAccountFeatures"', 'AccountID');
SELECT create_distributed_table('"public"."DbSamlConfigurations"', 'AccountID');
SELECT create_distributed_table('"public"."DbTriggerToRoles"', 'AccountID');
SELECT create_distributed_table('"public"."DbUserRolePreferences"', 'AccountID');
SELECT create_distributed_table('"public"."DbUserImageStamps"', 'AccountID');
SELECT create_distributed_table('"public"."DbTemplateNodeLinks"', 'AccountID');
SELECT create_distributed_table('"public"."DbFileInfoes"', 'AccountID');
SELECT create_distributed_table('"public"."DbRoles"', 'AccountID');
SELECT create_distributed_table('"public"."DbSystemPermissions"', 'AccountID');
SELECT create_distributed_table('"public"."DbTriggers"', 'AccountID');
SELECT create_distributed_table('"public"."DbEmailContent"', 'AccountID');
SELECT create_distributed_table('"public"."DbEventTriggers"', 'AccountID');
SELECT create_distributed_table('"public"."DbWorkflowStageInstanceToNotifications"', 'AccountID');
SELECT create_distributed_table('"public"."DbRoleClosures"', 'AccountID');
SELECT create_distributed_table('"public"."DbRoleRelationships"', 'AccountID');
SELECT create_distributed_table('"public"."DbTimeTriggers"', 'AccountID');
SELECT create_distributed_table('"public"."DbTriggerInfoNodes"', 'AccountID');
SELECT create_distributed_table('"public"."DbTriggerToWorkflow"', 'AccountID');
SELECT create_distributed_table('"public"."DbEmailQueueAttachmentNodes"', 'AccountID');
SELECT create_distributed_table('"public"."DbTemplateNodeChangeLogs"', 'AccountID');
SELECT create_distributed_table('"public"."DbTriggerToSearchCriteria"', 'AccountID');
SELECT create_distributed_table('"public"."DbFormFillDefinitions"', 'AccountID');
SELECT create_distributed_table('"public"."DbAccessLinksToDocumentRequests"', 'AccountID');
SELECT create_distributed_table('"public"."DbAccessLinksToNodeAndTriggers"', 'AccountID');
SELECT create_distributed_table('"public"."DbESignatureSigners"', 'AccountID');
SELECT create_distributed_table('"public"."DbESignatureNodeAssociations"', 'AccountID');
SELECT create_distributed_table('"public"."DbFormFillPendings"', 'AccountID');
SELECT create_distributed_table('"public"."DbFormFillToProfileItems"', 'AccountID');
SELECT create_distributed_table('"public"."DbNodeComments"', 'AccountID');
SELECT create_distributed_table('"public"."DbSecurityPolicyIpAddresses"', 'AccountID');
SELECT create_distributed_table('"public"."DbSecurityPolicyLoginTimes"', 'AccountID');
SELECT create_distributed_table('"public"."DbTriggerToApiCallouts"', 'AccountID');
SELECT create_distributed_table('"public"."DbWatermarkTriggerInfo"', 'AccountID');
SELECT create_distributed_table('"public"."DbDocumentRequestContainerNodes"', 'AccountID');
SELECT create_distributed_table('"public"."DbDocumentRequestContainers"', 'AccountID');
SELECT create_distributed_table('"public"."DbLegacyNodeMappings"', 'AccountID');
SELECT create_distributed_table('"public"."DbDocumentRequestToNotifications"', 'AccountID');
SELECT create_distributed_table('"public"."DbSfMappings"', 'AccountID');
SELECT create_distributed_table('"public"."DbPermissions"', 'AccountID');
SELECT create_distributed_table('"public"."DbRightSignatureDocuments"', 'AccountID');
SELECT create_distributed_table('"public"."DbUserSessionToDbRoles"', 'AccountID');
SELECT create_distributed_table('"public"."DbEmailRecipients"', 'AccountID');
SELECT create_distributed_table('"DbAccounts"', 'Id');
alter table public."DbAccessLinks" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbAccountFeatures" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbAccountSettings" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbAccountSettings" add constraint "FK_DbEmailSettings" FOREIGN KEY ("EmailSettingID") REFERENCES "DbEmailSettings"("Id");
alter table public."DbAccounts" add constraint "FK_BrandingID" FOREIGN KEY ("BrandingID") REFERENCES "DbBrandings"("Id");
alter table public."DbAuditLogs" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbAuditLogsToNodeDetails" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbAuditLogsToNodes" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbAuditLogsToRoleDetails" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbAuditLogsToRoles" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbDocumentRequests" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbESignatureTransactions" add constraint "FK_DbAccount" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbEmailImportMappings" add constraint "FK_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbEmailImportMappings" add constraint "FK_EmailSettingID" FOREIGN KEY ("EmailSettingID") REFERENCES "DbEmailSettings"("Id");
alter table public."DbEmailQueue" add constraint fk_accounts FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbEmailQueue" add constraint fk_emailsettings FOREIGN KEY ("EmailSettingID") REFERENCES "DbEmailSettings"("Id");
alter table public."DbEmailSettingToAccounts" add constraint fk_account FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbEmailSettingToAccounts" add constraint fk_emailsetting FOREIGN KEY ("EmailSettingsID") REFERENCES "DbEmailSettings"("Id");
alter table public."DbEmailSettingToUsers" add constraint fk_emailsetting FOREIGN KEY ("EmailSettingsID") REFERENCES "DbEmailSettings"("Id");
alter table public."DbEmailTemplateToPartner" add constraint "FK_DbEmailTemplate" FOREIGN KEY ("EmailTemplateID") REFERENCES "DbEmailTemplates"("Id");
alter table public."DbFileInfoes" add constraint "FK_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbFileQueue" add constraint "FK_Account" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbNodeAnnotations" add constraint fk_account FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbNodeClosures" add constraint "fk_accountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbAccessLinksToDocumentRequests" add constraint "FK_public.DbAccessLinksToDocumentRequests_public.DbAccessLinks_" FOREIGN KEY ("AccessLinkID", "AccountID") REFERENCES "DbAccessLinks"("Id", "AccountID");
alter table public."DbAccessLinksToNodeAndTriggers" add constraint "FK_public.DbAccessLinksToNodeAndTriggers_public.DbAccessLinks_A" FOREIGN KEY ("AccessLinkID", "AccountID") REFERENCES "DbAccessLinks"("Id", "AccountID");
alter table public."DbAccessLinks" add constraint "FK_public.DbAccessLinks_public.DbRoles_RoleID_AccountID" FOREIGN KEY ("RoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbAccessLinksToDocumentRequests" add constraint "FK_public.DbAccessLinksToDocumentRequests_public.DbDocumentRequ" FOREIGN KEY ("DocumentRequestID", "AccountID") REFERENCES "DbDocumentRequests"("Id", "AccountID") ON DELETE CASCADE;
alter table public."DbAccountSettings" add constraint "FK_public.DbAccountSettings_public.DbSecurityPolicies_DefaultGu" FOREIGN KEY ("DefaultGuestSecurityPolicyID", "AccountID") REFERENCES "DbSecurityPolicies"("Id", "AccountID");
alter table public."DbAccountSettings" add constraint "FK_public.DbAccountSettings_public.DbSecurityPolicies_DefaultUs" FOREIGN KEY ("DefaultUserSecurityPolicyID", "AccountID") REFERENCES "DbSecurityPolicies"("Id", "AccountID");
alter table public."DbEmailImportMappings" add constraint "FK_public.DbEmailImportMappings_public.DbNodes_NodeID_AccountID" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbAccessLinksToNodeAndTriggers" add constraint "FK_public.DbAccessLinksToNodeAndTriggers_public.DbNodes_NodeID_" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbAuditLogsToNodes" add constraint "FK_public.DbAuditLogsToNodes_public.DbNodes_NodeID_AccountID" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbNodeShares" add constraint fk_account FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbNodeToFileInfoes" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbNodes" add constraint fk_account FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbNotifications" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbPartners" add constraint "FK_BrandingID" FOREIGN KEY ("BrandingID") REFERENCES "DbBrandings"("Id");
alter table public."DbPermissions" add constraint fk_account FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbPortfolioToNodes" add constraint "FK_DbPortfolios" FOREIGN KEY ("PortfolioID") REFERENCES "DbPortfolios"("Id");
alter table public."DbPortfolioToUsers" add constraint "FK_DbPortfolios" FOREIGN KEY ("PortfolioID") REFERENCES "DbPortfolios"("Id");
alter table public."DbPresetValues" add constraint "FK_Account" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbProfileItems" add constraint fk_account FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbProfiles" add constraint fk_account FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbRetentionChangeReason" add constraint "FK_DbAccount" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbRoles" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbSamlConfigurations" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbSamlResponses" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbSearchCriteria" add constraint "fk_parentUserSearchCriteria" FOREIGN KEY ("ParentUserSearchCriteriaId") REFERENCES "DbSearchCriteria"("Id");
alter table public."DbSecurityPolicies" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbSfLinks" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbSfMappings" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbTriggerToSearchCriteria" add constraint "FK_DbSearchCriteria" FOREIGN KEY ("SearchCriteriaID") REFERENCES "DbSearchCriteria"("Id");
alter table public."DbUserImageStamps" add constraint "FK_DbAccounts" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbUserSearchToSearchCriteria" add constraint "FK_DbSearchCriteria" FOREIGN KEY ("SearchCriteriaId") REFERENCES "DbSearchCriteria"("Id");
alter table public."DbUserSearchToSearchCriteria" add constraint "FK_DbUserSearches" FOREIGN KEY ("UserSearchId") REFERENCES "DbUserSearches"("Id");
alter table public."DbUserSettings" add constraint "FK_DbEmailSettings" FOREIGN KEY ("EmailSettingID") REFERENCES "DbEmailSettings"("Id");
alter table public."DbUserSettings" add constraint "FK_DbPortfolios" FOREIGN KEY ("DefaultPortfolioID") REFERENCES "DbPortfolios"("Id");
alter table public."DbUsers" add constraint "FK_DbUserSettings" FOREIGN KEY ("UserSettingsID") REFERENCES "DbUserSettings"("Id");
alter table workflow."DbWorkflowInstanceHistoryRecords" add constraint "FK_DbWorkflowInstanceHistoryRecordTypes_RecordTypeID" FOREIGN KEY ("RecordTypeID") REFERENCES workflow."DbWorkflowInstanceHistoryRecordTypes"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_DbWorkflowStepTypes_TypeID" FOREIGN KEY ("TypeID") REFERENCES workflow."DbWorkflowStepTypes"("Id");
alter table public."DbDocumentRequestContainers" add constraint "DbFileRequestContainers_check" CHECK ("Rename" = false OR "Rename" = true AND "IsMultiple" = false);
alter table public."DbDocumentRequests" add constraint "DbFileRequests_check" CHECK ("IsTemplate" = true OR "IsTemplate" = false AND "DestinationNodeID" IS NOT NULL);
alter table public."DbTimeTriggers" add constraint "check_timeTrigger_preActionNotificationTimeSpanInDays" CHECK ("PreActionNotificationTimeSpanInDays" <= 365);
alter table public."DbTimeTriggers" add constraint "check_timeTrigger_timeSpanInSeconds" CHECK ("TimeSpanInSeconds"::numeric <= '220898664000'::numeric);
alter table public."DbComponentStatusHistories" add constraint "FK_public.DbComponentStatusHistories_public.DbComponentStatus_C" FOREIGN KEY ("ComponentStatusId") REFERENCES "DbComponentStatus"("Id") ON DELETE CASCADE;
alter table public."DbDocumentRequestAttachments" add constraint "FK_public.DbDocumentRequestAttachments_public.DbNodes_Attachmen" FOREIGN KEY ("AttachmentNodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbDocumentRequestContainerNodes" add constraint "FK_public.DbDocumentRequestContainerNodes_public.DbNodes_NodeID" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbDocumentRequests" add constraint "FK_public.DbDocumentRequests_public.DbNodes_DestinationNodeID_A" FOREIGN KEY ("DestinationNodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbEmailQueueAttachmentNodes" add constraint "FK_public.DbEmailQueueAttachmentNodes_public.DbNodes_NodeID_Acc" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbESignatureNodeAssociations" add constraint "FK_public.DbESignatureNodeAssociations_public.DbNodes_OriginalN" FOREIGN KEY ("OriginalNodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbESignatureNodeAssociations" add constraint "FK_public.DbESignatureNodeAssociations_public.DbNodes_SignedNod" FOREIGN KEY ("SignedNodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbESignatureTransactions" add constraint "FK_public.DbESignatureTransactions_public.DbNodes_AuditTrailNod" FOREIGN KEY ("AuditTrailNodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbESignatureTransactions" add constraint "FK_public.DbESignatureTransactions_public.DbNodes_AuditTrailPar" FOREIGN KEY ("AuditTrailParentNodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbESignatureTransactions" add constraint "FK_public.DbESignatureTransactions_public.DbNodes_SignedDocumen" FOREIGN KEY ("SignedDocumentParentNodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbNodes" add constraint "FK_public.DbNodes_public.DbFileInfoes_FileInfoID_AccountID" FOREIGN KEY ("FileInfoID", "AccountID") REFERENCES "DbFileInfoes"("Id", "AccountID");
alter table public."DbFileQueue" add constraint "FK_public.DbFileQueue_public.DbNodes_NodeID_AccountID" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbLegacyNodeMappings" add constraint "FK_public.DbLegacyNodeMappings_public.DbNodes_NodeId_AccountID" FOREIGN KEY ("NodeId", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbNodes" add constraint "FK_public.DbNodes_public.DbNodes_ParentID_AccountID" FOREIGN KEY ("ParentID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbNodeAnnotations" add constraint "FK_public.DbNodeAnnotations_public.DbNodes_NodeID_AccountID" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbNodeClosures" add constraint "FK_public.DbNodeClosures_public.DbNodes_ChildID_AccountID" FOREIGN KEY ("ChildID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbRoleRelationships" add constraint "Parent_Is_Group" CHECK ("func_RoleIsGroup"("ParentRoleID") = true);
alter table public."DbAccessLinks" add constraint "FK_public.DbAccessLinks_public.DbUsers_CreatedByUserID" FOREIGN KEY ("CreatedByUserID") REFERENCES "DbUsers"("Id");
alter table public."DbAuditLogs" add constraint "FK_public.DbAuditLogs_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id");
alter table public."DbAuditLogs" add constraint "FK_public.DbAuditLogs_public.DbUsers_GeneratedByUserID" FOREIGN KEY ("GeneratedByUserID") REFERENCES "DbUsers"("Id");
alter table public."DbDocumentRequests" add constraint "FK_public.DbDocumentRequests_public.DbUsers_CreatedByUserID" FOREIGN KEY ("CreatedByUserID") REFERENCES "DbUsers"("Id");
alter table public."DbEmailImportMappings" add constraint "FK_public.DbEmailImportMappings_public.DbUsers_CreatedByUserID" FOREIGN KEY ("CreatedByUserID") REFERENCES "DbUsers"("Id");
alter table public."DbESignatureTransactions" add constraint "FK_public.DbESignatureTransactions_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id");
alter table public."DbFileInfoes" add constraint "FK_public.DbFileInfoes_public.DbUsers_CreatedByUserID" FOREIGN KEY ("CreatedByUserID") REFERENCES "DbUsers"("Id");
alter table public."DbNodeComments" add constraint "FK_public.DbNodeComments_public.DbUsers_LastModifiedByUserID" FOREIGN KEY ("LastModifiedByUserID") REFERENCES "DbUsers"("Id");
alter table public."DbNodeComments" add constraint "FK_public.DbNodeComments_public.DbUsers_CreatedByUserID" FOREIGN KEY ("CreatedByUserID") REFERENCES "DbUsers"("Id");
alter table public."DbNodes" add constraint "FK_public.DbNodes_public.DbUsers_CreatedByUserID" FOREIGN KEY ("CreatedByUserID") REFERENCES "DbUsers"("Id");
alter table public."DbPortfolios" add constraint "FK_public.DbPortfolios_public.DbUsers_OwnerUserID" FOREIGN KEY ("OwnerUserID") REFERENCES "DbUsers"("Id");
alter table public."DbPortfolioToNodes" add constraint "FK_public.DbPortfolioToNodes_public.DbUsers_AddedByUserID" FOREIGN KEY ("AddedByUserID") REFERENCES "DbUsers"("Id");
alter table public."DbPortfolioToUsers" add constraint "FK_public.DbPortfolioToUsers_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id");
alter table public."DbResetPasswordRequests" add constraint "FK_public.DbResetPasswordRequests_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id");
alter table public."DbRightSignatureUsers" add constraint "FK_public.DbRightSignatureUsers_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id");
alter table public."DbRoles" add constraint "FK_public.DbRoles_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id");
alter table public."DbSamlConfigurations" add constraint "FK_public.DbSamlConfigurations_public.DbUsers_CreatedByUserID" FOREIGN KEY ("CreatedByUserID") REFERENCES "DbUsers"("Id");
alter table public."DbTriggers" add constraint "FK_public.DbTriggers_public.DbUsers_CreatedByUserID" FOREIGN KEY ("CreatedByUserID") REFERENCES "DbUsers"("Id");
alter table public."DbUserApplicationsMfa" add constraint "FK_public.DbUserApplicationsMfa_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id");
alter table public."DbUserExternalAuthentications" add constraint "FK_public.DbUserExternalAuthentications_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id");
alter table public."DbUserImageStamps" add constraint "FK_public.DbUserImageStamps_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id");
alter table public."DbUserPasswordHistories" add constraint "FK_public.DbUserPasswordHistories_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id");
alter table public."DbUserSearches" add constraint "FK_public.DbUserSearches_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id");
alter table public."DbUserSessions" add constraint "FK_public.DbUserSessions_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id");
alter table public."DbUserSessions" add constraint "FK_public.DbUserSessions_public.DbUsers_GeneratedByUserID" FOREIGN KEY ("GeneratedByUserID") REFERENCES "DbUsers"("Id");
alter table public."DbEmailSettingToUsers" add constraint "FK_public.DbEmailSettingToUsers_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id") ON DELETE CASCADE;
alter table public."DbRightSignatureDocuments" add constraint "FK_public.DbRightSignatureDocuments_public.DbRightSignatureUser" FOREIGN KEY ("SenderUserID") REFERENCES "DbRightSignatureUsers"("UserID");
alter table public."DbFormFillPendings" add constraint "FK_public.DbFormFillPendings_public.DbUsers_UserID" FOREIGN KEY ("UserID") REFERENCES "DbUsers"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowSteps_Db" FOREIGN KEY ("DbWorkflowStepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowInstances" add constraint "FK_workflow.DbWorkflowInstances_workflow.DbWorkflowInstanceStat" FOREIGN KEY ("StateID") REFERENCES workflow."DbWorkflowInstanceStates"("Id");
alter table workflow."DbStageApproveResults" add constraint "FK_workflow.DbStageApproveResults_workflow.DbWorkflowStageInsta" FOREIGN KEY ("StageInstanceID") REFERENCES workflow."DbWorkflowStageInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI1" FOREIGN KEY ("requestFileExternal_AttachmentAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI2" FOREIGN KEY ("addTrigger_DestinationAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI3" FOREIGN KEY ("addTrigger_TargetAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI4" FOREIGN KEY ("applyTemplate_TargetPathAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI5" FOREIGN KEY ("comment_TargetAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI6" FOREIGN KEY ("copy_DestinationAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI7" FOREIGN KEY ("copy_ResultAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI8" FOREIGN KEY ("copy_SourceAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAssetI9" FOREIGN KEY ("createLocation_ResultAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset10" FOREIGN KEY ("createLocation_SourceAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset11" FOREIGN KEY ("delete_TargetAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset12" FOREIGN KEY ("esignature_AuditTrailAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset14" FOREIGN KEY ("esignature_AuditTrailDestinationAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset15" FOREIGN KEY ("esignature_SignedResultAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset16" FOREIGN KEY ("esignature_SignedResultDestinationAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowESignatureStepInstanceUserReferences" add constraint "FK_workflow.DbWorkflowESignatureStepInstanceUserReferences_wor1" FOREIGN KEY ("AssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset17" FOREIGN KEY ("esignature_SourceAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowESignatureStepInstanceTemplateDocuments" add constraint "FK_workflow.DbWorkflowESignatureStepInstanceTemplateDocuments_1" FOREIGN KEY ("SourceAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset18" FOREIGN KEY ("move_DestinationAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset19" FOREIGN KEY ("move_SourceAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset20" FOREIGN KEY ("rename_TargetAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset21" FOREIGN KEY ("sendMessage_AttachmentAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset22" FOREIGN KEY ("setPermissions_SourceAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset23" FOREIGN KEY ("setProfile_TargetAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset24" FOREIGN KEY ("setRetention_DestinationAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset25" FOREIGN KEY ("setRetention_TargetAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset26" FOREIGN KEY ("share_SourceAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset27" FOREIGN KEY ("upload_ResultAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset28" FOREIGN KEY ("upload_SourceAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowAsset29" FOREIGN KEY ("requestFileExternal_DestinationAssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstanceDocumentRequestContainers" add constraint "FK_workflow.DbWorkflowStepInstanceDocumentRequestContainers_wo1" FOREIGN KEY ("AssetInstanceID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbAssetInstanceNodeReferences" add constraint "FK_workflow.DbAssetInstanceNodeReferences_workflow.DbWorkflowAs" FOREIGN KEY ("AssetInstanceID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowAssetsStagesInstances" add constraint "FK_workflow.DbWorkflowAssetsStagesInstances_workflow.DbWorkflo1" FOREIGN KEY ("AssetID") REFERENCES workflow."DbWorkflowAssetInstances"("Id");
alter table workflow."DbWorkflowStepInstanceEmailUserGroups" add constraint "FK_workflow.DbWorkflowStepInstanceEmailUserGroups_workflow.DbWo" FOREIGN KEY ("WorkflowAddTriggerStepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowStepInstanceEmailUsers" add constraint "FK_workflow.DbWorkflowStepInstanceEmailUsers_workflow.DbWorkflo" FOREIGN KEY ("WorkflowAddTriggerStepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowESignatureStepInstanceUserReferences" add constraint "FK_workflow.DbWorkflowESignatureStepInstanceUserReferences_wor2" FOREIGN KEY ("StepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowESignatureStepInstanceTemplateDocuments" add constraint "FK_workflow.DbWorkflowESignatureStepInstanceTemplateDocuments_2" FOREIGN KEY ("StepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowSendMessageInstanceRecipients" add constraint "FK_workflow.DbWorkflowSendMessageInstanceRecipients_workflow.Db" FOREIGN KEY ("StepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowStepInstanceUserGroups" add constraint "FK_workflow.DbWorkflowStepInstanceUserGroups_workflow.DbWorkflo" FOREIGN KEY ("WorkflowSetPermissionsStepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowStepInstanceUsers" add constraint "FK_workflow.DbWorkflowStepInstanceUsers_workflow.DbWorkflowStep" FOREIGN KEY ("WorkflowSetPermissionsStepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowSetProfileInstanceItems" add constraint "FK_workflow.DbWorkflowSetProfileInstanceItems_workflow.DbWorkfl" FOREIGN KEY ("StepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowShareStepInstanceNewUserReferences" add constraint "FK_workflow.DbWorkflowShareStepInstanceNewUserReferences_workfl" FOREIGN KEY ("StepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowStepInstanceGroupReferences" add constraint "FK_workflow.DbWorkflowStepInstanceGroupReferences_workflow.DbWo" FOREIGN KEY ("StepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowStepInstanceUserReferences" add constraint "FK_workflow.DbWorkflowStepInstanceUserReferences_workflow.DbWor" FOREIGN KEY ("StepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowInstanceHistoryRecords" add constraint "FK_workflow.DbWorkflowInstanceHistoryRecords_workflow.DbWorkfl1" FOREIGN KEY ("StepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowStepInstanceDocumentRequestContainers" add constraint "FK_workflow.DbWorkflowStepInstanceDocumentRequestContainers_wo2" FOREIGN KEY ("StepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowRequestFileExternalStepInstanceRecipientGroups" add constraint "FK_workflow.DbWorkflowRequestFileExternalStepInstanceRecipientG" FOREIGN KEY ("WorkflowStepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowRequestFileExternalStepInstanceNewUserReferences" add constraint "FK_workflow.DbWorkflowRequestFileExternalStepInstanceNewUserRef" FOREIGN KEY ("StepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowRequestFileExternalStepInstanceRecipients" add constraint "FK_workflow.DbWorkflowRequestFileExternalStepInstanceRecipients" FOREIGN KEY ("WorkflowStepInstanceID") REFERENCES workflow."DbWorkflowStepInstances"("Id");
alter table workflow."DbWorkflowStepDocumentRequestContainers" add constraint "FK_workflow.DbWorkflowStepDocumentRequestContainers_workflow.D1" FOREIGN KEY ("StepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowRequestFileExternalStepRecipientGroups" add constraint "FK_workflow.DbWorkflowRequestFileExternalStepRecipientGroups_wo" FOREIGN KEY ("WorkflowStepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowRequestFileExternalStepNewUserReferences" add constraint "FK_workflow.DbWorkflowRequestFileExternalStepNewUserReferences_" FOREIGN KEY ("StepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowRequestFileExternalStepRecipients" add constraint "FK_workflow.DbWorkflowRequestFileExternalStepRecipients_workflo" FOREIGN KEY ("WorkflowStepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowAddTriggerStepEmailUserGroups" add constraint "FK_workflow.DbWorkflowAddTriggerStepEmailUserGroups_workflow.Db" FOREIGN KEY ("WorkflowStepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowAddTriggerStepEmailUsers" add constraint "FK_workflow.DbWorkflowAddTriggerStepEmailUsers_workflow.DbWorkf" FOREIGN KEY ("WorkflowStepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowESignatureStepUserReferences" add constraint "FK_workflow.DbWorkflowESignatureStepUserReferences_workflow.DbW" FOREIGN KEY ("StepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowESignatureStepTemplateDocuments" add constraint "FK_workflow.DbWorkflowESignatureStepTemplateDocuments_workflow1" FOREIGN KEY ("StepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowSendMessageRecipients" add constraint "FK_workflow.DbWorkflowSendMessageRecipients_workflow.DbWorkflow" FOREIGN KEY ("StepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowSetPermissionsStepUserGroups" add constraint "FK_workflow.DbWorkflowSetPermissionsStepUserGroups_workflow.DbW" FOREIGN KEY ("WorkflowStepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowSetPermissionsStepUsers" add constraint "FK_workflow.DbWorkflowSetPermissionsStepUsers_workflow.DbWorkfl" FOREIGN KEY ("WorkflowStepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table public."DbNodeClosures" add constraint "FK_public.DbNodeClosures_public.DbNodes_ParentID_AccountID" FOREIGN KEY ("ParentID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbTriggers" add constraint "FK_public.DbTriggers_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbEmailContent" add constraint "FK_public.DbEmailContent_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbEventTriggers" add constraint "FK_public.DbEventTriggers_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbTimeTriggers" add constraint "FK_public.DbTimeTriggers_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbTriggerInfoNodes" add constraint "FK_public.DbTriggerInfoNodes_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbTriggerToNode" add constraint "FK_public.DbTriggerToNode_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbTriggerToWorkflow" add constraint "FK_public.DbTriggerToWorkflow_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbTriggerToRoles" add constraint "FK_public.DbTriggerToRoles_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbTriggerToSearchCriteria" add constraint "FK_public.DbTriggerToSearchCriteria_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbProfileValueNodes" add constraint "FK_public.DbProfileValueNodes_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbProfileToProfileItems" add constraint "FK_public.DbProfileToProfileItems_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbProfileValueRoles" add constraint "FK_public.DbProfileValueRoles_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbRoleRelationships" add constraint "FK_public.DbRoleRelationships_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbRoleToAccountFeatures" add constraint "FK_public.DbRoleToAccountFeatures_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbSystemPermissions" add constraint "FK_public.DbSystemPermissions_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbEmailQueueAttachmentNodes" add constraint "FK_public.DbEmailQueueAttachmentNodes_public.DbAccounts_Account" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbTemplateNodeChangeLogs" add constraint "FK_public.DbTemplateNodeChangeLogs_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbTemplateNodeLinks" add constraint "FK_public.DbTemplateNodeLinks_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbWorkflowStageInstanceToNotifications" add constraint "FK_public.DbWorkflowStageInstanceToNotifications_public.DbAccou" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbRoleClosures" add constraint "FK_public.DbRoleClosures_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbAccessLinksToNodeAndTriggers" add constraint "FK_public.DbAccessLinksToNodeAndTriggers_public.DbAccounts_Acco" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbDocumentRequestRoles" add constraint "FK_public.DbDocumentRequestRoles_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbNodeComments" add constraint "FK_public.DbNodeComments_public.DbNodes_NodeID_AccountID" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbNodeShares" add constraint "FK_public.DbNodeShares_public.DbNodes_AccountWorkspaceNodeID_Ac" FOREIGN KEY ("AccountWorkspaceNodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbNodeShares" add constraint "FK_public.DbNodeShares_public.DbNodes_SharedWorkspaceNodeID_Acc" FOREIGN KEY ("SharedWorkspaceNodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbNodeToFileInfoes" add constraint "FK_public.DbNodeToFileInfoes_public.DbNodes_NodeID_AccountID" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbPermissions" add constraint "FK_public.DbPermissions_public.DbNodes_NodeID_AccountID" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbNodes" add constraint "FK_public.DbNodes_public.DbProfiles_ProfileID_AccountID" FOREIGN KEY ("ProfileID", "AccountID") REFERENCES "DbProfiles"("Id", "AccountID");
alter table public."DbProfileValueNodes" add constraint "FK_public.DbProfileValueNodes_public.DbNodes_NodeID_AccountID" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbRightSignatureDocuments" add constraint "FK_public.DbRightSignatureDocuments_public.DbNodes_NodeID_Accou" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbSfLinks" add constraint "FK_public.DbSfLinks_public.DbNodes_NodeID_AccountID" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbSfMappings" add constraint "FK_public.DbSfMappings_public.DbNodes_ParentNodeID_AccountID" FOREIGN KEY ("ParentNodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbTemplateNodeChangeLogs" add constraint "FK_public.DbTemplateNodeChangeLogs_public.DbNodes_TemplateNodeI" FOREIGN KEY ("TemplateNodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbTemplateNodeLinks" add constraint "FK_public.DbTemplateNodeLinks_public.DbNodes_AppliedNodeID_Acco" FOREIGN KEY ("AppliedNodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbTemplateNodeLinks" add constraint "FK_public.DbTemplateNodeLinks_public.DbNodes_TemplateNodeID_Acc" FOREIGN KEY ("TemplateNodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbTriggerInfoNodes" add constraint "FK_public.DbTriggerInfoNodes_public.DbNodes_NodeID_AccountID" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbTriggerToNode" add constraint "FK_public.DbTriggerToNode_public.DbNodes_NodeID_AccountID" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbUserImageStamps" add constraint "FK_public.DbUserImageStamps_public.DbNodes_NodeID_AccountID" FOREIGN KEY ("NodeID", "AccountID") REFERENCES "DbNodes"("Id", "AccountID");
alter table public."DbAccessLinksToNodeAndTriggers" add constraint "FK_public.DbAccessLinksToNodeAndTriggers_public.DbTriggers_Trig" FOREIGN KEY ("TriggerID", "AccountID") REFERENCES "DbTriggers"("Id", "AccountID");
alter table public."DbTriggers" add constraint "FK_public.DbTriggers_public.DbEmailContent_EmailContentID_Accou" FOREIGN KEY ("EmailContentID", "AccountID") REFERENCES "DbEmailContent"("Id", "AccountID");
alter table public."DbEventTriggers" add constraint "FK_public.DbEventTriggers_public.DbTriggers_TriggerID_AccountID" FOREIGN KEY ("TriggerID", "AccountID") REFERENCES "DbTriggers"("Id", "AccountID");
alter table public."DbTimeTriggers" add constraint "FK_public.DbTimeTriggers_public.DbTriggers_TriggerID_AccountID" FOREIGN KEY ("TriggerID", "AccountID") REFERENCES "DbTriggers"("Id", "AccountID");
alter table public."DbTriggerInfoNodes" add constraint "FK_public.DbTriggerInfoNodes_public.DbTriggers_TriggerID_Accoun" FOREIGN KEY ("TriggerID", "AccountID") REFERENCES "DbTriggers"("Id", "AccountID");
alter table public."DbTriggerToApiCallouts" add constraint "FK_public.DbTriggerToApiCallouts_public.DbTriggers_TriggerID_Ac" FOREIGN KEY ("TriggerID", "AccountID") REFERENCES "DbTriggers"("Id", "AccountID");
alter table public."DbTriggerToNode" add constraint "FK_public.DbTriggerToNode_public.DbTriggers_TriggerID_AccountID" FOREIGN KEY ("TriggerID", "AccountID") REFERENCES "DbTriggers"("Id", "AccountID");
alter table public."DbTriggerToRoles" add constraint "FK_public.DbTriggerToRoles_public.DbTriggers_TriggerID_AccountI" FOREIGN KEY ("TriggerID", "AccountID") REFERENCES "DbTriggers"("Id", "AccountID");
alter table public."DbTriggerToSearchCriteria" add constraint "FK_public.DbTriggerToSearchCriteria_public.DbTriggers_TriggerID" FOREIGN KEY ("TriggerID", "AccountID") REFERENCES "DbTriggers"("Id", "AccountID") ON DELETE CASCADE;
alter table public."DbTriggerToWorkflow" add constraint "FK_public.DbTriggerToWorkflow_public.DbTriggers_TriggerID_Accou" FOREIGN KEY ("TriggerID", "AccountID") REFERENCES "DbTriggers"("Id", "AccountID");
alter table public."DbWatermarkTriggerInfo" add constraint "FK_public.DbWatermarkTriggerInfo_public.DbTriggers_TriggerID_Ac" FOREIGN KEY ("TriggerID", "AccountID") REFERENCES "DbTriggers"("Id", "AccountID");
alter table public."DbTriggerToRoles" add constraint "FK_public.DbTriggerToRoles_public.DbRoles_RoleID_AccountID" FOREIGN KEY ("RoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbAuditLogsToRoles" add constraint "FK_public.DbAuditLogsToRoles_public.DbRoles_RoleID_AccountID" FOREIGN KEY ("RoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbDocumentRequestRoles" add constraint "FK_public.DbDocumentRequestRoles_public.DbRoles_RecipientRoleID" FOREIGN KEY ("RecipientRoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbESignatureSigners" add constraint "FK_public.DbESignatureSigners_public.DbRoles_RoleID_AccountID" FOREIGN KEY ("RoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbFileInfoes" add constraint "FK_public.DbFileInfoes_public.DbRoles_CheckedOutByRoleID_Accoun" FOREIGN KEY ("CheckedOutByRoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbNodeShares" add constraint "FK_public.DbNodeShares_public.DbRoles_RoleID_AccountID" FOREIGN KEY ("RoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbNotifications" add constraint "FK_public.DbNotifications_public.DbRoles_RecipientRoleID_Accoun" FOREIGN KEY ("RecipientRoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbPermissions" add constraint "FK_public.DbPermissions_public.DbRoles_RoleID_AccountID" FOREIGN KEY ("RoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbRoles" add constraint "FK_public.DbRoles_public.DbProfiles_ProfileID_AccountID" FOREIGN KEY ("ProfileID", "AccountID") REFERENCES "DbProfiles"("Id", "AccountID");
alter table public."DbProfileValueRoles" add constraint "FK_public.DbProfileValueRoles_public.DbRoles_RoleID_AccountID" FOREIGN KEY ("RoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbRoleClosures" add constraint "FK_public.DbRoleClosures_public.DbRoles_ChildID_AccountID" FOREIGN KEY ("ChildID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbRoleClosures" add constraint "FK_public.DbRoleClosures_public.DbRoles_ParentID_AccountID" FOREIGN KEY ("ParentID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbRoles" add constraint "FK_public.DbRoles_public.DbRoles_RoleManagerID_AccountID" FOREIGN KEY ("RoleManagerID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbRoleRelationships" add constraint "FK_public.DbRoleRelationships_public.DbRoles_ParentRoleID_Accou" FOREIGN KEY ("ParentRoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbRoleRelationships" add constraint "FK_public.DbRoleRelationships_public.DbRoles_ChildRoleID_Accoun" FOREIGN KEY ("ChildRoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbRoleToAccountFeatures" add constraint "FK_public.DbRoleToAccountFeatures_public.DbRoles_RoleID_Account" FOREIGN KEY ("RoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbSamlConfigurations" add constraint "FK_public.DbSamlConfigurations_public.DbRoles_DefaultGroupID_Ac" FOREIGN KEY ("DefaultGroupID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbRoles" add constraint "FK_public.DbRoles_public.DbSecurityPolicies_SecurityPolicyID_Ac" FOREIGN KEY ("SecurityPolicyID", "AccountID") REFERENCES "DbSecurityPolicies"("Id", "AccountID");
alter table public."DbRoles" add constraint "FK_public.DbRoles_public.DbSystemPermissions_SystemPermissionID" FOREIGN KEY ("SystemPermissionID", "AccountID") REFERENCES "DbSystemPermissions"("Id", "AccountID");
alter table public."DbUserRolePreferences" add constraint "FK_public.DbUserRolePreferences_public.DbRoles_RoleID_AccountID" FOREIGN KEY ("RoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbUserSessionToDbRoles" add constraint "FK_public.DbUserSessionToDbRoles_public.DbRoles_RoleID_AccountI" FOREIGN KEY ("RoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
alter table public."DbAuditLogsToRoles" add constraint "FK_public.DbAuditLogsToRoles_public.DbAuditLogs_AuditLogID_Acco" FOREIGN KEY ("AuditLogID", "AccountID") REFERENCES "DbAuditLogs"("Id", "AccountID");
alter table public."DbAuditLogsToRoleDetails" add constraint "FK_public.DbAuditLogsToRoleDetails_public.DbAuditLogsToRoles_Au" FOREIGN KEY ("AuditLogToRoleID", "AccountID") REFERENCES "DbAuditLogsToRoles"("Id", "AccountID");
alter table public."DbAuditLogsToNodes" add constraint "FK_public.DbAuditLogsToNodes_public.DbAuditLogs_AuditLogID_Acco" FOREIGN KEY ("AuditLogID", "AccountID") REFERENCES "DbAuditLogs"("Id", "AccountID");
alter table public."DbAuditLogsToNodeDetails" add constraint "FK_public.DbAuditLogsToNodeDetails_public.DbAuditLogsToNodes_Au" FOREIGN KEY ("AuditLogToNodeID", "AccountID") REFERENCES "DbAuditLogsToNodes"("Id", "AccountID");
alter table public."DbDocumentRequestAttachments" add constraint "FK_public.DbDocumentRequestAttachments_public.DbDocumentRequest" FOREIGN KEY ("DocumentRequestID", "AccountID") REFERENCES "DbDocumentRequests"("Id", "AccountID");
alter table public."DbDocumentRequestContainers" add constraint "FK_public.DbDocumentRequestContainers_public.DbDocumentRequests" FOREIGN KEY ("DocumentRequestID", "AccountID") REFERENCES "DbDocumentRequests"("Id", "AccountID");
alter table public."DbDocumentRequestRoles" add constraint "FK_public.DbDocumentRequestRoles_public.DbDocumentRequests_Docu" FOREIGN KEY ("DocumentRequestID", "AccountID") REFERENCES "DbDocumentRequests"("Id", "AccountID");
alter table public."DbDocumentRequestToNotifications" add constraint "FK_public.DbDocumentRequestToNotifications_public.DbDocumentReq" FOREIGN KEY ("DocumentRequestID", "AccountID") REFERENCES "DbDocumentRequests"("Id", "AccountID") ON DELETE CASCADE;
alter table public."DbDocumentRequestContainerNodes" add constraint "FK_public.DbDocumentRequestContainerNodes_public.DbDocumentRequ" FOREIGN KEY ("DocumentRequestContainerID", "AccountID") REFERENCES "DbDocumentRequestContainers"("Id", "AccountID");
alter table public."DbDocumentRequestContainers" add constraint "FK_public.DbDocumentRequestContainers_public.DbFileInfoes_FileI" FOREIGN KEY ("FileInfoID", "AccountID") REFERENCES "DbFileInfoes"("Id", "AccountID");
alter table public."DbDocumentRequestContainers" add constraint "FK_public.DbDocumentRequestContainers_public.DbFormFillDefiniti" FOREIGN KEY ("FormFillDefinitionID", "AccountID") REFERENCES "DbFormFillDefinitions"("Id", "AccountID");
alter table public."DbFileQueue" add constraint "FK_public.DbFileQueue_public.DbFileInfoes_FileInfoID_AccountID" FOREIGN KEY ("FileInfoID", "AccountID") REFERENCES "DbFileInfoes"("Id", "AccountID");
alter table public."DbFileInfoes" add constraint "FK_public.DbFileInfoes_public.DbFormFillDefinitions_FormFillDef" FOREIGN KEY ("FormFillDefinitionID", "AccountID") REFERENCES "DbFormFillDefinitions"("Id", "AccountID");
alter table public."DbFileInfoes" add constraint "FK_public.DbFileInfoes_public.DbNodeComments_NodeCommentID_Acco" FOREIGN KEY ("NodeCommentID", "AccountID") REFERENCES "DbNodeComments"("Id", "AccountID");
alter table public."DbNodeToFileInfoes" add constraint "FK_public.DbNodeToFileInfoes_public.DbFileInfoes_FileInfoID_Acc" FOREIGN KEY ("FileInfoID", "AccountID") REFERENCES "DbFileInfoes"("Id", "AccountID");
alter table public."DbFileInfoes" add constraint "FK_public.DbFileInfoes_public.DbFileInfoes_GeneratedFromFileInf" FOREIGN KEY ("GeneratedFromFileInfoID", "AccountID") REFERENCES "DbFileInfoes"("Id", "AccountID");
alter table public."DbFormFillPendings" add constraint "FK_public.DbFormFillPendings_public.DbFormFillDefinitions_FormF" FOREIGN KEY ("FormFillDefinitionID", "AccountID") REFERENCES "DbFormFillDefinitions"("Id", "AccountID") ON DELETE CASCADE;
alter table public."DbFormFillToProfileItems" add constraint "FK_public.DbFormFillToProfileItems_public.DbFormFillDefinitions" FOREIGN KEY ("FormFillDefinitionID", "AccountID") REFERENCES "DbFormFillDefinitions"("Id", "AccountID") ON DELETE CASCADE;
alter table public."DbFormFillDefinitions" add constraint "FK_public.DbFormFillDefinitions_public.DbProfiles_ProfileID_Acc" FOREIGN KEY ("ProfileID", "AccountID") REFERENCES "DbProfiles"("Id", "AccountID");
alter table public."DbFormFillPendings" add constraint "FK_public.DbFormFillPendings_public.DbFileInfoes_AppliedNodeFil" FOREIGN KEY ("AppliedNodeFileInfoID", "AccountID") REFERENCES "DbFileInfoes"("Id", "AccountID") ON DELETE CASCADE;
alter table public."DbFormFillToProfileItems" add constraint "FK_public.DbFormFillToProfileItems_public.DbProfileItems_Profil" FOREIGN KEY ("ProfileItemID", "AccountID") REFERENCES "DbProfileItems"("Id", "AccountID");
alter table public."DbPresetValues" add constraint "FK_public.DbPresetValues_public.DbProfileItems_ProfileItemID_Ac" FOREIGN KEY ("ProfileItemID", "AccountID") REFERENCES "DbProfileItems"("Id", "AccountID");
alter table public."DbProfileToProfileItems" add constraint "FK_public.DbProfileToProfileItems_public.DbProfileItems_Profile" FOREIGN KEY ("ProfileItemID", "AccountID") REFERENCES "DbProfileItems"("Id", "AccountID");
alter table public."DbProfileValueNodes" add constraint "FK_public.DbProfileValueNodes_public.DbProfileItems_ProfileItem" FOREIGN KEY ("ProfileItemID", "AccountID") REFERENCES "DbProfileItems"("Id", "AccountID");
alter table public."DbProfileValueRoles" add constraint "FK_public.DbProfileValueRoles_public.DbProfileItems_ProfileItem" FOREIGN KEY ("ProfileItemID", "AccountID") REFERENCES "DbProfileItems"("Id", "AccountID");
alter table public."DbProfileValueNodes" add constraint "FK_public.DbProfileValueNodes_public.DbPresetValues_PresetValue" FOREIGN KEY ("PresetValueID", "AccountID") REFERENCES "DbPresetValues"("Id", "AccountID");
alter table public."DbProfileValueRoles" add constraint "FK_public.DbProfileValueRoles_public.DbPresetValues_PresetValue" FOREIGN KEY ("PresetValueID", "AccountID") REFERENCES "DbPresetValues"("Id", "AccountID");
alter table public."DbProfileValueNodes" add constraint "FK_public.DbProfileValueNodes_public.DbProfiles_ProfileID_Accou" FOREIGN KEY ("ProfileID", "AccountID") REFERENCES "DbProfiles"("Id", "AccountID");
alter table public."DbProfileToProfileItems" add constraint "FK_public.DbProfileToProfileItems_public.DbProfiles_ProfileID_A" FOREIGN KEY ("ProfileID", "AccountID") REFERENCES "DbProfiles"("Id", "AccountID");
alter table public."DbProfileValueRoles" add constraint "FK_public.DbProfileValueRoles_public.DbProfiles_ProfileID_Accou" FOREIGN KEY ("ProfileID", "AccountID") REFERENCES "DbProfiles"("Id", "AccountID");
alter table public."DbDocumentRequestToNotifications" add constraint "FK_public.DbDocumentRequestToNotifications_public.DbNotificatio" FOREIGN KEY ("NotificationID", "AccountID") REFERENCES "DbNotifications"("Id", "AccountID") ON DELETE CASCADE;
alter table public."DbWorkflowStageInstanceToNotifications" add constraint "FK_public.DbWorkflowStageInstanceToNotifications_public.DbNotif" FOREIGN KEY ("NotificationID", "AccountID") REFERENCES "DbNotifications"("Id", "AccountID") ON DELETE CASCADE;
alter table public."DbESignatureNodeAssociations" add constraint "FK_public.DbESignatureNodeAssociations_public.DbESignatureTrans" FOREIGN KEY ("TransactionID", "AccountID") REFERENCES "DbESignatureTransactions"("Id", "AccountID");
alter table public."DbESignatureSigners" add constraint "FK_public.DbESignatureSigners_public.DbESignatureTransactions_T" FOREIGN KEY ("TransactionID", "AccountID") REFERENCES "DbESignatureTransactions"("Id", "AccountID");
alter table public."DbESignatureTransactions" add constraint "FK_public.DbESignatureTransactions_public.DbESignatureTransacti" FOREIGN KEY ("TemplateID", "AccountID") REFERENCES "DbESignatureTransactions"("Id", "AccountID");
alter table public."DbSamlResponses" add constraint "FK_public.DbSamlResponses_public.DbSamlConfigurations_Configura" FOREIGN KEY ("ConfigurationID", "AccountID") REFERENCES "DbSamlConfigurations"("Id", "AccountID");
alter table public."DbPermissions" add constraint "FK_public.DbPermissions_public.DbPermissions_ChildPermissionId_" FOREIGN KEY ("ChildPermissionId", "AccountID") REFERENCES "DbPermissions"("Id", "AccountID");
alter table public."DbSecurityPolicyIpAddresses" add constraint "FK_public.DbSecurityPolicyIpAddresses_public.DbSecurityPolicies" FOREIGN KEY ("SecurityPolicyID", "AccountID") REFERENCES "DbSecurityPolicies"("Id", "AccountID");
alter table public."DbSecurityPolicyLoginTimes" add constraint "FK_public.DbSecurityPolicyLoginTimes_public.DbSecurityPolicies_" FOREIGN KEY ("SecurityPolicyID", "AccountID") REFERENCES "DbSecurityPolicies"("Id", "AccountID");
alter table public."DbEmailQueueAttachmentNodes" add constraint "FK_public.DbEmailQueueAttachmentNodes_public.DbEmailQueue_Email" FOREIGN KEY ("EmailQueueID", "AccountID") REFERENCES "DbEmailQueue"("Id", "AccountID");
alter table public."DbEmailRecipients" add constraint "FK_public.DbEmailRecipients_public.DbEmailQueue_EmailQueueID_Ac" FOREIGN KEY ("EmailQueueID", "AccountID") REFERENCES "DbEmailQueue"("Id", "AccountID");
alter table public."DbSfLinks" add constraint "FK_public.DbSfLinks_public.DbSfMappings_SfMappingID_AccountID" FOREIGN KEY ("SfMappingID", "AccountID") REFERENCES "DbSfMappings"("Id", "AccountID");
alter table public."DbSfMappings" add constraint "FK_public.DbSfMappings_public.DbPermissions_GroupPermissionID_A" FOREIGN KEY ("GroupPermissionID", "AccountID") REFERENCES "DbPermissions"("Id", "AccountID");
alter table public."DbSfMappings" add constraint "FK_public.DbSfMappings_public.DbPermissions_UserPermissionID_Ac" FOREIGN KEY ("UserPermissionID", "AccountID") REFERENCES "DbPermissions"("Id", "AccountID");
alter table public."DbEmailTemplateToPartner" add constraint "FK_public.DbEmailTemplateToPartner_public.DbPartners_PartnerID" FOREIGN KEY ("PartnerID") REFERENCES "DbPartners"("Id");
alter table public."DbUserSessionToDbRoles" add constraint "FK_public.DbUserSessionToDbRoles_public.DbUserSessions_UserSess" FOREIGN KEY ("UserSessionID") REFERENCES "DbUserSessions"("Id");
alter table workflow."DbWorkflowSetProfileItems" add constraint "FK_workflow.DbWorkflowSetProfileItems_workflow.DbWorkflowSteps_" FOREIGN KEY ("StepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowShareStepNewUserReferences" add constraint "FK_workflow.DbWorkflowShareStepNewUserReferences_workflow.DbWor" FOREIGN KEY ("StepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowStepGroupReferences" add constraint "FK_workflow.DbWorkflowStepGroupReferences_workflow.DbWorkflowSt" FOREIGN KEY ("StepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowStepUserReferences" add constraint "FK_workflow.DbWorkflowStepUserReferences_workflow.DbWorkflowSte" FOREIGN KEY ("StepID") REFERENCES workflow."DbWorkflowSteps"("Id");
alter table workflow."DbWorkflowAssetsStages" add constraint "FK_workflow.DbWorkflowAssetsStages_workflow.DbWorkflowStages_St" FOREIGN KEY ("StageID") REFERENCES workflow."DbWorkflowStages"("Id");
alter table workflow."DbWorkflowStageInstances" add constraint "FK_workflow.DbWorkflowStageInstances_workflow.DbWorkflowStages_" FOREIGN KEY ("StageTypeID") REFERENCES workflow."DbWorkflowStages"("Id");
alter table workflow."DbWorkflowStageApproverGroups" add constraint "FK_workflow.DbWorkflowStageApproverGroups_workflow.DbWorkflowSt" FOREIGN KEY ("WorkflowStageID") REFERENCES workflow."DbWorkflowStages"("Id");
alter table workflow."DbWorkflowStageApprovers" add constraint "FK_workflow.DbWorkflowStageApprovers_workflow.DbWorkflowStages_" FOREIGN KEY ("WorkflowStageID") REFERENCES workflow."DbWorkflowStages"("Id");
alter table workflow."DbWorkflowStageAssigneeGroups" add constraint "FK_workflow.DbWorkflowStageAssigneeGroups_workflow.DbWorkflowSt" FOREIGN KEY ("WorkflowStageID") REFERENCES workflow."DbWorkflowStages"("Id");
alter table workflow."DbWorkflowStageAssignees" add constraint "FK_workflow.DbWorkflowStageAssignees_workflow.DbWorkflowStages_" FOREIGN KEY ("WorkflowStageID") REFERENCES workflow."DbWorkflowStages"("Id");
alter table workflow."DbProfileRoutingRules" add constraint "FK_workflow.DbProfileRoutingRules_workflow.DbWorkflowStages_Sta" FOREIGN KEY ("StageID") REFERENCES workflow."DbWorkflowStages"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowStages_StageID" FOREIGN KEY ("StageID") REFERENCES workflow."DbWorkflowStages"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_requestF1" FOREIGN KEY ("requestFileExternal_AttachmentAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_requestF2" FOREIGN KEY ("requestFileExternal_DestinationAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowStepDocumentRequestContainers" add constraint "FK_workflow.DbWorkflowStepDocumentRequestContainers_workflow.D2" FOREIGN KEY ("AssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbAssetNodeReference" add constraint "FK_workflow.DbAssetNodeReference_workflow.DbWorkflowAssets_Asse" FOREIGN KEY ("AssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowAssetsStages" add constraint "FK_workflow.DbWorkflowAssetsStages_workflow.DbWorkflowAssets_As" FOREIGN KEY ("AssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowStages" add constraint "FK_workflow.DbWorkflowStages_workflow.DbWorkflowAssets_Approval" FOREIGN KEY ("ApprovalAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbProfileRoutingRules" add constraint "FK_workflow.DbProfileRoutingRules_workflow.DbWorkflowAssets_Ass" FOREIGN KEY ("AssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_addTrigg1" FOREIGN KEY ("addTrigger_DestinationAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_addTrigg2" FOREIGN KEY ("addTrigger_TargetAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_applyTemp" FOREIGN KEY ("applyTemplate_TargetPathAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_comment_T" FOREIGN KEY ("comment_TargetAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_copy_Dest" FOREIGN KEY ("copy_DestinationAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_copy_Resu" FOREIGN KEY ("copy_ResultAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_copy_Sour" FOREIGN KEY ("copy_SourceAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_createLo1" FOREIGN KEY ("createLocation_ParentPathAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_createLo2" FOREIGN KEY ("createLocation_ResultAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_delete_Ta" FOREIGN KEY ("delete_TargetAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_esignatu1" FOREIGN KEY ("esignature_AuditTrailAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_esignatu2" FOREIGN KEY ("esignature_AuditTrailDestinationAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_esignatu3" FOREIGN KEY ("esignature_SignedResultAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_esignatu4" FOREIGN KEY ("esignature_SignedResultDestinationAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_esignatu5" FOREIGN KEY ("esignature_SourceAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowESignatureStepTemplateDocuments" add constraint "FK_workflow.DbWorkflowESignatureStepTemplateDocuments_workflow2" FOREIGN KEY ("SourceAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_move_Dest" FOREIGN KEY ("move_DestinationAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_move_Sour" FOREIGN KEY ("move_SourceAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_rename_Ta" FOREIGN KEY ("rename_TargetAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_sendMessa" FOREIGN KEY ("sendMessage_AttachmentAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_setPermis" FOREIGN KEY ("setPermissions_TargetAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_setProfil" FOREIGN KEY ("setProfile_TargetAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_setReten1" FOREIGN KEY ("setRetention_DestinationAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_setReten2" FOREIGN KEY ("setRetention_TargetAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_share_Sou" FOREIGN KEY ("share_SourceAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_upload_Re" FOREIGN KEY ("upload_ResultAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowSteps" add constraint "FK_workflow.DbWorkflowSteps_workflow.DbWorkflowAssets_upload_So" FOREIGN KEY ("upload_SourceAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowAssetInstances" add constraint "FK_workflow.DbWorkflowAssetInstances_workflow.DbWorkflowAssets_" FOREIGN KEY ("WorkflowAssetID") REFERENCES workflow."DbWorkflowAssets"("Id");
alter table workflow."DbWorkflowAssets" add constraint "FK_workflow.DbWorkflowAssets_workflow.DbWorkflows_WorkflowID" FOREIGN KEY ("WorkflowID") REFERENCES workflow."DbWorkflows"("Id");
alter table workflow."DbWorkflowInstanceHistoryRecords" add constraint "FK_workflow.DbWorkflowInstanceHistoryRecords_workflow.DbWorkfl2" FOREIGN KEY ("WorkflowID") REFERENCES workflow."DbWorkflows"("Id");
alter table workflow."DbWorkflowInstances" add constraint "FK_workflow.DbWorkflowInstances_workflow.DbWorkflows_WorkflowID" FOREIGN KEY ("WorkflowID") REFERENCES workflow."DbWorkflows"("Id");
alter table workflow."DbWorkflowsAvailableStates" add constraint "FK_workflow.DbWorkflowsAvailableStates_workflow.DbWorkflows_Wor" FOREIGN KEY ("WorkflowID") REFERENCES workflow."DbWorkflows"("Id");
alter table workflow."DbWorkflowNotificationConfigurations" add constraint "FK_workflow.DbWorkflowNotificationConfigurations_workflow.DbWor" FOREIGN KEY ("Id") REFERENCES workflow."DbWorkflows"("Id");
alter table workflow."DbWorkflowOwnerGroups" add constraint "FK_workflow.DbWorkflowOwnerGroups_workflow.DbWorkflows_Workflow" FOREIGN KEY ("WorkflowID") REFERENCES workflow."DbWorkflows"("Id");
alter table workflow."DbWorkflowOwners" add constraint "FK_workflow.DbWorkflowOwners_workflow.DbWorkflows_WorkflowID" FOREIGN KEY ("WorkflowID") REFERENCES workflow."DbWorkflows"("Id");
alter table workflow."DbWorkflowScheduleConfigurations" add constraint "FK_workflow.DbWorkflowScheduleConfigurations_workflow.DbWorkflo" FOREIGN KEY ("Id") REFERENCES workflow."DbWorkflows"("Id");
alter table workflow."DbWorkflowStages" add constraint "FK_workflow.DbWorkflowStages_workflow.DbWorkflows_WorkflowID" FOREIGN KEY ("WorkflowID") REFERENCES workflow."DbWorkflows"("Id");
alter table workflow."DbWorkflowStarterGroups" add constraint "FK_workflow.DbWorkflowStarterGroups_workflow.DbWorkflows_Workfl" FOREIGN KEY ("WorkflowID") REFERENCES workflow."DbWorkflows"("Id");
alter table workflow."DbWorkflowStarters" add constraint "FK_workflow.DbWorkflowStarters_workflow.DbWorkflows_WorkflowID" FOREIGN KEY ("WorkflowID") REFERENCES workflow."DbWorkflows"("Id");
alter table workflow."DbWorkflowWatcherGroups" add constraint "FK_workflow.DbWorkflowWatcherGroups_workflow.DbWorkflows_Workfl" FOREIGN KEY ("WorkflowID") REFERENCES workflow."DbWorkflows"("Id");
alter table workflow."DbWorkflowWatchers" add constraint "FK_workflow.DbWorkflowWatchers_workflow.DbWorkflows_WorkflowID" FOREIGN KEY ("WorkflowID") REFERENCES workflow."DbWorkflows"("Id");
alter table workflow."DbWorkflowsAvailableStates" add constraint "FK_workflow.DbWorkflowsAvailableStates_workflow.DbWorkflowInsta" FOREIGN KEY ("StateID") REFERENCES workflow."DbWorkflowInstanceStates"("Id");
alter table workflow."DbWorkflowStages" add constraint "FK_workflow.DbWorkflowStages_workflow.DbWorkflowInstanceStates1" FOREIGN KEY ("ApprovedRoutingWorkflowInstanceStateID") REFERENCES workflow."DbWorkflowInstanceStates"("Id");
alter table workflow."DbWorkflowStages" add constraint "FK_workflow.DbWorkflowStages_workflow.DbWorkflowInstanceStates2" FOREIGN KEY ("DefaultProfileRoutingWorkflowInstanceStateID") REFERENCES workflow."DbWorkflowInstanceStates"("Id");
alter table workflow."DbWorkflowStages" add constraint "FK_workflow.DbWorkflowStages_workflow.DbWorkflowInstanceStates3" FOREIGN KEY ("PastRoutingWorkflowInstanceStateID") REFERENCES workflow."DbWorkflowInstanceStates"("Id");
alter table workflow."DbProfileRoutingRules" add constraint "FK_workflow.DbProfileRoutingRules_workflow.DbWorkflowInstanceSt" FOREIGN KEY ("RoutingWorkflowInstanceStateID") REFERENCES workflow."DbWorkflowInstanceStates"("Id");
alter table workflow."DbWorkflowStages" add constraint "FK_workflow.DbWorkflowStages_workflow.DbWorkflowInstanceStates4" FOREIGN KEY ("RejectedRoutingWorkflowInstanceStateID") REFERENCES workflow."DbWorkflowInstanceStates"("Id");
alter table workflow."DbWorkflowAssetInstances" add constraint "FK_workflow.DbWorkflowAssetInstances_workflow.DbWorkflowInstanc" FOREIGN KEY ("WorkflowID") REFERENCES workflow."DbWorkflowInstances"("Id");
alter table workflow."DbWorkflowInstanceHistoryRecords" add constraint "FK_workflow.DbWorkflowInstanceHistoryRecords_workflow.DbWorkfl3" FOREIGN KEY ("WorkflowInstanceID") REFERENCES workflow."DbWorkflowInstances"("Id");
alter table workflow."DbWorkflowStageInstances" add constraint "FK_workflow.DbWorkflowStageInstances_workflow.DbWorkflowInstanc" FOREIGN KEY ("WorkflowID") REFERENCES workflow."DbWorkflowInstances"("Id");
alter table workflow."DbWorkflowInstanceHistoryRecords" add constraint "FK_workflow.DbWorkflowInstanceHistoryRecords_workflow.DbWorkfl4" FOREIGN KEY ("StageInstanceID") REFERENCES workflow."DbWorkflowStageInstances"("Id");
alter table workflow."DbWorkflowStepInstances" add constraint "FK_workflow.DbWorkflowStepInstances_workflow.DbWorkflowStageIns" FOREIGN KEY ("StageID") REFERENCES workflow."DbWorkflowStageInstances"("Id");
alter table workflow."DbWorkflowInstances" add constraint "FK_workflow.DbWorkflowInstances_workflow.DbWorkflowStageInstanc" FOREIGN KEY ("CurrentStageID") REFERENCES workflow."DbWorkflowStageInstances"("Id");
alter table workflow."DbWorkflowAssetsStagesInstances" add constraint "FK_workflow.DbWorkflowAssetsStagesInstances_workflow.DbWorkflo2" FOREIGN KEY ("StageID") REFERENCES workflow."DbWorkflowStageInstances"("Id");
alter table workflow."DbWorkflowSetProfileInstanceItemPresetValues" add constraint "FK_workflow.DbWorkflowSetProfileInstanceItemPresetValues_workfl" FOREIGN KEY ("StepProfileItemID") REFERENCES workflow."DbWorkflowSetProfileInstanceItems"("Id");
alter table workflow."DbWorkflowSetProfileItemPresetValues" add constraint "FK_workflow.DbWorkflowSetProfileItemPresetValues_workflow.DbWor" FOREIGN KEY ("StepProfileItemID") REFERENCES workflow."DbWorkflowSetProfileItems"("Id");
alter table public."DbWorkflowStageInstanceToNotifications" add constraint "FK_DbWorkflowStageInstanceToNotifications_DbWorkflowStageInstan" FOREIGN KEY ("WorkflowStageInstanceID") REFERENCES workflow."DbWorkflowStageInstances"("Id");
alter table public."DbRoles" add constraint "CK_RoleManagerID" CHECK ("RoleType" = 3 AND "RoleManagerID" IS NOT NULL OR "RoleType" <> '-1'::integer AND "RoleManagerID" IS NULL);
alter table public."DbDocumentRequestAttachments" add constraint "FK_public.DbDocumentRequestAttachments_public.DbAccounts_Accoun" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbFormFillDefinitions" add constraint "FK_public.DbFormFillDefinitions_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbDocumentRequestContainers" add constraint "FK_public.DbDocumentRequestContainers_public.DbAccounts_Account" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbDocumentRequestContainerNodes" add constraint "FK_public.DbDocumentRequestContainerNodes_public.DbAccounts_Acc" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbFormFillPendings" add constraint "FK_public.DbFormFillPendings_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbFormFillToProfileItems" add constraint "FK_public.DbFormFillToProfileItems_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbNodeComments" add constraint "FK_public.DbNodeComments_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbESignatureSigners" add constraint "FK_public.DbESignatureSigners_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbESignatureNodeAssociations" add constraint "FK_public.DbESignatureNodeAssociations_public.DbAccounts_Accoun" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbSecurityPolicyIpAddresses" add constraint "FK_public.DbSecurityPolicyIpAddresses_public.DbAccounts_Account" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbSecurityPolicyLoginTimes" add constraint "FK_public.DbSecurityPolicyLoginTimes_public.DbAccounts_AccountI" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbUserRolePreferences" add constraint "FK_public.DbUserRolePreferences_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbTriggerToApiCallouts" add constraint "FK_public.DbTriggerToApiCallouts_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbWatermarkTriggerInfo" add constraint "FK_public.DbWatermarkTriggerInfo_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbLegacyNodeMappings" add constraint "FK_public.DbLegacyNodeMappings_public.DbAccounts_AccountID" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbAccessLinksToDocumentRequests" add constraint "FK_public.DbAccessLinksToDocumentRequests_public.DbAccounts_Acc" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbDocumentRequestToNotifications" add constraint "FK_public.DbDocumentRequestToNotifications_public.DbAccounts_Ac" FOREIGN KEY ("AccountID") REFERENCES "DbAccounts"("Id");
alter table public."DbPermissions" add constraint ck_permission CHECK ("Restrict" = false OR "Restrict" = true AND "Preview" = false AND "Read" = false AND "Write" = false AND "Delete" = false AND "Admin" = false AND "UploadFiles" = false AND "CreateDirectories" = false AND "ChildPermissionId" IS NULL AND ("Enforce" = false OR "Enforce" = true));

select create_distributed_function('"patindex"(character varying,character varying)');
select create_distributed_function('"isnumeric"(text)');
select create_distributed_function('"func_getnaturalsortablevalue"(character varying)');
select create_distributed_function('"datediff"(character varying,timestamp without time zone,timestamp without time zone)');
select create_distributed_function('"func_insertintodbtemptablesearchresults"(dbtemptablesearchresulttype[])');

CREATE OR REPLACE FUNCTION createrelationships() RETURNS TRIGGER AS $$
BEGIN 
  EXECUTE format(
	  'insert into %1$s ("ParentID", "ChildID", "Depth", "AccountID") values (($1)."Id", ($1)."Id", 0, ($1)."AccountID");
	  insert into %1$s ("ParentID", "ChildID", "Depth", "AccountID")
	  select closures."ParentID", ($1)."Id", closures."Depth" + 1, ($1)."AccountID"
	  from %1$s as closures WHERE ($1)."ParentID" = closures."ChildID";',
	  TG_ARGV[0]
   ) USING NEW;	
   RETURN NEW;
END;
$$ LANGUAGE plpgsql;

select create_distributed_function('createrelationships()');

SELECT run_command_on_colocated_placements(
  'public."DbNodes"',
  'public."DbNodeClosures"',
  $cmd$
    CREATE TRIGGER tr_dbnode_insert AFTER INSERT ON %s
      FOR EACH ROW EXECUTE PROCEDURE createRelationships(%L)
  $cmd$	
);

CREATE OR REPLACE FUNCTION updateRelationships() RETURNS TRIGGER AS $$
BEGIN 
  EXECUTE format(
	  'delete from %1$s
	   where "ChildID" in (select "ChildID" from %1$s where "ParentID" = ($1)."Id" and "AccountID" = ($1)."AccountID")
       and "ParentID" in (select "ParentID" from %1$s where "ChildID" = ($1)."Id" and "ParentID" != "ChildID" and "AccountID" = ($1)."AccountID");
	   
	   insert into %1$s ("ParentID", "ChildID", "Depth", "AccountID")
       select supertree."ParentID", subtree."ChildID", supertree."Depth" + subtree."Depth" + 1, supertree."AccountID"
       from %1$s supertree, %1$s subtree
       where supertree."ChildID" = ($1)."ParentID" and subtree."ParentID" = ($1)."Id" and supertree."AccountID" = subtree."AccountID";',
	  TG_ARGV[0]
   ) USING NEW;	
   RETURN NEW;
END;
$$ LANGUAGE plpgsql;

select create_distributed_function('updateRelationships()');

SELECT run_command_on_colocated_placements(
  'public."DbNodes"',
  'public."DbNodeClosures"',
  $cmd$
    CREATE TRIGGER tr_dbnode_update AFTER UPDATE ON %s
      FOR EACH ROW WHEN ((old."ParentID" IS DISTINCT FROM new."ParentID")) EXECUTE PROCEDURE updaterelationships(%L)
  $cmd$	
);

CREATE OR REPLACE FUNCTION createdroleclosurerelationship() RETURNS TRIGGER AS $$
DECLARE
closure bigint := NULL;
BEGIN	
	EXECUTE format(
	'SELECT * FROM "%s" WHERE "ChildID" = ($1)."ParentID" AND "ParentID" = ($1)."ChildID" AND ($1)."AccountID" = "AccountID";', 
	 TG_ARGV[0]) USING NEW INTO closure;
    IF closure IS NOT NULL
 	THEN
    	RETURN NULL;
    END IF;
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

select create_distributed_function('createdroleclosurerelationship()');

SELECT run_command_on_placements(
  'public."DbRoleClosures"',
  $cmd$
    CREATE TRIGGER tr_dbroleclosures_insert BEFORE INSERT ON %1$s
	  FOR EACH ROW EXECUTE FUNCTION createdroleclosurerelationship(%1$s)
  $cmd$	
);

CREATE OR REPLACE FUNCTION createrolerelationship() RETURNS TRIGGER AS $$
BEGIN	
    EXECUTE format(
    'INSERT INTO %s ("ParentID", "ChildID", "AccountID") values (($1)."Id", ($1)."Id", ($1)."AccountID");',
	 TG_ARGV[0]
   ) USING NEW;
   RETURN NEW;
END;
$$ LANGUAGE plpgsql;

select create_distributed_function('createrolerelationship()');

SELECT run_command_on_colocated_placements(
  'public."DbRoles"',
  'public."DbRoleClosures"',
  $cmd$
    CREATE TRIGGER tr_dbrole_insert AFTER INSERT ON %s 
	  FOR EACH ROW EXECUTE FUNCTION createrolerelationship(%L);
  $cmd$	
);

CREATE OR REPLACE FUNCTION deleterolerelationship() RETURNS TRIGGER AS $$
BEGIN	
    EXECUTE format(
    'DELETE FROM %s
     where "ParentID" = "ChildID" and "ChildID" = ($1)."Id" and "AccountID" = ($1)."AccountID";',
	 TG_ARGV[0]
   ) USING OLD;
   RETURN OLD;
END;
$$ LANGUAGE plpgsql;

select create_distributed_function('deleterolerelationship()');

SELECT run_command_on_colocated_placements(
  'public."DbRoles"',
  'public."DbRoleClosures"',
  $cmd$
    CREATE TRIGGER tr_dbrole_delete BEFORE DELETE ON %s 
	  FOR EACH ROW EXECUTE FUNCTION deleterolerelationship(%L);
  $cmd$	
);

CREATE OR REPLACE PROCEDURE sp_insertRoleRelationshipClosures(tableName text, parentid bigint, childid bigint, accountID int)
AS $$
BEGIN
	EXECUTE format(
    'INSERT INTO %1$s ("ParentID", "ChildID", "AccountID")
     SELECT cl."ParentID", child."ChildID", child."AccountID"
     FROM %1$s AS cl
	 JOIN %1$s AS child on child."ParentID" = $2 AND child."AccountID" = cl."AccountID"
     WHERE cl."ChildID" = $1 AND cl."AccountID" = $3;',
	 tableName
   ) USING parentid, childid, accountID;
END;
$$ LANGUAGE 'plpgsql';	

select create_distributed_function('"sp_insertrolerelationshipclosures"(text,bigint,bigint,integer)');

CREATE OR REPLACE FUNCTION insertrolerelationshipclosures() RETURNS TRIGGER AS $$
BEGIN	
    EXECUTE format(
    'CALL sp_insertRoleRelationshipClosures(''%1$s'', ($1)."ParentRoleID", ($1)."ChildRoleID", ($1)."AccountID");',
	 TG_ARGV[0]
   ) USING NEW;
   RETURN NEW;
END;
$$ LANGUAGE plpgsql;

select create_distributed_function('insertrolerelationshipclosures()');

SELECT run_command_on_colocated_placements(
  'public."DbRoleRelationships"',
  'public."DbRoleClosures"',
  $cmd$
	CREATE TRIGGER tr_dbrolerelationships_insert AFTER INSERT ON %s 
	  FOR EACH ROW EXECUTE FUNCTION insertrolerelationshipclosures(%L);
  $cmd$	
);

CREATE OR REPLACE PROCEDURE sp_deleteRoleRelationshipClosures(tablename text, parentid bigint, childid bigint, accountid int)
AS $$
DECLARE
    db_row RECORD;
    db_cursor refcursor;
BEGIN
    OPEN db_cursor FOR EXECUTE format(
	'SELECT parent."ParentID", child."ChildID" 
	 FROM %1$s AS parent 
	 JOIN %1$s AS child ON child."ParentID" = $2 AND child."AccountID" = parent."AccountID"
	 WHERE parent."ChildID" = $1 AND parent."AccountID" = $3 
	 GROUP BY parent."ParentID", child."ChildID"', tablename) USING parentid, childid, accountid;
    LOOP
        FETCH db_cursor INTO db_row;
        EXIT WHEN NOT FOUND;
        EXECUTE format('DELETE FROM %s cl WHERE cl."ParentID" = $1 AND cl."ChildID" = $2 AND cl."AccountID" = $3;', tablename) USING db_row."ParentID", db_row."ChildID", accountid;
    END LOOP;
    CLOSE db_cursor;
END;
$$ LANGUAGE 'plpgsql';
								   
select create_distributed_function('"sp_deleterolerelationshipclosures"(text,bigint,bigint,int)');

CREATE OR REPLACE FUNCTION deleteRoleRelationshipClosures() RETURNS TRIGGER AS $$
BEGIN	
    EXECUTE format(
	'CALL sp_deleterolerelationshipclosures(''%1$s'', ($1)."ParentRoleID", ($1)."ChildRoleID", ($1)."AccountID")',
	 TG_ARGV[0]
   ) USING OLD;
   RETURN OLD;
END;
$$ LANGUAGE plpgsql;

select create_distributed_function('deleteRoleRelationshipClosures()');

SELECT run_command_on_colocated_placements(
  'public."DbRoleRelationships"',
  'public."DbRoleClosures"',
  $cmd$
	CREATE TRIGGER tr_DbRoleRelationships_delete BEFORE DELETE ON %s 
	  FOR EACH ROW EXECUTE PROCEDURE deleteRoleRelationshipClosures(%L);
  $cmd$	
);

CREATE OR REPLACE FUNCTION updateRoleRelationshipClosures()
    RETURNS trigger AS $$
BEGIN
	EXECUTE format('CALL sp_deleterolerelationshipclosures(''%1$s'', ($1)."ParentRoleID", ($1)."ChildRoleID", ($1)."AccountID");', TG_ARGV[0]) USING OLD;
	EXECUTE format('CALL sp_insertrolerelationshipclosures(''%1$s'', ($1)."ParentRoleID", ($1)."ChildRoleID", ($1)."AccountID");', TG_ARGV[0]) USING NEW;
    RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';

select create_distributed_function('updateRoleRelationshipClosures()');

SELECT run_command_on_colocated_placements(
  'public."DbRoleRelationships"',
  'public."DbRoleClosures"',
  $cmd$
	CREATE TRIGGER tr_dbrolerelationships_update AFTER UPDATE ON %s 
	  FOR EACH ROW EXECUTE FUNCTION updaterolerelationshipclosures(%L);
  $cmd$	
);

IMPORTANT!

  1. When you mark table as "distributed" all referenced table must be a distributed table or a reference table.
  2. When you mark table as "distributed" PK and Unique constraints must include distribution key (AccountID)
  3. You can't use GENERATED BY ... AS IDENTITY

The Following SQL Queries were super helpful in generating the script to distribute the database.

namespace CitusTableDistributionTool.SQL
{
    internal static class SqlQueries
    {
        public static string CreateDbAccountsDistributedTableCommand => @"SELECT create_distributed_table('""DbAccounts""', 'Id');";

        public static string CreateDbUsersSessionsReferenceTableCommand => @"SELECT create_reference_table('""public"".""DbUserSessions""');";

        public static string QueryAddConstraintCommands => @"
select 'alter table '||quote_ident(ns.nspname)||'.'||quote_ident(tb.relname)||
       ' add constraint '||quote_ident(conname)||' '||
       pg_get_constraintdef(c.oid, true)||';' as ddl
from pg_constraint c
  join pg_class tb on tb.oid = c.conrelid
  left outer join pg_inherits on pg_inherits.inhrelid = tb.oid
  join pg_namespace ns on ns.oid = tb.relnamespace
where ns.nspname in ('public', 'workflow')
 and c.contype in ('f', 'c')
 and pg_inherits.inhrelid is null;";       

        public static string QueryCreateDistributedTablesCommands => @"
select 'SELECT create_distributed_table(''""' || t.table_schema || '"".""' || t.table_name || '""'', ''AccountID'');'   
from information_schema.tables t
inner join information_schema.columns c on c.table_name = t.table_name
                                and c.table_schema = t.table_schema
join pg_class on pg_class.relname = c.table_name
left outer join pg_inherits on pg_inherits.inhrelid = pg_class.oid
where c.column_name = 'AccountID'
      and t.table_name != 'DbUserSessions'
      and t.table_schema in ('public')
      and t.table_type = 'BASE TABLE'
	  and pg_inherits.inhrelid is null
      and (pg_class.relkind = 'r' or pg_class.relkind = 'p')
order by t.table_schema;";

        public static string QueryCreatePublicReferenceTablesCommands => @"
select 'SELECT create_reference_table(''""' || t.table_schema || '"".""' || t.table_name || '""'');' 
from information_schema.tables t
left join (select table_schema, table_name
           from information_schema.columns
           where column_name = 'AccountID') c
                    on c.table_name = t.table_name
                    and c.table_schema = t.table_schema
join pg_class on pg_class.relname = t.table_name
left outer join pg_inherits on pg_inherits.inhrelid = pg_class.oid
where c.table_name is null 
      and t.table_name != 'DbAccounts'
      and t.table_schema in ('public')
      and t.table_type = 'BASE TABLE'
      and pg_inherits.inhrelid is null
      and (pg_class.relkind = 'r' or pg_class.relkind = 'p')
order by t.table_schema,
         t.table_name;";

        public static string QueryCreateTriggerCommands => @"
SELECT pg_get_triggerdef(oid) || ';'
FROM information_schema.triggers
JOIN pg_trigger ON pg_trigger.tgname = information_schema.triggers.trigger_name
WHERE trigger_schema in ('public', 'workflow');";

        public static string QueryCreateWorkflowReferenceTablesCommands => @"
select 'SELECT create_reference_table(''""' || t.table_schema || '"".""' || t.table_name || '""'');' 
from information_schema.tables t
join pg_class on pg_class.relname = t.table_name
left outer join pg_inherits on pg_inherits.inhrelid = pg_class.oid
where t.table_schema in ('workflow')
      and t.table_type = 'BASE TABLE'
      and pg_inherits.inhrelid is null
      and (pg_class.relkind = 'r' or pg_class.relkind = 'p')
order by t.table_schema,
         t.table_name;";

        public static string QueryDistributeFunctionsAndStoredProceduresInfo => @"
        select 'select create_distributed_function(''""' || p.proname || '""(' || '{0}' || ')'');' as CommandTemplate,
       pg_get_function_arguments(p.oid) as Arguments
from pg_proc p
left join pg_namespace n on p.pronamespace = n.oid
left join pg_language l on p.prolang = l.oid
left join pg_type t on t.oid = p.prorettype 
where n.nspname not in ('pg_catalog', 'information_schema')
	and n.nspname in ('public', 'workflow')
    and p.proname not like '%uuid_%';
";

        public static string QueryDropConstraintCommands => @"
select 'alter table '||quote_ident(ns.nspname)||'.'||quote_ident(tb.relname)||
       ' drop constraint '||quote_ident(conname)||';' as ddl
from pg_constraint c
  join pg_class tb on tb.oid = c.conrelid
  left outer join pg_inherits on pg_inherits.inhrelid = tb.oid
  join pg_namespace ns on ns.oid = tb.relnamespace
where ns.nspname in ('public', 'workflow')
 and c.contype in ('f', 'c')
 and pg_inherits.inhrelid is null;";

        public static string QueryDropTriggerCommands => @"
SELECT 'DROP TRIGGER ' || tgname || ' ON ""' || event_object_schema || '"".""' || event_object_table || '"";'
FROM information_schema.triggers
JOIN pg_trigger ON pg_trigger.tgname = information_schema.triggers.trigger_name
WHERE trigger_schema in ('public', 'workflow');";

        public static string IfStatementForFutureUseInMigrations => @"
DO
    $do$
    BEGIN
        IF EXISTS (SELECT * FROM pg_extension WHERE extname = 'citus') THEN
            {COMMAND GOES HERE}
        END IF;
    END
$do$";
    }

    public class DistributeFunctionsAndStoredProceduresInfo
    {
        public string CommandTemplate { get; set; }
        public string Arguments { get; set; }
    }

    // views? types?


    //    distrubute functions https://docs.microsoft.com/en-us/azure/postgresql/reference-hyperscale-functions
    //    SELECT create_distributed_function('createrolerelationship()'); - seems to only work with trigger functions - jk SELECT create_distributed_function('"func_RoleIsGroup"(bigint)');

    //     also need to figure out how to do complex joins

    // need to apply extension uuis-ossp, triggers, to all worker nodes
}

A Few Things We Learned

This will colocate a set of tables with another table (there is also a parameter called 'colocate' to specify this when running the create_distributed_table command)

SELECT mark_tables_colocated('stores', ARRAY['products', 'line_items']);

A few changes that still need to accounted for on the quinng/citusStuffs branch.

  • The Id column was dropped on the DbRoleClosures table because the id would not get autopopulated when triggers inserted new rows to this table.
  • The DbUserSessions table was not distributed even though it has an accountID. It is most often not queried by the accountID. So... the following constraint had to be removed
    alter table public."DbUserSessions" add constraint "FK_public.DbUserSessions_public.DbRoles_RoleID_AccountID" FOREIGN KEY ("RoleID", "AccountID") REFERENCES "DbRoles"("Id", "AccountID");
  • The role_is_group function was removed because it was used in a constraint, and was having issues. This function could probably be written in a different way to get it working.
  • The branch 'quinn/citusStuffs' has all the work we did to get Citus working, pay particular attention to the changes in the initial migration script.