SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'IX_Scenes_FloorPlanID' AND object_id = OBJECT_ID(N'dbo.Scenes'))
    CREATE INDEX IX_Scenes_FloorPlanID ON dbo.Scenes(FloorPlanID, IsArchived, ChapterID, SceneNumber, SortOrder)
    INCLUDE (SceneTitle, InitialFloorPlanFloorID);
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'IX_Scenes_InitialFloorPlanFloorID' AND object_id = OBJECT_ID(N'dbo.Scenes'))
    CREATE INDEX IX_Scenes_InitialFloorPlanFloorID ON dbo.Scenes(InitialFloorPlanFloorID)
    WHERE InitialFloorPlanFloorID IS NOT NULL;
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'IX_SceneFloorPlanOccupancy_FloorPlanID' AND object_id = OBJECT_ID(N'dbo.SceneFloorPlanOccupancy'))
    CREATE INDEX IX_SceneFloorPlanOccupancy_FloorPlanID ON dbo.SceneFloorPlanOccupancy(FloorPlanID, SceneID, LocationID)
    INCLUDE (FloorPlanFloorID, CharacterID, StoryAssetID);
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'IX_SceneFloorPlanOccupancy_LocationID' AND object_id = OBJECT_ID(N'dbo.SceneFloorPlanOccupancy'))
    CREATE INDEX IX_SceneFloorPlanOccupancy_LocationID ON dbo.SceneFloorPlanOccupancy(LocationID)
    INCLUDE (SceneID, FloorPlanID, FloorPlanFloorID, CharacterID, StoryAssetID);
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'IX_SceneFloorPlanOccupancy_CharacterID' AND object_id = OBJECT_ID(N'dbo.SceneFloorPlanOccupancy'))
    CREATE INDEX IX_SceneFloorPlanOccupancy_CharacterID ON dbo.SceneFloorPlanOccupancy(CharacterID)
    INCLUDE (SceneID, FloorPlanID, LocationID)
    WHERE CharacterID IS NOT NULL;
GO

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'IX_SceneFloorPlanOccupancy_StoryAssetID' AND object_id = OBJECT_ID(N'dbo.SceneFloorPlanOccupancy'))
    CREATE INDEX IX_SceneFloorPlanOccupancy_StoryAssetID ON dbo.SceneFloorPlanOccupancy(StoryAssetID)
    INCLUDE (SceneID, FloorPlanID, LocationID)
    WHERE StoryAssetID IS NOT NULL;
GO
