PlotDirector/PlotLine/Sql/275_InvestigationGuidance.sql

13 lines
847 B
Transact-SQL

-- Phase 1.5: private follow-through state only. Canonical investigations/events remain untouched.
SET ANSI_NULLS ON;
SET QUOTED_IDENTIFIER ON;
GO
IF OBJECT_ID('dbo.WriterInvestigationGuidance') IS NULL
CREATE TABLE dbo.WriterInvestigationGuidance(
InvestigationID uniqueidentifier NOT NULL PRIMARY KEY REFERENCES dbo.WriterInvestigations(ID) ON DELETE CASCADE,
UserID int NOT NULL, BookID int NOT NULL, IsActive bit NOT NULL DEFAULT 1, Finished bit NOT NULL DEFAULT 0,
Version int NOT NULL, Json nvarchar(max) NOT NULL CHECK(ISJSON(Json)=1), UpdatedUtc datetime2 NOT NULL DEFAULT SYSUTCDATETIME());
IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE object_id=OBJECT_ID('dbo.WriterInvestigationGuidance') AND name='IX_Guidance_Active')
CREATE UNIQUE INDEX IX_Guidance_Active ON dbo.WriterInvestigationGuidance(UserID,BookID) WHERE IsActive=1;
GO