Retain explicit Word Companion scene associations during backup and restore
This commit is contained in:
parent
6ae371558b
commit
571f670c0d
@ -161,8 +161,8 @@ ValidationRuns,ProjectID or FK descendant,ValidationRuns,Serialized persistent s
|
|||||||
WarningSeverities,Global/user/independent,,Reference/user/system; scope review pending,Pending,Pending
|
WarningSeverities,Global/user/independent,,Reference/user/system; scope review pending,Pending,Pending
|
||||||
WarningTypes,Global/user/independent,,Reference/user/system; scope review pending,Pending,Pending
|
WarningTypes,Global/user/independent,,Reference/user/system; scope review pending,Pending,Pending
|
||||||
WholeBookPlotSynthesisRuns,ProjectID or FK descendant,,Pending classification,Pending,Pending
|
WholeBookPlotSynthesisRuns,ProjectID or FK descendant,,Pending classification,Pending,Pending
|
||||||
WordCompanionSceneAssets,ProjectID or FK descendant,,Pending classification,Pending,Pending
|
WordCompanionSceneAssets,ProjectID or FK descendant,WordCompanionSceneAssets,Version 1.2 additive explicit Word associations; populated SQL stored-value round trip passed,Copy/in-place/safety/SQL rollback passed,Entity associations; file bytes not applicable
|
||||||
WordCompanionSceneLocations,ProjectID or FK descendant,,Pending classification,Pending,Pending
|
WordCompanionSceneLocations,ProjectID or FK descendant,WordCompanionSceneLocations,Version 1.2 additive explicit Word associations; populated SQL stored-value round trip passed,Copy/in-place/safety/SQL rollback passed,Entity associations; file bytes not applicable
|
||||||
WritingPlans,ProjectID or FK descendant,WritingPlans,Serialized persistent set; populated SQL projection and stored-value copy/in-place comparisons passed,Pass: source SQL fields; copy references/actors; in-place restore; SQL failure rollback,External file bytes not covered; embedded/text/JSON values compared where populated
|
WritingPlans,ProjectID or FK descendant,WritingPlans,Serialized persistent set; populated SQL projection and stored-value copy/in-place comparisons passed,Pass: source SQL fields; copy references/actors; in-place restore; SQL failure rollback,External file bytes not covered; embedded/text/JSON values compared where populated
|
||||||
WritingScheduleItems,ProjectID or FK descendant,WritingScheduleItems,Serialized persistent set; populated SQL projection and stored-value copy/in-place comparisons passed,Pass: source SQL fields; copy references/actors; in-place restore; SQL failure rollback,External file bytes not covered; embedded/text/JSON values compared where populated
|
WritingScheduleItems,ProjectID or FK descendant,WritingScheduleItems,Serialized persistent set; populated SQL projection and stored-value copy/in-place comparisons passed,Pass: source SQL fields; copy references/actors; in-place restore; SQL failure rollback,External file bytes not covered; embedded/text/JSON values compared where populated
|
||||||
WritingSolverVersions,Global/user/independent,,Account/billing/system execution state; excluded from portable project backup,Pending,Pending
|
WritingSolverVersions,Global/user/independent,,Account/billing/system execution state; excluded from portable project backup,Pending,Pending
|
||||||
|
|||||||
|
@ -790,6 +790,16 @@ ValidationRuns,ValidationRuns,StartedDate,datetime2,False,False,True,Represented
|
|||||||
ValidationRuns,ValidationRuns,CompletedDate,datetime2,True,False,True,Represented; projection and semantic comparison still required
|
ValidationRuns,ValidationRuns,CompletedDate,datetime2,True,False,True,Represented; projection and semantic comparison still required
|
||||||
ValidationRuns,ValidationRuns,TriggeredBy,nvarchar,True,False,True,Represented; projection and semantic comparison still required
|
ValidationRuns,ValidationRuns,TriggeredBy,nvarchar,True,False,True,Represented; projection and semantic comparison still required
|
||||||
ValidationRuns,ValidationRuns,ScopeDescription,nvarchar,True,False,True,Represented; projection and semantic comparison still required
|
ValidationRuns,ValidationRuns,ScopeDescription,nvarchar,True,False,True,Represented; projection and semantic comparison still required
|
||||||
|
WordCompanionSceneAssets,WordCompanionSceneAssets,WordCompanionSceneAssetID,int,False,False,True,Represented; projection and semantic comparison still required
|
||||||
|
WordCompanionSceneAssets,WordCompanionSceneAssets,SceneID,int,False,False,True,Represented; projection and semantic comparison still required
|
||||||
|
WordCompanionSceneAssets,WordCompanionSceneAssets,StoryAssetID,int,False,False,True,Represented; projection and semantic comparison still required
|
||||||
|
WordCompanionSceneAssets,WordCompanionSceneAssets,CreatedDate,datetime2,False,False,True,Represented; projection and semantic comparison still required
|
||||||
|
WordCompanionSceneAssets,WordCompanionSceneAssets,UpdatedDate,datetime2,False,False,True,Represented; projection and semantic comparison still required
|
||||||
|
WordCompanionSceneLocations,WordCompanionSceneLocations,WordCompanionSceneLocationID,int,False,False,True,Represented; projection and semantic comparison still required
|
||||||
|
WordCompanionSceneLocations,WordCompanionSceneLocations,SceneID,int,False,False,True,Represented; projection and semantic comparison still required
|
||||||
|
WordCompanionSceneLocations,WordCompanionSceneLocations,LocationID,int,False,False,True,Represented; projection and semantic comparison still required
|
||||||
|
WordCompanionSceneLocations,WordCompanionSceneLocations,CreatedDate,datetime2,False,False,True,Represented; projection and semantic comparison still required
|
||||||
|
WordCompanionSceneLocations,WordCompanionSceneLocations,UpdatedDate,datetime2,False,False,True,Represented; projection and semantic comparison still required
|
||||||
WritingPlans,WritingPlans,WritingPlanID,int,False,False,True,Represented; projection and semantic comparison still required
|
WritingPlans,WritingPlans,WritingPlanID,int,False,False,True,Represented; projection and semantic comparison still required
|
||||||
WritingPlans,WritingPlans,UserID,int,False,False,True,Represented; projection and semantic comparison still required
|
WritingPlans,WritingPlans,UserID,int,False,False,True,Represented; projection and semantic comparison still required
|
||||||
WritingPlans,WritingPlans,ProjectID,int,False,False,True,Represented; projection and semantic comparison still required
|
WritingPlans,WritingPlans,ProjectID,int,False,False,True,Represented; projection and semantic comparison still required
|
||||||
|
|||||||
|
@ -1,4 +1,6 @@
|
|||||||
Collection,SourceRows,CopyRows,InPlaceRows,Verification
|
Collection,SourceRows,CopyRows,InPlaceRows,Verification
|
||||||
|
WordCompanionSceneAssets,1,1,1,Stored field comparison passed; only populated values exercised; external file bytes excluded
|
||||||
|
WordCompanionSceneLocations,1,1,1,Stored field comparison passed; only populated values exercised; external file bytes excluded
|
||||||
ManuscriptDocuments,1,1,1,Stored field comparison passed; only populated values exercised; external file bytes excluded
|
ManuscriptDocuments,1,1,1,Stored field comparison passed; only populated values exercised; external file bytes excluded
|
||||||
SceneManuscriptSources,1,1,1,Stored field comparison passed; only populated values exercised; external file bytes excluded
|
SceneManuscriptSources,1,1,1,Stored field comparison passed; only populated values exercised; external file bytes excluded
|
||||||
ManuscriptStructuralChapterSources,1,1,1,Stored field comparison passed; only populated values exercised; external file bytes excluded
|
ManuscriptStructuralChapterSources,1,1,1,Stored field comparison passed; only populated values exercised; external file bytes excluded
|
||||||
|
|||||||
|
@ -153,3 +153,9 @@ Confirmed further export omissions: appearance detection provenance, character k
|
|||||||
Confirmed copied Timeline presets retained original focus/filter entity IDs. Copy now remaps their explicit and embedded references while preserving unrecognised filter properties; invalid/missing references fail preview before allocation. Expanded malformed preview matrix: 15 cases. Persisted event source keys, once correctly exported, exposed their global uniqueness constraint: importing a copy collided with the original event. Copies now receive project/event-specific source identities and detach original analysis references, with an explicit preview warning. In-place restore retains original provenance keys. No claim is made that unexported SI review history has been restored.
|
Confirmed copied Timeline presets retained original focus/filter entity IDs. Copy now remaps their explicit and embedded references while preserving unrecognised filter properties; invalid/missing references fail preview before allocation. Expanded malformed preview matrix: 15 cases. Persisted event source keys, once correctly exported, exposed their global uniqueness constraint: importing a copy collided with the original event. Copies now receive project/event-specific source identities and detach original analysis references, with an explicit preview warning. In-place restore retains original provenance keys. No claim is made that unexported SI review history has been restored.
|
||||||
|
|
||||||
Verification: latest isolated run `/tmp/plotdirector-phase2-transfer-planning.log` passed, including actual safety backups, constraint-failure rollback and cross-author boundaries. Build zero warnings/errors. Broader harness running before commit. Migration 215, like 213/214, has only been applied to the synthetic database; Development remains unchanged.
|
Verification: latest isolated run `/tmp/plotdirector-phase2-transfer-planning.log` passed, including actual safety backups, constraint-failure rollback and cross-author boundaries. Build zero warnings/errors. Broader harness running before commit. Migration 215, like 213/214, has only been applied to the synthetic database; Development remains unchanged.
|
||||||
|
|
||||||
|
### Explicit Word scene associations
|
||||||
|
|
||||||
|
Populating WordCompanionSceneAssets and WordCompanionSceneLocations reproduced a failed in-place restore before repair, while copied projects silently omitted these explicit selections. These tables are distinct from asset placement/location tables. Forward-only migration 216 and additive version-1.2 collections now export them, validate their graph references, remap copied identities/targets and restore them before constraint revalidation.
|
||||||
|
|
||||||
|
The isolated SQL matrix now passes 64 populated persistent collections: 980 source SQL values across 67 entities including diagnostic/root rows; 941 copy values; 944 in-place restore values. Safety backups, real constraint rollback and author boundaries passed again. Build zero warnings/errors. Evidence: `/tmp/plotdirector-phase2-transfer-companion-before.log` (failure), `/tmp/plotdirector-phase2-transfer-companion.log` (pass). The preceding 405-check harness passed at commit 6ae3715. Next: associated uploaded-file bytes and gallery records; remaining SI/review persistence and other import/export workflows. No Development writes or deployment.
|
||||||
|
|||||||
@ -86,3 +86,5 @@ UPDATE dbo.StoryMaps SET AppearanceJson=JSON_MODIFY(AppearanceJson,'$.extension'
|
|||||||
ReferenceJson=JSON_MODIFY(ReferenceJson,'$.extension',JSON_QUERY(N'{"source":"café"}')) WHERE MapID=@map;
|
ReferenceJson=JSON_MODIFY(ReferenceJson,'$.extension',JSON_QUERY(N'{"source":"café"}')) WHERE MapID=@map;
|
||||||
UPDATE dbo.Locations SET DetectionPriority=7,ExcludeFromCompanionDetection=1 WHERE LocationID=@otherLocation;
|
UPDATE dbo.Locations SET DetectionPriority=7,ExcludeFromCompanionDetection=1 WHERE LocationID=@otherLocation;
|
||||||
UPDATE dbo.ThreadEvents SET Source=N'Manual',SourceKey=CONCAT(N'synthetic-event-source-key-',@project),Confidence=.85 WHERE ThreadEventID=@threadEvent;
|
UPDATE dbo.ThreadEvents SET Source=N'Manual',SourceKey=CONCAT(N'synthetic-event-source-key-',@project),Confidence=.85 WHERE ThreadEventID=@threadEvent;
|
||||||
|
INSERT dbo.WordCompanionSceneAssets(SceneID,StoryAssetID) VALUES(@scene,@asset);
|
||||||
|
INSERT dbo.WordCompanionSceneLocations(SceneID,LocationID) VALUES(@scene,@otherLocation);
|
||||||
|
|||||||
@ -43,7 +43,7 @@ internal static class ProjectTransferDatabaseTests
|
|||||||
}
|
}
|
||||||
if(applyMigrations)
|
if(applyMigrations)
|
||||||
{
|
{
|
||||||
foreach(var file in new[]{"PlotLine/Sql/213_ProjectBackupBookContext.sql","PlotLine/Sql/214_ProjectBackupPersistentSourceState.sql","PlotLine/Sql/215_ProjectBackupMapStoredMetadata.sql"})
|
foreach(var file in new[]{"PlotLine/Sql/213_ProjectBackupBookContext.sql","PlotLine/Sql/214_ProjectBackupPersistentSourceState.sql","PlotLine/Sql/215_ProjectBackupMapStoredMetadata.sql","PlotLine/Sql/216_ProjectBackupCompanionSceneLinks.sql"})
|
||||||
foreach(var batch in System.Text.RegularExpressions.Regex.Split(await File.ReadAllTextAsync(file), @"^\s*GO\s*$", System.Text.RegularExpressions.RegexOptions.Multiline | System.Text.RegularExpressions.RegexOptions.IgnoreCase))
|
foreach(var batch in System.Text.RegularExpressions.Regex.Split(await File.ReadAllTextAsync(file), @"^\s*GO\s*$", System.Text.RegularExpressions.RegexOptions.Multiline | System.Text.RegularExpressions.RegexOptions.IgnoreCase))
|
||||||
if(!string.IsNullOrWhiteSpace(batch)) await db.ExecuteAsync(batch,commandTimeout:180);
|
if(!string.IsNullOrWhiteSpace(batch)) await db.ExecuteAsync(batch,commandTimeout:180);
|
||||||
Console.WriteLine("Applied required migrations to the verified synthetic database only.");
|
Console.WriteLine("Applied required migrations to the verified synthetic database only.");
|
||||||
@ -257,7 +257,7 @@ internal static class ProjectTransferDatabaseTests
|
|||||||
coverage.Add($"{property.Name},{Count(before)},{Count(after)},{Count(sameProject)},{(diagnostic?"Diagnostic/shared vocabulary; excluded from portable restoration comparison":"Stored field comparison passed; only populated values exercised; external file bytes excluded")}");
|
coverage.Add($"{property.Name},{Count(before)},{Count(after)},{Count(sameProject)},{(diagnostic?"Diagnostic/shared vocabulary; excluded from portable restoration comparison":"Stored field comparison passed; only populated values exercised; external file bytes excluded")}");
|
||||||
}
|
}
|
||||||
await File.WriteAllLinesAsync("Docs/Sprints/2026-11-03-phase2-roundtrip-coverage.csv",coverage);
|
await File.WriteAllLinesAsync("Docs/Sprints/2026-11-03-phase2-roundtrip-coverage.csv",coverage);
|
||||||
Console.WriteLine("PASS 62 populated persistent collections: copy/in-place stored values and actual safety/rollback; unrepresented tables and external file bytes remain pending.");
|
Console.WriteLine("PASS 64 populated persistent collections: copy/in-place stored values and actual safety/rollback; unrepresented tables and external file bytes remain pending.");
|
||||||
}
|
}
|
||||||
private static async Task VerifyStoredRoundTripAsync(SqlConnection db, ProjectBackupExport original, ProjectBackupExport restored, int? importingUser)
|
private static async Task VerifyStoredRoundTripAsync(SqlConnection db, ProjectBackupExport original, ProjectBackupExport restored, int? importingUser)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -102,6 +102,8 @@ public sealed class ProjectBackupRepository(ISqlConnectionFactory connectionFact
|
|||||||
data.AuthorPlotSeeds = (await state.ReadAsync<AuthorPlotSeed>()).ToList();
|
data.AuthorPlotSeeds = (await state.ReadAsync<AuthorPlotSeed>()).ToList();
|
||||||
data.ContinuityWarningAcknowledgements = (await state.ReadAsync<ContinuityWarningAcknowledgement>()).ToList();
|
data.ContinuityWarningAcknowledgements = (await state.ReadAsync<ContinuityWarningAcknowledgement>()).ToList();
|
||||||
data.PlotEventTargetPlotLines = (await state.ReadAsync<ProjectBackupPlotEventTarget>()).ToList();
|
data.PlotEventTargetPlotLines = (await state.ReadAsync<ProjectBackupPlotEventTarget>()).ToList();
|
||||||
|
data.WordCompanionSceneAssets = (await state.ReadAsync<ProjectBackupCompanionSceneAsset>()).ToList();
|
||||||
|
data.WordCompanionSceneLocations = (await state.ReadAsync<ProjectBackupCompanionSceneLocation>()).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
var bookMetadata = (await connection.QueryAsync<Book>(
|
var bookMetadata = (await connection.QueryAsync<Book>(
|
||||||
@ -140,6 +142,8 @@ public sealed class ProjectBackupRepository(ISqlConnectionFactory connectionFact
|
|||||||
ProjectId = projectId,
|
ProjectId = projectId,
|
||||||
IncludedEntitySets =
|
IncludedEntitySets =
|
||||||
[
|
[
|
||||||
|
nameof(data.WordCompanionSceneAssets),
|
||||||
|
nameof(data.WordCompanionSceneLocations),
|
||||||
nameof(data.ManuscriptDocuments),
|
nameof(data.ManuscriptDocuments),
|
||||||
nameof(data.SceneManuscriptSources),
|
nameof(data.SceneManuscriptSources),
|
||||||
nameof(data.ManuscriptStructuralChapterSources),
|
nameof(data.ManuscriptStructuralChapterSources),
|
||||||
|
|||||||
@ -13,6 +13,8 @@ public sealed class ProjectBackupExport
|
|||||||
|
|
||||||
public sealed class ProjectBackupData
|
public sealed class ProjectBackupData
|
||||||
{
|
{
|
||||||
|
public IReadOnlyList<ProjectBackupCompanionSceneAsset> WordCompanionSceneAssets { get; set; } = [];
|
||||||
|
public IReadOnlyList<ProjectBackupCompanionSceneLocation> WordCompanionSceneLocations { get; set; } = [];
|
||||||
public IReadOnlyList<ManuscriptDocumentModel> ManuscriptDocuments { get; set; } = [];
|
public IReadOnlyList<ManuscriptDocumentModel> ManuscriptDocuments { get; set; } = [];
|
||||||
public IReadOnlyList<ProjectBackupSceneManuscriptSource> SceneManuscriptSources { get; set; } = [];
|
public IReadOnlyList<ProjectBackupSceneManuscriptSource> SceneManuscriptSources { get; set; } = [];
|
||||||
public IReadOnlyList<ProjectBackupStructuralChapterSource> ManuscriptStructuralChapterSources { get; set; } = [];
|
public IReadOnlyList<ProjectBackupStructuralChapterSource> ManuscriptStructuralChapterSources { get; set; } = [];
|
||||||
@ -222,3 +224,20 @@ public sealed class ProjectBackupPlotEventTarget
|
|||||||
public int PlotLineID { get; set; }
|
public int PlotLineID { get; set; }
|
||||||
public DateTime CreatedDate { get; set; }
|
public DateTime CreatedDate { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sealed class ProjectBackupCompanionSceneAsset
|
||||||
|
{
|
||||||
|
public int WordCompanionSceneAssetID { get; set; }
|
||||||
|
public int SceneID { get; set; }
|
||||||
|
public int StoryAssetID { get; set; }
|
||||||
|
public DateTime CreatedDate { get; set; }
|
||||||
|
public DateTime UpdatedDate { get; set; }
|
||||||
|
}
|
||||||
|
public sealed class ProjectBackupCompanionSceneLocation
|
||||||
|
{
|
||||||
|
public int WordCompanionSceneLocationID { get; set; }
|
||||||
|
public int SceneID { get; set; }
|
||||||
|
public int LocationID { get; set; }
|
||||||
|
public DateTime CreatedDate { get; set; }
|
||||||
|
public DateTime UpdatedDate { get; set; }
|
||||||
|
}
|
||||||
|
|||||||
@ -807,7 +807,7 @@ public sealed class ImportService(IImportRepository imports, ICurrentUserService
|
|||||||
private static readonly string[] ProjectBackupIdentityTables =
|
private static readonly string[] ProjectBackupIdentityTables =
|
||||||
[
|
[
|
||||||
"ProjectTimelineSettings", "TimelineViewPresets", "SceneMetricTypes", "Books", "Chapters", "Scenes", "StoryMaps",
|
"ProjectTimelineSettings", "TimelineViewPresets", "SceneMetricTypes", "Books", "Chapters", "Scenes", "StoryMaps",
|
||||||
"ManuscriptDocuments", "WritingPlans", "WritingScheduleItems", "CharacterAliases", "AssetAliases", "LocationAliases", "AuthorPlotSeeds", "ContinuityWarningAcknowledgements",
|
"WordCompanionSceneAssets", "WordCompanionSceneLocations", "ManuscriptDocuments", "WritingPlans", "WritingScheduleItems", "CharacterAliases", "AssetAliases", "LocationAliases", "AuthorPlotSeeds", "ContinuityWarningAcknowledgements",
|
||||||
"SceneOutcomes", "PlotLines", "PlotThreads", "ThreadEvents", "AssetStates", "StoryAssets", "AssetEvents",
|
"SceneOutcomes", "PlotLines", "PlotThreads", "ThreadEvents", "AssetStates", "StoryAssets", "AssetEvents",
|
||||||
"AssetDependencies", "AssetCustodyEvents", "AssetCustodyEventCharacters", "Characters", "SceneCharacters",
|
"AssetDependencies", "AssetCustodyEvents", "AssetCustodyEventCharacters", "Characters", "SceneCharacters",
|
||||||
"CharacterAttributeTypes", "CharacterAttributeEvents", "CharacterKnowledge", "CharacterRelationships",
|
"CharacterAttributeTypes", "CharacterAttributeEvents", "CharacterKnowledge", "CharacterRelationships",
|
||||||
@ -1492,6 +1492,18 @@ public sealed class ImportService(IImportRepository imports, ICurrentUserService
|
|||||||
note.FromSceneID = ExistingOrNew("Scenes", note.FromSceneID);
|
note.FromSceneID = ExistingOrNew("Scenes", note.FromSceneID);
|
||||||
note.ToSceneID = ExistingOrNew("Scenes", note.ToSceneID);
|
note.ToSceneID = ExistingOrNew("Scenes", note.ToSceneID);
|
||||||
}
|
}
|
||||||
|
foreach (var link in backup.Data.WordCompanionSceneAssets)
|
||||||
|
{
|
||||||
|
link.WordCompanionSceneAssetID=NewId("WordCompanionSceneAssets",link.WordCompanionSceneAssetID);
|
||||||
|
link.SceneID=ExistingOrNew("Scenes",link.SceneID);
|
||||||
|
link.StoryAssetID=ExistingOrNew("StoryAssets",link.StoryAssetID);
|
||||||
|
}
|
||||||
|
foreach (var link in backup.Data.WordCompanionSceneLocations)
|
||||||
|
{
|
||||||
|
link.WordCompanionSceneLocationID=NewId("WordCompanionSceneLocations",link.WordCompanionSceneLocationID);
|
||||||
|
link.SceneID=ExistingOrNew("Scenes",link.SceneID);
|
||||||
|
link.LocationID=ExistingOrNew("Locations",link.LocationID);
|
||||||
|
}
|
||||||
foreach (var preset in backup.Data.TimelineViewPresets)
|
foreach (var preset in backup.Data.TimelineViewPresets)
|
||||||
ProjectBackupTimelineState.Remap(preset,projectId,ExistingOrNewNullable);
|
ProjectBackupTimelineState.Remap(preset,projectId,ExistingOrNewNullable);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,8 @@ internal static class ProjectBackupGraphValidation
|
|||||||
private sealed record Link(string Column, string TargetCollection, string TargetColumn);
|
private sealed record Link(string Column, string TargetCollection, string TargetColumn);
|
||||||
private sealed record Entity(string Collection, string? Identity, params Link[] Links);
|
private sealed record Entity(string Collection, string? Identity, params Link[] Links);
|
||||||
private static readonly Entity[] Entities = [
|
private static readonly Entity[] Entities = [
|
||||||
|
new("WordCompanionSceneAssets","WordCompanionSceneAssetID",new Link("SceneID","Scenes","SceneID"),new Link("StoryAssetID","StoryAssets","StoryAssetID")),
|
||||||
|
new("WordCompanionSceneLocations","WordCompanionSceneLocationID",new Link("SceneID","Scenes","SceneID"),new Link("LocationID","Locations","LocationID")),
|
||||||
new("AssetAliases", "AssetAliasID", new Link("StoryAssetID", "StoryAssets", "StoryAssetID")),
|
new("AssetAliases", "AssetAliasID", new Link("StoryAssetID", "StoryAssets", "StoryAssetID")),
|
||||||
new("AssetCustodyCharacters", "AssetCustodyEventCharacterID", new Link("AssetCustodyEventID", "AssetCustodyEvents", "AssetCustodyEventID"), new Link("CharacterID", "Characters", "CharacterID")),
|
new("AssetCustodyCharacters", "AssetCustodyEventCharacterID", new Link("AssetCustodyEventID", "AssetCustodyEvents", "AssetCustodyEventID"), new Link("CharacterID", "Characters", "CharacterID")),
|
||||||
new("AssetCustodyEvents", "AssetCustodyEventID", new Link("SceneID", "Scenes", "SceneID"), new Link("StoryAssetID", "StoryAssets", "StoryAssetID")),
|
new("AssetCustodyEvents", "AssetCustodyEventID", new Link("SceneID", "Scenes", "SceneID"), new Link("StoryAssetID", "StoryAssets", "StoryAssetID")),
|
||||||
|
|||||||
313
PlotLine/Sql/216_ProjectBackupCompanionSceneLinks.sql
Normal file
313
PlotLine/Sql/216_ProjectBackupCompanionSceneLinks.sql
Normal file
@ -0,0 +1,313 @@
|
|||||||
|
-- Retain explicit Word Companion scene associations, distinct from asset physical locations.
|
||||||
|
SET ANSI_NULLS ON;
|
||||||
|
SET QUOTED_IDENTIFIER ON;
|
||||||
|
GO
|
||||||
|
CREATE OR ALTER PROCEDURE dbo.ProjectBackup_PersistentState_List @ProjectID int
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
SELECT * FROM dbo.ManuscriptDocuments WHERE ProjectID=@ProjectID ORDER BY ManuscriptDocumentID;
|
||||||
|
SELECT * FROM dbo.SceneManuscriptSources WHERE ProjectID=@ProjectID ORDER BY SceneID;
|
||||||
|
SELECT * FROM dbo.ManuscriptStructuralChapterSources WHERE ProjectID=@ProjectID ORDER BY ChapterID;
|
||||||
|
SELECT * FROM dbo.WritingPlans WHERE ProjectID=@ProjectID ORDER BY WritingPlanID;
|
||||||
|
SELECT i.* FROM dbo.WritingScheduleItems i JOIN dbo.WritingPlans p ON p.WritingPlanID=i.WritingPlanID WHERE p.ProjectID=@ProjectID ORDER BY i.WritingScheduleItemID;
|
||||||
|
SELECT a.* FROM dbo.CharacterAliases a JOIN dbo.Characters c ON c.CharacterID=a.CharacterID WHERE c.ProjectID=@ProjectID ORDER BY a.CharacterAliasID;
|
||||||
|
SELECT a.* FROM dbo.AssetAliases a JOIN dbo.StoryAssets s ON s.StoryAssetID=a.StoryAssetID WHERE s.ProjectID=@ProjectID ORDER BY a.AssetAliasID;
|
||||||
|
SELECT a.* FROM dbo.LocationAliases a JOIN dbo.Locations l ON l.LocationID=a.LocationID WHERE l.ProjectID=@ProjectID ORDER BY a.LocationAliasID;
|
||||||
|
SELECT * FROM dbo.AuthorPlotSeeds WHERE ProjectID=@ProjectID ORDER BY AuthorPlotSeedID;
|
||||||
|
SELECT * FROM dbo.ContinuityWarningAcknowledgements WHERE ProjectID=@ProjectID ORDER BY ContinuityWarningAcknowledgementID;
|
||||||
|
SELECT x.* FROM dbo.PlotEventTargetPlotLines x JOIN dbo.ThreadEvents e ON e.ThreadEventID=x.PlotEventID JOIN dbo.PlotThreads t ON t.PlotThreadID=e.PlotThreadID JOIN dbo.PlotLines p ON p.PlotLineID=t.PlotLineID WHERE p.ProjectID=@ProjectID ORDER BY x.PlotEventID,x.PlotLineID;
|
||||||
|
SELECT x.* FROM dbo.WordCompanionSceneAssets x JOIN dbo.Scenes s ON s.SceneID=x.SceneID JOIN dbo.Chapters c ON c.ChapterID=s.ChapterID JOIN dbo.Books b ON b.BookID=c.BookID WHERE b.ProjectID=@ProjectID ORDER BY x.WordCompanionSceneAssetID;
|
||||||
|
SELECT x.* FROM dbo.WordCompanionSceneLocations x JOIN dbo.Scenes s ON s.SceneID=x.SceneID JOIN dbo.Chapters c ON c.ChapterID=s.ChapterID JOIN dbo.Books b ON b.BookID=c.BookID WHERE b.ProjectID=@ProjectID ORDER BY x.WordCompanionSceneLocationID;
|
||||||
|
|
||||||
|
END;
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE OR ALTER PROCEDURE dbo.ProjectRestore_ApplyFromJson
|
||||||
|
@ProjectID int,
|
||||||
|
@SourceRestorePointID int = NULL,
|
||||||
|
@SafetyRestorePointID int = NULL,
|
||||||
|
@JsonData nvarchar(max)
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
SET XACT_ABORT ON;
|
||||||
|
|
||||||
|
IF ISNULL(ISJSON(@JsonData), 0) <> 1
|
||||||
|
THROW 51001, 'Restore JSON is invalid.', 1;
|
||||||
|
|
||||||
|
IF ISNULL(JSON_VALUE(@JsonData, '$.Format'), N'') <> N'PlotDirector.ProjectBackup'
|
||||||
|
THROW 51002, 'Restore JSON format is not recognised.', 1;
|
||||||
|
|
||||||
|
IF ISNULL(JSON_VALUE(@JsonData, '$.FormatVersion'), N'') NOT IN (N'1.0', N'1.1', N'1.2')
|
||||||
|
THROW 51003, 'Restore JSON format version is not supported.', 1;
|
||||||
|
|
||||||
|
IF ISNULL(@ProjectID,0)<=0 OR ISNULL(TRY_CONVERT(int, JSON_VALUE(@JsonData, '$.Project.ProjectID')),-1) <> @ProjectID
|
||||||
|
THROW 51004, 'Restore point does not belong to this project.', 1;
|
||||||
|
|
||||||
|
DECLARE @RestoreTables table (TableName sysname NOT NULL PRIMARY KEY);
|
||||||
|
INSERT INTO @RestoreTables (TableName)
|
||||||
|
VALUES
|
||||||
|
(N'WordCompanionSceneAssets'), (N'WordCompanionSceneLocations'), (N'ManuscriptDocuments'), (N'SceneManuscriptSources'), (N'ManuscriptStructuralChapterSources'), (N'WritingPlans'), (N'WritingScheduleItems'), (N'CharacterAliases'), (N'AssetAliases'), (N'LocationAliases'), (N'AuthorPlotSeeds'), (N'ContinuityWarningAcknowledgements'), (N'PlotEventTargetPlotLines'),
|
||||||
|
(N'ProjectTimelineSettings'), (N'ProjectTimelineMetricSettings'), (N'TimelineViewPresets'),
|
||||||
|
(N'SceneMetricTypes'), (N'SceneMetricValues'), (N'Books'), (N'Chapters'), (N'Scenes'),
|
||||||
|
(N'ScenePurposes'), (N'SceneOutcomes'), (N'PlotLines'), (N'PlotThreads'), (N'ThreadEvents'),
|
||||||
|
(N'AssetStates'), (N'StoryAssets'), (N'AssetEvents'), (N'AssetDependencies'),
|
||||||
|
(N'AssetCustodyEvents'), (N'AssetCustodyEventCharacters'), (N'Characters'), (N'SceneCharacters'),
|
||||||
|
(N'CharacterAttributeTypes'), (N'CharacterAttributeEvents'), (N'CharacterKnowledge'),
|
||||||
|
(N'CharacterRelationships'), (N'RelationshipEvents'), (N'Locations'), (N'LocationRelationships'),
|
||||||
|
(N'MapReferenceImages'), (N'StoryMaps'), (N'MapFeatures'), (N'MapRelationships'), (N'MapJourneyNotes'),
|
||||||
|
(N'FloorPlans'), (N'FloorPlanFloors'), (N'FloorPlanBlocks'), (N'FloorPlanTransitions'),
|
||||||
|
(N'SceneAssetLocations'), (N'SceneFloorPlanOccupancy'), (N'SceneDependencies'), (N'ValidationRuns'), (N'ContinuityWarnings'),
|
||||||
|
(N'SceneNotes'), (N'SceneWorkflow'), (N'SceneChecklistItems'), (N'SceneAttachments'),
|
||||||
|
(N'ChapterGoals'), (N'Scenarios'), (N'ScenarioSceneOrder'), (N'ScenarioValidationRuns'),
|
||||||
|
(N'ScenarioWarnings');
|
||||||
|
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
DECLARE @PreviousMapRevision int = ISNULL((SELECT MAX(Revision) FROM dbo.StoryMaps WHERE ProjectID=@ProjectID),0);
|
||||||
|
|
||||||
|
|
||||||
|
DECLARE @TableName sysname;
|
||||||
|
DECLARE DisableCursor CURSOR LOCAL FAST_FORWARD FOR SELECT TableName FROM @RestoreTables;
|
||||||
|
OPEN DisableCursor;
|
||||||
|
FETCH NEXT FROM DisableCursor INTO @TableName;
|
||||||
|
WHILE @@FETCH_STATUS = 0
|
||||||
|
BEGIN
|
||||||
|
DECLARE @DisableSql nvarchar(max) = N'ALTER TABLE dbo.' + QUOTENAME(@TableName) + N' NOCHECK CONSTRAINT ALL;';
|
||||||
|
EXEC (@DisableSql);
|
||||||
|
FETCH NEXT FROM DisableCursor INTO @TableName;
|
||||||
|
END
|
||||||
|
CLOSE DisableCursor;
|
||||||
|
DEALLOCATE DisableCursor;
|
||||||
|
|
||||||
|
DELETE x FROM dbo.WordCompanionSceneAssets x JOIN dbo.Scenes s ON s.SceneID=x.SceneID JOIN dbo.Chapters c ON c.ChapterID=s.ChapterID JOIN dbo.Books b ON b.BookID=c.BookID WHERE b.ProjectID=@ProjectID;
|
||||||
|
DELETE x FROM dbo.WordCompanionSceneLocations x JOIN dbo.Scenes s ON s.SceneID=x.SceneID JOIN dbo.Chapters c ON c.ChapterID=s.ChapterID JOIN dbo.Books b ON b.BookID=c.BookID WHERE b.ProjectID=@ProjectID;
|
||||||
|
DELETE i FROM dbo.WritingScheduleItems i JOIN dbo.WritingPlans p ON p.WritingPlanID=i.WritingPlanID WHERE p.ProjectID=@ProjectID;
|
||||||
|
DELETE dbo.WritingPlans WHERE ProjectID=@ProjectID;
|
||||||
|
DELETE dbo.AuthorPlotSeeds WHERE ProjectID=@ProjectID;
|
||||||
|
DELETE dbo.ContinuityWarningAcknowledgements WHERE ProjectID=@ProjectID;
|
||||||
|
DELETE a FROM dbo.CharacterAliases a JOIN dbo.Characters c ON c.CharacterID=a.CharacterID WHERE c.ProjectID=@ProjectID;
|
||||||
|
DELETE a FROM dbo.AssetAliases a JOIN dbo.StoryAssets s ON s.StoryAssetID=a.StoryAssetID WHERE s.ProjectID=@ProjectID;
|
||||||
|
DELETE a FROM dbo.LocationAliases a JOIN dbo.Locations l ON l.LocationID=a.LocationID WHERE l.ProjectID=@ProjectID;
|
||||||
|
DELETE x FROM dbo.PlotEventTargetPlotLines x JOIN dbo.ThreadEvents e ON e.ThreadEventID=x.PlotEventID JOIN dbo.PlotThreads t ON t.PlotThreadID=e.PlotThreadID JOIN dbo.PlotLines p ON p.PlotLineID=t.PlotLineID WHERE p.ProjectID=@ProjectID;
|
||||||
|
DELETE dbo.SceneManuscriptSources WHERE ProjectID=@ProjectID;
|
||||||
|
DELETE dbo.ManuscriptStructuralChapterSources WHERE ProjectID=@ProjectID;
|
||||||
|
DELETE dbo.ManuscriptDocuments WHERE ProjectID=@ProjectID;
|
||||||
|
|
||||||
|
DELETE n FROM dbo.MapJourneyNotes n JOIN dbo.StoryMaps m ON m.MapID=n.MapID WHERE m.ProjectID=@ProjectID;
|
||||||
|
DELETE r FROM dbo.MapRelationships r JOIN dbo.StoryMaps m ON m.MapID=r.MapID WHERE m.ProjectID=@ProjectID;
|
||||||
|
DELETE f FROM dbo.MapFeatures f JOIN dbo.StoryMaps m ON m.MapID=f.MapID WHERE m.ProjectID=@ProjectID;
|
||||||
|
DELETE dbo.StoryMaps WHERE ProjectID=@ProjectID;
|
||||||
|
DELETE dbo.MapReferenceImages WHERE ProjectID=@ProjectID;
|
||||||
|
UPDATE dbo.UserFile SET IsDeleted=1,DeletedDateUTC=SYSUTCDATETIME() WHERE ProjectID=@ProjectID AND EntityType=N'MapReferenceImage';
|
||||||
|
|
||||||
|
DELETE sw FROM dbo.ScenarioWarnings sw INNER JOIN dbo.Scenarios sc ON sc.ScenarioID = sw.ScenarioID WHERE sc.ProjectID = @ProjectID;
|
||||||
|
DELETE svr FROM dbo.ScenarioValidationRuns svr INNER JOIN dbo.Scenarios sc ON sc.ScenarioID = svr.ScenarioID WHERE sc.ProjectID = @ProjectID;
|
||||||
|
DELETE sso FROM dbo.ScenarioSceneOrder sso INNER JOIN dbo.Scenarios sc ON sc.ScenarioID = sso.ScenarioID WHERE sc.ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.Scenarios WHERE ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
DELETE FROM dbo.ContinuityWarnings WHERE ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.ValidationRuns WHERE ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
DELETE sa FROM dbo.SceneAttachments sa INNER JOIN dbo.Scenes s ON s.SceneID = sa.SceneID INNER JOIN dbo.Chapters c ON c.ChapterID = s.ChapterID INNER JOIN dbo.Books b ON b.BookID = c.BookID WHERE b.ProjectID = @ProjectID;
|
||||||
|
DELETE sci FROM dbo.SceneChecklistItems sci INNER JOIN dbo.Scenes s ON s.SceneID = sci.SceneID INNER JOIN dbo.Chapters c ON c.ChapterID = s.ChapterID INNER JOIN dbo.Books b ON b.BookID = c.BookID WHERE b.ProjectID = @ProjectID;
|
||||||
|
DELETE sw FROM dbo.SceneWorkflow sw INNER JOIN dbo.Scenes s ON s.SceneID = sw.SceneID INNER JOIN dbo.Chapters c ON c.ChapterID = s.ChapterID INNER JOIN dbo.Books b ON b.BookID = c.BookID WHERE b.ProjectID = @ProjectID;
|
||||||
|
DELETE sn FROM dbo.SceneNotes sn INNER JOIN dbo.Scenes s ON s.SceneID = sn.SceneID INNER JOIN dbo.Chapters c ON c.ChapterID = s.ChapterID INNER JOIN dbo.Books b ON b.BookID = c.BookID WHERE b.ProjectID = @ProjectID;
|
||||||
|
DELETE cg FROM dbo.ChapterGoals cg INNER JOIN dbo.Chapters c ON c.ChapterID = cg.ChapterID INNER JOIN dbo.Books b ON b.BookID = c.BookID WHERE b.ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
DELETE sfpo FROM dbo.SceneFloorPlanOccupancy sfpo
|
||||||
|
INNER JOIN dbo.Scenes s ON s.SceneID = sfpo.SceneID
|
||||||
|
INNER JOIN dbo.Chapters c ON c.ChapterID = s.ChapterID
|
||||||
|
INNER JOIN dbo.Books b ON b.BookID = c.BookID
|
||||||
|
WHERE b.ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
DELETE sd FROM dbo.SceneDependencies sd
|
||||||
|
LEFT JOIN dbo.Scenes ss ON ss.SceneID = sd.SourceSceneID
|
||||||
|
LEFT JOIN dbo.Chapters sc ON sc.ChapterID = ss.ChapterID
|
||||||
|
LEFT JOIN dbo.Books sb ON sb.BookID = sc.BookID
|
||||||
|
LEFT JOIN dbo.Scenes ts ON ts.SceneID = sd.TargetSceneID
|
||||||
|
LEFT JOIN dbo.Chapters tc ON tc.ChapterID = ts.ChapterID
|
||||||
|
LEFT JOIN dbo.Books tb ON tb.BookID = tc.BookID
|
||||||
|
WHERE sd.ProjectID = @ProjectID OR sb.ProjectID = @ProjectID OR tb.ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
DELETE re FROM dbo.RelationshipEvents re INNER JOIN dbo.CharacterRelationships cr ON cr.CharacterRelationshipID = re.CharacterRelationshipID WHERE cr.ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.CharacterRelationships WHERE ProjectID = @ProjectID;
|
||||||
|
DELETE ck FROM dbo.CharacterKnowledge ck INNER JOIN dbo.Characters ch ON ch.CharacterID = ck.CharacterID WHERE ch.ProjectID = @ProjectID;
|
||||||
|
DELETE cae FROM dbo.CharacterAttributeEvents cae INNER JOIN dbo.Characters ch ON ch.CharacterID = cae.CharacterID WHERE ch.ProjectID = @ProjectID;
|
||||||
|
DELETE sc FROM dbo.SceneCharacters sc INNER JOIN dbo.Characters ch ON ch.CharacterID = sc.CharacterID WHERE ch.ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
DELETE acec FROM dbo.AssetCustodyEventCharacters acec INNER JOIN dbo.AssetCustodyEvents ace ON ace.AssetCustodyEventID = acec.AssetCustodyEventID INNER JOIN dbo.StoryAssets sa ON sa.StoryAssetID = ace.StoryAssetID WHERE sa.ProjectID = @ProjectID;
|
||||||
|
DELETE ace FROM dbo.AssetCustodyEvents ace INNER JOIN dbo.StoryAssets sa ON sa.StoryAssetID = ace.StoryAssetID WHERE sa.ProjectID = @ProjectID;
|
||||||
|
DELETE ad FROM dbo.AssetDependencies ad INNER JOIN dbo.StoryAssets sa ON sa.StoryAssetID = ad.SourceAssetID WHERE sa.ProjectID = @ProjectID;
|
||||||
|
DELETE ae FROM dbo.AssetEvents ae INNER JOIN dbo.StoryAssets sa ON sa.StoryAssetID = ae.StoryAssetID WHERE sa.ProjectID = @ProjectID;
|
||||||
|
DELETE sal FROM dbo.SceneAssetLocations sal INNER JOIN dbo.StoryAssets sa ON sa.StoryAssetID = sal.StoryAssetID WHERE sa.ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.StoryAssets WHERE ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
DELETE fpt FROM dbo.FloorPlanTransitions fpt INNER JOIN dbo.FloorPlanFloors fpf ON fpf.FloorPlanFloorID = fpt.FloorPlanFloorID INNER JOIN dbo.FloorPlans fp ON fp.FloorPlanID = fpf.FloorPlanID WHERE fp.ProjectID = @ProjectID;
|
||||||
|
DELETE fpb FROM dbo.FloorPlanBlocks fpb INNER JOIN dbo.FloorPlanFloors fpf ON fpf.FloorPlanFloorID = fpb.FloorPlanFloorID INNER JOIN dbo.FloorPlans fp ON fp.FloorPlanID = fpf.FloorPlanID WHERE fp.ProjectID = @ProjectID;
|
||||||
|
DELETE fpf FROM dbo.FloorPlanFloors fpf INNER JOIN dbo.FloorPlans fp ON fp.FloorPlanID = fpf.FloorPlanID WHERE fp.ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.FloorPlans WHERE ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
DELETE lr FROM dbo.LocationRelationships lr INNER JOIN dbo.Locations l ON l.LocationID = lr.FromLocationID WHERE l.ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.Locations WHERE ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
DELETE te FROM dbo.ThreadEvents te INNER JOIN dbo.PlotThreads pt ON pt.PlotThreadID = te.PlotThreadID INNER JOIN dbo.PlotLines pl ON pl.PlotLineID = pt.PlotLineID WHERE pl.ProjectID = @ProjectID;
|
||||||
|
DELETE pt FROM dbo.PlotThreads pt INNER JOIN dbo.PlotLines pl ON pl.PlotLineID = pt.PlotLineID WHERE pl.ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.PlotLines WHERE ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
DELETE FROM dbo.TimelineViewPresets WHERE ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.ProjectTimelineMetricSettings WHERE ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.ProjectTimelineSettings WHERE ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
DELETE smv FROM dbo.SceneMetricValues smv INNER JOIN dbo.Scenes s ON s.SceneID = smv.SceneID INNER JOIN dbo.Chapters c ON c.ChapterID = s.ChapterID INNER JOIN dbo.Books b ON b.BookID = c.BookID WHERE b.ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.SceneMetricTypes WHERE ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.CharacterAttributeTypes WHERE ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.AssetStates WHERE ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
DELETE sp FROM dbo.ScenePurposes sp INNER JOIN dbo.Scenes s ON s.SceneID = sp.SceneID INNER JOIN dbo.Chapters c ON c.ChapterID = s.ChapterID INNER JOIN dbo.Books b ON b.BookID = c.BookID WHERE b.ProjectID = @ProjectID;
|
||||||
|
DELETE so FROM dbo.SceneOutcomes so INNER JOIN dbo.Scenes s ON s.SceneID = so.SceneID INNER JOIN dbo.Chapters c ON c.ChapterID = s.ChapterID INNER JOIN dbo.Books b ON b.BookID = c.BookID WHERE b.ProjectID = @ProjectID;
|
||||||
|
DELETE s FROM dbo.Scenes s INNER JOIN dbo.Chapters c ON c.ChapterID = s.ChapterID INNER JOIN dbo.Books b ON b.BookID = c.BookID WHERE b.ProjectID = @ProjectID;
|
||||||
|
DELETE c FROM dbo.Chapters c INNER JOIN dbo.Books b ON b.BookID = c.BookID WHERE b.ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.Books WHERE ProjectID = @ProjectID;
|
||||||
|
DELETE FROM dbo.Characters WHERE ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
UPDATE p
|
||||||
|
SET ProjectName = src.ProjectName,
|
||||||
|
Description = src.Description,
|
||||||
|
CreatedDate = src.CreatedDate,
|
||||||
|
UpdatedDate = SYSUTCDATETIME(),
|
||||||
|
CreatedByUserID = CASE WHEN JSON_VALUE(@JsonData,'$.FormatVersion')=N'1.2' THEN src.CreatedByUserID ELSE p.CreatedByUserID END,
|
||||||
|
ModifiedByUserID = CASE WHEN JSON_VALUE(@JsonData,'$.FormatVersion')=N'1.2' THEN src.ModifiedByUserID ELSE p.ModifiedByUserID END,
|
||||||
|
CreatedDateUTC = CASE WHEN JSON_VALUE(@JsonData,'$.FormatVersion')=N'1.2' THEN src.CreatedDateUTC ELSE p.CreatedDateUTC END,
|
||||||
|
ModifiedDateUTC = CASE WHEN JSON_VALUE(@JsonData,'$.FormatVersion')=N'1.2' THEN src.ModifiedDateUTC ELSE p.ModifiedDateUTC END,
|
||||||
|
IsArchived = src.IsArchived,
|
||||||
|
ArchivedDate = src.ArchivedDate,
|
||||||
|
ArchivedReason = src.ArchivedReason
|
||||||
|
FROM dbo.Projects p
|
||||||
|
CROSS APPLY OPENJSON(@JsonData, '$.Project')
|
||||||
|
WITH
|
||||||
|
(
|
||||||
|
ProjectID int '$.ProjectID',
|
||||||
|
ProjectName nvarchar(200) '$.ProjectName',
|
||||||
|
Description nvarchar(max) '$.Description',
|
||||||
|
CreatedDate datetime2 '$.CreatedDate',
|
||||||
|
CreatedByUserID int '$.CreatedByUserID',
|
||||||
|
ModifiedByUserID int '$.ModifiedByUserID',
|
||||||
|
CreatedDateUTC datetime2 '$.CreatedDateUTC',
|
||||||
|
ModifiedDateUTC datetime2 '$.ModifiedDateUTC',
|
||||||
|
IsArchived bit '$.IsArchived',
|
||||||
|
ArchivedDate datetime2 '$.ArchivedDate',
|
||||||
|
ArchivedReason nvarchar(1000) '$.ArchivedReason'
|
||||||
|
) src
|
||||||
|
WHERE p.ProjectID = @ProjectID AND src.ProjectID = @ProjectID;
|
||||||
|
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'SceneMetricTypes', N'$.Data.SceneMetricTypes', @JsonData, @ProjectID, 1;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'AssetStates', N'$.Data.AssetStates', @JsonData, @ProjectID, 1;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'CharacterAttributeTypes', N'$.Data.CharacterAttributeTypes', @JsonData, @ProjectID, 1;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'Books', N'$.Data.Books', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'Chapters', N'$.Data.Chapters', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'Characters', N'$.Data.Characters', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'Locations', N'$.Data.Locations', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'FloorPlans', N'$.Data.FloorPlans', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'FloorPlanFloors', N'$.Data.FloorPlanFloors', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'FloorPlanBlocks', N'$.Data.FloorPlanBlocks', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'FloorPlanTransitions', N'$.Data.FloorPlanTransitions', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'Scenes', N'$.Data.Scenes', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'ScenePurposes', N'$.Data.ScenePurposes', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'SceneOutcomes', N'$.Data.SceneOutcomes', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'SceneMetricValues', N'$.Data.SceneMetricValues', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'ProjectTimelineSettings', N'$.Data.TimelineSettings', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'ProjectTimelineMetricSettings', N'$.Data.TimelineMetricSettings', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'TimelineViewPresets', N'$.Data.TimelineViewPresets', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'PlotLines', N'$.Data.PlotLines', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'PlotThreads', N'$.Data.PlotThreads', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'ThreadEvents', N'$.Data.ThreadEvents', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'StoryAssets', N'$.Data.StoryAssets', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'AssetEvents', N'$.Data.AssetEvents', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'AssetDependencies', N'$.Data.AssetDependencies', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'AssetCustodyEvents', N'$.Data.AssetCustodyEvents', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'AssetCustodyEventCharacters', N'$.Data.AssetCustodyCharacters', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'SceneCharacters', N'$.Data.SceneCharacters', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'CharacterAttributeEvents', N'$.Data.CharacterAttributeEvents', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'CharacterKnowledge', N'$.Data.CharacterKnowledge', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'CharacterRelationships', N'$.Data.CharacterRelationships', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'RelationshipEvents', N'$.Data.RelationshipEvents', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'LocationRelationships', N'$.Data.LocationRelationships', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'SceneAssetLocations', N'$.Data.SceneAssetLocations', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'SceneFloorPlanOccupancy', N'$.Data.SceneFloorPlanOccupancy', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'SceneDependencies', N'$.Data.SceneDependencies', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'ValidationRuns', N'$.Data.ValidationRuns', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'ContinuityWarnings', N'$.Data.ContinuityWarnings', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'SceneNotes', N'$.Data.SceneNotes', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'SceneWorkflow', N'$.Data.SceneWorkflow', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'SceneChecklistItems', N'$.Data.SceneChecklistItems', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'SceneAttachments', N'$.Data.SceneAttachments', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'ChapterGoals', N'$.Data.ChapterGoals', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'Scenarios', N'$.Data.Scenarios', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'ScenarioSceneOrder', N'$.Data.ScenarioSceneOrder', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'ScenarioValidationRuns', N'$.Data.ScenarioValidationRuns', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'ScenarioWarnings', N'$.Data.ScenarioWarnings', @JsonData, @ProjectID, 0;
|
||||||
|
|
||||||
|
-- Older backups contain no Maps sets. The automatic safety restore point preserves current geography.
|
||||||
|
IF EXISTS(SELECT 1 FROM OPENJSON(@JsonData,'$.Data.MapReferenceImages') WITH(ProjectID int '$.ProjectID') WHERE ProjectID IS NULL OR ProjectID<>@ProjectID) THROW 51005,'Reference images cross project boundaries.',1;
|
||||||
|
INSERT dbo.MapReferenceImages(ImageID,ProjectID,OriginalFileName,ContentType,Width,Height,ImageData)
|
||||||
|
SELECT x.ImageID,@ProjectID,x.OriginalFileName,x.ContentType,x.Width,x.Height,CAST(N'' AS xml).value('xs:base64Binary(sql:column("x.ImageData"))','varbinary(max)')
|
||||||
|
FROM OPENJSON(@JsonData,'$.Data.MapReferenceImages') WITH(ImageID uniqueidentifier '$.ImageID',OriginalFileName nvarchar(200) '$.OriginalFileName',ContentType nvarchar(40) '$.ContentType',Width int '$.Width',Height int '$.Height',ImageData nvarchar(max) '$.ImageData') x;
|
||||||
|
DECLARE @ImageOwner int=(SELECT TOP(1) UserID FROM dbo.ProjectUserAccess WHERE ProjectID=@ProjectID AND AccessRole='Owner' AND IsActive=1 ORDER BY ProjectUserAccessID);
|
||||||
|
INSERT dbo.UserFile(UserID,ProjectID,EntityType,EntityID,FileName,OriginalFileName,ContentType,FileSizeBytes,StoragePath)
|
||||||
|
SELECT @ImageOwner,@ProjectID,N'MapReferenceImage',@ProjectID,CONVERT(nvarchar(36),ImageID)+N'.webp',OriginalFileName,ContentType,FileSizeBytes,N'db:map-reference/'+CONVERT(nvarchar(20),@ProjectID)+N'/'+CONVERT(nvarchar(36),ImageID) FROM dbo.MapReferenceImages WHERE ProjectID=@ProjectID;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'StoryMaps', N'$.Data.StoryMaps', @JsonData, @ProjectID, 1;
|
||||||
|
IF EXISTS(SELECT 1 FROM OPENJSON(@JsonData,'$.Data.MapFeatures') WITH(MapID int '$.MapID') x WHERE NOT EXISTS(SELECT 1 FROM dbo.StoryMaps m WHERE m.MapID=x.MapID AND m.ProjectID=@ProjectID))
|
||||||
|
OR EXISTS(SELECT 1 FROM OPENJSON(@JsonData,'$.Data.MapRelationships') WITH(MapID int '$.MapID') x WHERE NOT EXISTS(SELECT 1 FROM dbo.StoryMaps m WHERE m.MapID=x.MapID AND m.ProjectID=@ProjectID))
|
||||||
|
THROW 51005,'Map backup contains features outside this project.',1;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'MapFeatures', N'$.Data.MapFeatures', @JsonData, @ProjectID, 0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'MapRelationships', N'$.Data.MapRelationships', @JsonData, @ProjectID, 0;
|
||||||
|
IF EXISTS(SELECT 1 FROM dbo.StoryMaps m JOIN dbo.StoryMaps parent ON parent.MapID=m.ParentMapID WHERE m.ProjectID=@ProjectID AND parent.ProjectID<>@ProjectID)
|
||||||
|
OR EXISTS(SELECT 1 FROM dbo.MapFeatures f JOIN dbo.StoryMaps m ON m.MapID=f.MapID JOIN dbo.Locations l ON l.LocationID=f.LocationID WHERE m.ProjectID=@ProjectID AND l.ProjectID<>@ProjectID)
|
||||||
|
THROW 51005,'Map hierarchy or Location links cross projects.',1;
|
||||||
|
IF EXISTS(SELECT 1 FROM OPENJSON(@JsonData,'$.Data.MapJourneyNotes') WITH(MapID int '$.MapID',CharacterID int '$.CharacterID',FromSceneID int '$.FromSceneID',ToSceneID int '$.ToSceneID',RouteFeatureID uniqueidentifier '$.RouteFeatureID') n
|
||||||
|
WHERE NOT EXISTS(SELECT 1 FROM dbo.StoryMaps m WHERE m.MapID=n.MapID AND m.ProjectID=@ProjectID)
|
||||||
|
OR NOT EXISTS(SELECT 1 FROM dbo.Characters c WHERE c.CharacterID=n.CharacterID AND c.ProjectID=@ProjectID)
|
||||||
|
OR (SELECT COUNT(*) FROM dbo.Scenes s JOIN dbo.Chapters ch ON ch.ChapterID=s.ChapterID JOIN dbo.Books b ON b.BookID=ch.BookID WHERE b.ProjectID=@ProjectID AND s.SceneID IN(n.FromSceneID,n.ToSceneID))<>2
|
||||||
|
OR (n.RouteFeatureID IS NOT NULL AND NOT EXISTS(SELECT 1 FROM dbo.MapFeatures f WHERE f.MapID=n.MapID AND f.FeatureID=n.RouteFeatureID AND f.GeometryClass='Path')))
|
||||||
|
THROW 51005,'Journey annotations cross project or map boundaries.',1;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'MapJourneyNotes',N'$.Data.MapJourneyNotes',@JsonData,@ProjectID,0;
|
||||||
|
IF EXISTS(SELECT 1 FROM dbo.StoryMaps m WHERE m.ProjectID=@ProjectID AND (ISJSON(m.AppearanceJson)<>1 OR ISJSON(m.ReferenceJson)<>1 OR (JSON_VALUE(m.ReferenceJson,'$.imageID') IS NOT NULL AND NOT EXISTS(SELECT 1 FROM dbo.MapReferenceImages i WHERE i.ProjectID=@ProjectID AND i.ImageID=TRY_CONVERT(uniqueidentifier,JSON_VALUE(m.ReferenceJson,'$.imageID')))))) THROW 51005,'Invalid map appearance or foreign reference image.',1;
|
||||||
|
UPDATE dbo.StoryMaps SET Revision=CASE WHEN Revision>@PreviousMapRevision THEN Revision+1 ELSE @PreviousMapRevision+1 END WHERE ProjectID=@ProjectID;
|
||||||
|
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'ManuscriptDocuments',N'$.Data.ManuscriptDocuments',@JsonData,@ProjectID,1;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'SceneManuscriptSources',N'$.Data.SceneManuscriptSources',@JsonData,@ProjectID,1;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'ManuscriptStructuralChapterSources',N'$.Data.ManuscriptStructuralChapterSources',@JsonData,@ProjectID,1;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'WritingPlans',N'$.Data.WritingPlans',@JsonData,@ProjectID,1;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'WritingScheduleItems',N'$.Data.WritingScheduleItems',@JsonData,@ProjectID,0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'CharacterAliases',N'$.Data.CharacterAliases',@JsonData,@ProjectID,0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'AssetAliases',N'$.Data.AssetAliases',@JsonData,@ProjectID,0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'LocationAliases',N'$.Data.LocationAliases',@JsonData,@ProjectID,0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'AuthorPlotSeeds',N'$.Data.AuthorPlotSeeds',@JsonData,@ProjectID,1;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'ContinuityWarningAcknowledgements',N'$.Data.ContinuityWarningAcknowledgements',@JsonData,@ProjectID,1;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'PlotEventTargetPlotLines',N'$.Data.PlotEventTargetPlotLines',@JsonData,@ProjectID,0;
|
||||||
|
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'WordCompanionSceneAssets',N'$.Data.WordCompanionSceneAssets',@JsonData,@ProjectID,0;
|
||||||
|
EXEC dbo.ProjectRestore_InsertJsonTable N'WordCompanionSceneLocations',N'$.Data.WordCompanionSceneLocations',@JsonData,@ProjectID,0;
|
||||||
|
|
||||||
|
DECLARE EnableCursor CURSOR LOCAL FAST_FORWARD FOR SELECT TableName FROM @RestoreTables;
|
||||||
|
OPEN EnableCursor;
|
||||||
|
FETCH NEXT FROM EnableCursor INTO @TableName;
|
||||||
|
WHILE @@FETCH_STATUS = 0
|
||||||
|
BEGIN
|
||||||
|
DECLARE @EnableSql nvarchar(max) = N'ALTER TABLE dbo.' + QUOTENAME(@TableName) + N' WITH CHECK CHECK CONSTRAINT ALL;';
|
||||||
|
EXEC (@EnableSql);
|
||||||
|
FETCH NEXT FROM EnableCursor INTO @TableName;
|
||||||
|
END
|
||||||
|
CLOSE EnableCursor;
|
||||||
|
DEALLOCATE EnableCursor;
|
||||||
|
|
||||||
|
IF @SourceRestorePointID IS NOT NULL AND @SafetyRestorePointID IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO dbo.ProjectRestoreHistory (ProjectID, SourceRestorePointID, SafetyRestorePointID, PerformedBy, Notes)
|
||||||
|
VALUES (@ProjectID, @SourceRestorePointID, @SafetyRestorePointID, SUSER_SNAME(), N'Project restored from saved restore point.');
|
||||||
|
END;
|
||||||
|
|
||||||
|
COMMIT TRANSACTION;
|
||||||
|
END;
|
||||||
|
GO
|
||||||
Loading…
x
Reference in New Issue
Block a user