feat(data): session keys, scan stamps and archive queries
Migration 0002 adds sequence_sessions and archive_folders. New repository methods: folder scan state, session-key mapping, sequence locations and relocation, frame sync from sidecars, duplicate and candidate lookups, folder rebase, integrity updates and verifiable card import history. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
6 files changed
+228
No files matched your search
@@ -79,6 +79,9 @@ public sealed record ArchiveHealth(
|
||||
long CorruptFrames,
|
||||
long DuplicateFrames);
|
||||
|
||||
/// <summary>Where a sequence lives in its archive.</summary>
|
||||
public sealed record SequenceLocation(Guid Id, string Folder, string? Title);
|
||||
|
||||
/// <summary>Sequences (projects) with their tags; Library listing and Archive statistics.</summary>
|
||||
public sealed class SequenceRepository
|
||||
{
|
||||
@@ -259,6 +262,45 @@ public sealed class SequenceRepository
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>Folder and title of every sequence of an archive, by folder.</summary>
|
||||
public Task<IReadOnlyList<SequenceLocation>> ListLocationsAsync(Guid archiveId, CancellationToken cancellationToken = default) =>
|
||||
_db.ListAsync("SELECT id, folder, title FROM sequences WHERE archive_id = $1 ORDER BY folder, id", [archiveId],
|
||||
r => new SequenceLocation(r.GetGuid(0), r.GetString(1), r.GetStringOrNull(2)), cancellationToken);
|
||||
|
||||
/// <summary>The sequence created for a session key (automatic grouping of uploads and card sessions).</summary>
|
||||
public Task<Guid?> FindBySessionKeyAsync(Guid archiveId, string sessionKey, CancellationToken cancellationToken = default) =>
|
||||
_db.ScalarAsync<Guid?>("SELECT sequence_id FROM sequence_sessions WHERE archive_id = $1 AND session_key = $2",
|
||||
[archiveId, sessionKey], cancellationToken);
|
||||
|
||||
/// <summary>Binds a session key to a sequence unless it is already bound; returns the sequence the key resolves to.</summary>
|
||||
public Task<Guid> MapSessionKeyAsync(Guid archiveId, string sessionKey, Guid sequenceId, CancellationToken cancellationToken = default) =>
|
||||
_db.InTransactionAsync(async session =>
|
||||
{
|
||||
await session.ExecuteAsync(
|
||||
"INSERT INTO sequence_sessions (archive_id, session_key, sequence_id) VALUES ($1, $2, $3) ON CONFLICT (archive_id, session_key) DO NOTHING",
|
||||
[archiveId, sessionKey, sequenceId], cancellationToken).ConfigureAwait(false);
|
||||
return (await session.ScalarAsync<Guid?>("SELECT sequence_id FROM sequence_sessions WHERE archive_id = $1 AND session_key = $2",
|
||||
[archiveId, sessionKey], cancellationToken).ConfigureAwait(false))!.Value;
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>Moves a sequence to another folder and/or title (mass rename); false when it does not exist.</summary>
|
||||
public Task<bool> RelocateAsync(Guid id, string folder, string? title, CancellationToken cancellationToken = default) =>
|
||||
_db.InTransactionAsync(async session =>
|
||||
{
|
||||
var current = await session.QuerySingleOrDefaultAsync($"{_select} WHERE s.id = $1{_db.Sql.ForUpdate}", [id], Map, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (current is null) return false;
|
||||
var titleChanged = current.Title != title;
|
||||
await UpsertRowAsync(session, current with
|
||||
{
|
||||
Folder = folder,
|
||||
Title = title,
|
||||
SettingsVersion = titleChanged ? current.SettingsVersion + 1 : current.SettingsVersion,
|
||||
UpdatedAt = DateTimeOffset.UtcNow,
|
||||
}, cancellationToken).ConfigureAwait(false);
|
||||
return true;
|
||||
}, cancellationToken);
|
||||
|
||||
private static List<string> Filter(SequenceQuery query, SqlParameters p)
|
||||
{
|
||||
var where = new List<string>();
|
||||
|
||||
Reference in new issue
Block a user