SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO

IF OBJECT_ID(N'dbo.StoryIntelligenceBookPipelines', N'U') IS NOT NULL
BEGIN
    IF EXISTS
    (
        SELECT 1
        FROM sys.check_constraints
        WHERE name = N'CK_StoryIntelligenceBookPipelines_CurrentStage'
            AND parent_object_id = OBJECT_ID(N'dbo.StoryIntelligenceBookPipelines')
    )
    BEGIN
        ALTER TABLE dbo.StoryIntelligenceBookPipelines
            DROP CONSTRAINT CK_StoryIntelligenceBookPipelines_CurrentStage;
    END;

    ALTER TABLE dbo.StoryIntelligenceBookPipelines
        ADD CONSTRAINT CK_StoryIntelligenceBookPipelines_CurrentStage
        CHECK (CurrentStage IN
        (
            N'Chapters',
            N'SceneReview',
            N'SceneImport',
            N'CharacterReview',
            N'CharacterImport',
            N'LocationReview',
            N'LocationImport',
            N'Complete'
        ));
END;
GO
