Deployment modifications

This commit is contained in:
nick 2026-09-12 19:40:13 +01:00
parent d4c421a836
commit 1f5216c29f
8 changed files with 232 additions and 12 deletions

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<key id="49c1e5c2-21a2-4a05-8080-08fa2b0dd614" version="1">
<creationDate>2026-09-12T18:32:05.1596463Z</creationDate>
<activationDate>2026-09-12T18:32:05.1596463Z</activationDate>
<expirationDate>2026-12-11T18:32:05.1596463Z</expirationDate>
<descriptor deserializerType="Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
<descriptor>
<encryption algorithm="AES_256_CBC" />
<validation algorithm="HMACSHA256" />
<masterKey p4:requiresEncryption="true" xmlns:p4="http://schemas.asp.net/2015/03/dataProtection">
<!-- Warning: the key below is in an unencrypted form. -->
<value>7wzHKkUnWgH96NmDXrAbiYoKOD0O5wQ18zR38r7ouCpJrN2EP3p8cE5JPO7nqaScKovUoH/iRzophulwPFgm2A==</value>
</masterKey>
</descriptor>
</descriptor>
</key>

View File

@ -6,6 +6,9 @@ demand-generated character illustrations produced before template 21J.3 so the
admin can deliberately regenerate them with the corrected art direction.
*/
SET QUOTED_IDENTIFIER ON;
GO
UPDATE dbo.IllustrationLibraryItems
SET MetadataJson = JSON_MODIFY(
JSON_MODIFY(

View File

@ -6,6 +6,9 @@ validate and safely invalidate illustration assignments. Existing rows remain
active and are backfilled with conservative defaults.
*/
SET QUOTED_IDENTIFIER ON;
GO
IF COL_LENGTH(N'dbo.StoryIntelligenceCharacterIllustrationAssignments', N'ImportSessionID') IS NULL
ALTER TABLE dbo.StoryIntelligenceCharacterIllustrationAssignments ADD ImportSessionID int NULL;

View File

@ -33,18 +33,6 @@ IF OBJECT_ID(N'dbo.SceneManuscriptSources', N'U') IS NOT NULL
THROW 52010, 'Scene manuscript source hard-delete cascade was not applied.', 1;
GO
IF OBJECT_ID(N'dbo.ManuscriptStructuralChapterSources', N'U') IS NOT NULL
AND NOT EXISTS
(
SELECT 1
FROM sys.foreign_keys
WHERE name = N'FK_ManuscriptStructuralChapterSources_Chapters'
AND parent_object_id = OBJECT_ID(N'dbo.ManuscriptStructuralChapterSources')
AND delete_referential_action_desc = N'CASCADE'
)
THROW 52011, 'Structural chapter source hard-delete cascade was not applied.', 1;
GO
IF OBJECT_ID(N'dbo.ManuscriptStructuralChapterSources', N'U') IS NOT NULL
AND EXISTS
(
@ -62,3 +50,15 @@ BEGIN
FOREIGN KEY (ChapterID) REFERENCES dbo.Chapters(ChapterID) ON DELETE CASCADE;
END;
GO
IF OBJECT_ID(N'dbo.ManuscriptStructuralChapterSources', N'U') IS NOT NULL
AND NOT EXISTS
(
SELECT 1
FROM sys.foreign_keys
WHERE name = N'FK_ManuscriptStructuralChapterSources_Chapters'
AND parent_object_id = OBJECT_ID(N'dbo.ManuscriptStructuralChapterSources')
AND delete_referential_action_desc = N'CASCADE'
)
THROW 52011, 'Structural chapter source hard-delete cascade was not applied.', 1;
GO

View File

@ -1,3 +1,8 @@
SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO
IF OBJECT_ID(N'dbo.StoryIntelligenceReviewCandidateGenerations', N'U') IS NULL
BEGIN
CREATE TABLE dbo.StoryIntelligenceReviewCandidateGenerations

View File

@ -1,4 +1,8 @@
-- Reuse canonical relationships and events. Existing author data is not rewritten.
SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO
SET XACT_ABORT ON;
GO
IF COL_LENGTH('dbo.RelationshipEvents','SourceReviewKey') IS NULL

View File

@ -0,0 +1,131 @@
SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO
/*
Remove obsolete dependency from the development reset procedure.
The old visualisation assignment table was intentionally dropped by script 150.
*/
CREATE OR ALTER PROCEDURE dbo.StoryIntelligence_DevelopmentAccountReset
@DevelopmentEmail nvarchar(256)
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;
DECLARE @UserID int;
SELECT @UserID = UserID
FROM dbo.AppUser
WHERE Email = @DevelopmentEmail;
IF @UserID IS NULL
THROW 52101, 'Development account email was not found.', 1;
DECLARE @ProjectIDs TABLE (ProjectID int NOT NULL PRIMARY KEY);
INSERT @ProjectIDs (ProjectID)
SELECT DISTINCT p.ProjectID
FROM dbo.Projects p
INNER JOIN dbo.ProjectUserAccess pua ON pua.ProjectID = p.ProjectID
WHERE pua.UserID = @UserID
AND pua.AccessRole = N'Owner'
AND pua.IsActive = 1;
DECLARE @DeletedProjects table (ProjectID int NOT NULL PRIMARY KEY, ProjectName nvarchar(200) NULL);
INSERT @DeletedProjects(ProjectID, ProjectName)
SELECT p.ProjectID, p.ProjectName
FROM dbo.Projects p
INNER JOIN @ProjectIDs ids ON ids.ProjectID = p.ProjectID;
BEGIN TRY
BEGIN TRANSACTION;
UPDATE dbo.StoryIntelligenceRuns
SET Status = CASE WHEN Status IN (N'Pending', N'Running') THEN N'Cancelled' ELSE Status END,
CurrentStage = N'Cancelled by Phase 21U reset',
CurrentMessage = N'Development reset invalidated this run.',
CompletedUtc = COALESCE(CompletedUtc, SYSUTCDATETIME()),
UpdatedUtc = SYSUTCDATETIME()
WHERE ProjectID IN (SELECT ProjectID FROM @ProjectIDs)
AND Status IN (N'Pending', N'Running');
UPDATE dbo.IllustrationLibraryItems
SET Status = CASE WHEN Status IN (N'Queued', N'Generating') THEN N'Failed' ELSE Status END,
LastError = N'Invalidated by Phase 21U development reset',
UpdatedUtc = SYSUTCDATETIME()
WHERE Category IN (N'Character', N'Location', N'Asset')
AND Status IN (N'Queued', N'Generating');
DELETE FROM dbo.StoryMemoryIllustrationAssignments;
DELETE FROM dbo.StoryMemoryIllustrationDemands;
DELETE FROM dbo.StoryMemoryRelationships;
DELETE FROM dbo.StoryMemoryCharacterAttributes;
DELETE FROM dbo.StoryMemoryCharacterAliases;
DELETE FROM dbo.StoryMemoryAssets;
DELETE FROM dbo.StoryMemoryLocations;
DELETE FROM dbo.StoryMemoryCharacters;
DELETE FROM dbo.StoryMemoryProcessedSceneResults;
DELETE FROM dbo.StoryMemoryImportPreferences;
DELETE FROM dbo.StoryIntelligenceIllustrationDemands;
IF OBJECT_ID(N'dbo.IllustrationGenerationAttempts', N'U') IS NOT NULL
DELETE FROM dbo.IllustrationGenerationAttempts;
IF OBJECT_ID(N'dbo.IllustrationLibraryApprovalHistory', N'U') IS NOT NULL
DELETE FROM dbo.IllustrationLibraryApprovalHistory;
IF OBJECT_ID(N'dbo.IllustrationLibraryLineage', N'U') IS NOT NULL
DELETE FROM dbo.IllustrationLibraryLineage;
UPDATE dbo.IllustrationLibraryItems
SET ParentItemID = NULL
WHERE Category IN (N'Character', N'Location', N'Asset');
DELETE FROM dbo.IllustrationLibraryItems
WHERE Category IN (N'Character', N'Location', N'Asset');
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
IF XACT_STATE() <> 0 ROLLBACK TRANSACTION;
THROW;
END CATCH;
DECLARE @ProjectID int;
DECLARE project_cursor CURSOR LOCAL FAST_FORWARD FOR
SELECT ProjectID FROM @ProjectIDs ORDER BY ProjectID;
OPEN project_cursor;
FETCH NEXT FROM project_cursor INTO @ProjectID;
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE dbo.Projects
SET IsArchived = 1,
ArchivedDate = COALESCE(ArchivedDate, SYSUTCDATETIME()),
ArchivedReason = N'Phase 21U development reset'
WHERE ProjectID = @ProjectID;
EXEC dbo.ProjectHardDelete_ForOwner @ProjectID = @ProjectID, @UserID = @UserID;
FETCH NEXT FROM project_cursor INTO @ProjectID;
END
CLOSE project_cursor;
DEALLOCATE project_cursor;
SELECT N'ProjectsDeleted' AS Metric, COUNT(*) AS Value FROM @DeletedProjects
UNION ALL SELECT N'RemainingOwnedProjects', COUNT(*)
FROM dbo.Projects p
INNER JOIN dbo.ProjectUserAccess pua ON pua.ProjectID = p.ProjectID
WHERE pua.UserID = @UserID AND pua.IsActive = 1
UNION ALL SELECT N'RemainingStoryIntelligenceRuns', COUNT(*)
FROM dbo.StoryIntelligenceRuns
WHERE UserID = @UserID
UNION ALL SELECT N'RemainingIllustrationLibraryItems', COUNT(*)
FROM dbo.IllustrationLibraryItems
WHERE Category IN (N'Character', N'Location', N'Asset');
SELECT ProjectID, ProjectName
FROM @DeletedProjects
ORDER BY ProjectID;
END;
GO

View File

@ -0,0 +1,58 @@
SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO
CREATE OR ALTER PROCEDURE dbo.CharacterEnrichmentRun_ClaimNext
@LeaseMinutes int = 90
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;
DECLARE @RunID int;
BEGIN TRANSACTION;
SELECT TOP (1) @RunID = CharacterEnrichmentRunID
FROM dbo.CharacterEnrichmentRuns WITH (UPDLOCK, HOLDLOCK)
WHERE IsCurrent = 1
AND (
Status = N'Queued'
OR (Status = N'Running' AND StartedUtc < DATEADD(minute, -ABS(@LeaseMinutes), SYSUTCDATETIME()))
)
ORDER BY QueuedUtc, CharacterEnrichmentRunID;
IF @RunID IS NULL
BEGIN
COMMIT TRANSACTION;
SELECT TOP (0) * FROM dbo.CharacterEnrichmentRuns;
RETURN;
END;
UPDATE dbo.CharacterEnrichmentRuns
SET Status = N'Running',
StartedUtc = SYSUTCDATETIME(),
AttemptCount = AttemptCount + 1,
CurrentStage = N'Preparing character analysis',
CurrentMessage = N'Preparing character analysis...',
UpdatedUtc = SYSUTCDATETIME()
WHERE CharacterEnrichmentRunID = @RunID
AND IsCurrent = 1
AND (
Status = N'Queued'
OR (Status = N'Running' AND StartedUtc < DATEADD(minute, -ABS(@LeaseMinutes), SYSUTCDATETIME()))
);
IF @@ROWCOUNT = 0
BEGIN
COMMIT TRANSACTION;
SELECT TOP (0) * FROM dbo.CharacterEnrichmentRuns;
RETURN;
END;
SELECT * FROM dbo.CharacterEnrichmentRuns WHERE CharacterEnrichmentRunID = @RunID;
COMMIT TRANSACTION;
END;
GO