E1: schema dell'esportazione, migrazione 0003, archivi ed ExportSettings (#58)
La tappa E1 della 0.3.0 prepara il database per le copie esterne senza cambiare comportamento: nulla in interfaccia, motore o API usa ancora ciò che segue. - Migrazione 0003: export_destination, export_account, export_copy, export_run, export_item, video_analysis e media_conversion (risposta di Alberto del 26 novembre: i convertiti per la libreria in una tabella a parte, media non cambia), con i vincoli e gli indici di §8.3. - Archivi IExportStore, IVideoAnalysisStore e IMediaConversionStore in IFebeStorage; ExportSettings sulle cinque chiavi esportazione.*. - AccountStore.DeleteAsync spegne «Automatica» delle cartelle dell'account e vi scrive il suo nome prima di cancellarlo (finché non ci sono destinazioni non fa nulla). - Prove: aggiornamento dei database delle versioni 1 e 2 con foreign_key_check pulito, database più nuovo rifiutato e lasciato intatto, vincoli, archivi, piani delle ricerche, impostazioni e documenti. - SPECIFICA §4.10, §8.3 e §15, decisioni.md e stato.md aggiornati. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dc92cabe5c
commit
ea4666d49b
23 files changed
+3756
-7
No files matched your search
@@ -60,7 +60,8 @@ public interface IAccountStore
|
||||
/// <summary>
|
||||
/// Removes the account record and, by cascade, its entries, files records and highlights. Files on disk are not
|
||||
/// touched: removing an account with its files is a library operation, and the default is to keep them and make
|
||||
/// the account «Solo archivio» (spec §4.2).
|
||||
/// the account «Solo archivio» (spec §4.2). Its export destinations stay, without account and with the user name;
|
||||
/// its «Esporta questo account» choice goes with it (spec §4.10).
|
||||
/// </summary>
|
||||
Task DeleteAsync(long accountId, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
using Febe.Core.Domain;
|
||||
|
||||
namespace Febe.Core.Storage;
|
||||
|
||||
/// <summary>
|
||||
/// Export destinations, the switch «Esporta questo account», copies, jobs and their files (spec §4.10; §8.3
|
||||
/// <c>export_destination</c>, <c>export_account</c>, <c>export_copy</c>, <c>export_run</c>, <c>export_item</c>).
|
||||
/// Only records: no method touches a file.
|
||||
/// </summary>
|
||||
public interface IExportStore
|
||||
{
|
||||
// Destinations ---------------------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Adds a destination. General: <see cref="ExportDestination.AccountId"/> null; Account: set.
|
||||
/// <see cref="ExportDestination.RemovedAt"/> and <see cref="ExportDestination.RemovedAccountUsername"/> must be null.
|
||||
/// <see cref="DuplicateRecordException"/> when a general folder is already in use, or the account already has an own
|
||||
/// folder in use (retire it first).
|
||||
/// </summary>
|
||||
Task<ExportDestination> AddDestinationAsync(ExportDestination destination, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Writes label, content types, formats, naming schemes, «Automatica» and its answer, pause and error.
|
||||
/// <see cref="KeyNotFoundException"/> for a missing id; <see cref="ArgumentException"/> if scope, account or root
|
||||
/// differ from the stored row, the row is retired, or «Automatica» is turned on for an own folder whose account was
|
||||
/// removed (it is attached to an account first).
|
||||
/// </summary>
|
||||
Task UpdateDestinationAsync(ExportDestination destination, CancellationToken ct = default);
|
||||
|
||||
Task<ExportDestination?> GetDestinationAsync(long id, CancellationToken ct = default);
|
||||
|
||||
/// <summary>The general folder in use, or null.</summary>
|
||||
Task<ExportDestination?> GetGeneralDestinationAsync(CancellationToken ct = default);
|
||||
|
||||
/// <summary>The own folder in use of an account, or null.</summary>
|
||||
Task<ExportDestination?> GetAccountDestinationAsync(long accountId, CancellationToken ct = default);
|
||||
|
||||
/// <summary>The general folder first, then by id; retired rows only when asked.</summary>
|
||||
Task<IReadOnlyList<ExportDestination>> ListDestinationsAsync(bool includeRetired = false, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Retires a destination (removed by Alberto, or replaced by another folder): sets the removal time and turns
|
||||
/// «Automatica» off. No row and no file is deleted. <see cref="KeyNotFoundException"/> for a missing id.
|
||||
/// </summary>
|
||||
Task RetireDestinationAsync(long id, DateTimeOffset at, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Gives an orphan own folder in use back to a re-added account: sets the account, clears the user name and, in the
|
||||
/// same transaction, sets the account on its orphan copies. «Automatica» stays off (the removal of the account turned
|
||||
/// it off and forgot «Solo i nuovi»), so turning it on again asks. <see cref="InvalidOperationException"/> if it is not
|
||||
/// an orphan in use, or the account already has an own folder in use; <see cref="DuplicateRecordException"/> if an
|
||||
/// orphan copy would collide with a current copy of the account.
|
||||
/// </summary>
|
||||
Task AttachDestinationAsync(long id, long accountId, CancellationToken ct = default);
|
||||
|
||||
// «Esporta questo account» ---------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>The choice of the account; null when none is recorded (the default applies).</summary>
|
||||
Task<bool?> GetAccountExportEnabledAsync(long accountId, CancellationToken ct = default);
|
||||
|
||||
Task SetAccountExportEnabledAsync(long accountId, bool enabled, CancellationToken ct = default);
|
||||
|
||||
// Copies ---------------------------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Records a copy. <see cref="ArgumentException"/> when the account is null (only the removal of an account clears it);
|
||||
/// <see cref="DuplicateRecordException"/> when its identity already has a current (Copied or Failed) row, or its path
|
||||
/// in the destination is held by a Copied or Superseded row.
|
||||
/// </summary>
|
||||
Task<ExportCopy> AddCopyAsync(ExportCopy copy, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Writes state, superseded-by, media, origin, path, bytes, copy SHA-256, state time and error.
|
||||
/// <see cref="KeyNotFoundException"/> for a missing id; <see cref="ArgumentException"/> if an identity column
|
||||
/// (destination, account, source SHA-256, variant, format, frame) differs from the stored row;
|
||||
/// <see cref="DuplicateRecordException"/> when the new state collides with another current row or path (as in
|
||||
/// <see cref="AddCopyAsync"/>).
|
||||
/// </summary>
|
||||
Task UpdateCopyAsync(ExportCopy copy, CancellationToken ct = default);
|
||||
|
||||
Task<ExportCopy?> GetCopyAsync(long id, CancellationToken ct = default);
|
||||
|
||||
/// <summary>The current (Copied or Failed) copy of an identity.</summary>
|
||||
Task<ExportCopy?> FindCurrentCopyAsync(ExportCopyIdentity identity, CancellationToken ct = default);
|
||||
|
||||
/// <summary>The newest row of an identity in any state: Removed or Superseded means «never queued by itself».</summary>
|
||||
Task<ExportCopy?> FindLatestCopyAsync(ExportCopyIdentity identity, CancellationToken ct = default);
|
||||
|
||||
/// <summary>Every copy whose original has this SHA-256 or was replaced by it, any destination, account and state, newest first.</summary>
|
||||
Task<IReadOnlyList<ExportCopy>> ListCopiesBySha256Async(string sha256, CancellationToken ct = default);
|
||||
|
||||
/// <summary>The Copied or Superseded copy recorded on this path of a destination (case-insensitive for ASCII).</summary>
|
||||
Task<ExportCopy?> FindCopyByPathAsync(long destinationId, string relativePath, CancellationToken ct = default);
|
||||
|
||||
/// <summary>Copies of a destination by key, with an optional state.</summary>
|
||||
Task<IReadOnlyList<ExportCopy>> ListCopiesAsync(long destinationId, ExportCopyState? state = null, long afterId = 0, int limit = 500, CancellationToken ct = default);
|
||||
|
||||
/// <summary>Counts per state of a destination; every state is present, zero included.</summary>
|
||||
Task<IReadOnlyDictionary<ExportCopyState, int>> CountCopiesAsync(long destinationId, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Re-links an orphan row (account removed) to a re-added account, when its file is adopted again.
|
||||
/// <see cref="KeyNotFoundException"/> for a missing id; <see cref="InvalidOperationException"/> if the row is not an orphan;
|
||||
/// <see cref="DuplicateRecordException"/> if the account already has a current copy of that identity.
|
||||
/// </summary>
|
||||
Task<ExportCopy> RelinkOrphanCopyAsync(long copyId, long accountId, long? mediaId, DateTimeOffset at, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// The library file of an account changed from <paramref name="oldSha256"/> to <paramref name="newSha256"/>: its
|
||||
/// Copied rows of the old file become Superseded, its Removed rows of the old file get the new SHA-256, and its rows
|
||||
/// superseded by the old file move to the new one. A row whose own original is the new file (the library went back to
|
||||
/// it, A→B→A) is never superseded by itself: a Removed one loses the stamp, and the newest Superseded one of each
|
||||
/// identity becomes Copied again, unless that identity already has a current row (then it stays Superseded by the old
|
||||
/// file, as history). Returns the rows changed. The caller calls it only when no present file of that account still
|
||||
/// has the old SHA-256.
|
||||
/// </summary>
|
||||
Task<int> SupersedeCopiesAsync(long accountId, string oldSha256, string newSha256, DateTimeOffset at, CancellationToken ct = default);
|
||||
|
||||
// Jobs and their files -------------------------------------------------------------------------------------------
|
||||
|
||||
Task<ExportRun> CreateRunAsync(ExportRun run, CancellationToken ct = default);
|
||||
|
||||
Task UpdateRunAsync(ExportRun run, CancellationToken ct = default);
|
||||
|
||||
Task<ExportRun?> GetRunAsync(long runId, CancellationToken ct = default);
|
||||
|
||||
/// <summary>Jobs, newest first.</summary>
|
||||
Task<IReadOnlyList<ExportRun>> ListRunsAsync(CancellationToken ct = default);
|
||||
|
||||
/// <summary>Running, Interrupted and Paused jobs, oldest first.</summary>
|
||||
Task<IReadOnlyList<ExportRun>> ListUnfinishedRunsAsync(CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Adds items in one transaction; an item already there for the same job, file, variant, format and frame is left
|
||||
/// unchanged (so a resumed job adds nothing twice). <see cref="ArgumentException"/> when an item has no account or no
|
||||
/// library file (only the deletion of the file clears it, and an item without one would not be recognised again).
|
||||
/// </summary>
|
||||
Task AddItemsAsync(IReadOnlyList<ExportItem> items, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Writes account (never cleared), source SHA-256, state, note, path, copy and error of items. Job, file, variant,
|
||||
/// format and frame are the identity of an item and are never rewritten: <see cref="ArgumentException"/> if they
|
||||
/// differ from the stored row (a file deleted meanwhile stays cleared); <see cref="KeyNotFoundException"/> for a
|
||||
/// missing item of the job.
|
||||
/// </summary>
|
||||
Task UpdateItemsAsync(IReadOnlyList<ExportItem> items, CancellationToken ct = default);
|
||||
|
||||
Task<ExportItem?> GetItemAsync(long itemId, CancellationToken ct = default);
|
||||
|
||||
/// <summary>Items of a job, by key, with an optional state.</summary>
|
||||
Task<IReadOnlyList<ExportItem>> ListItemsAsync(ExportItemQuery query, CancellationToken ct = default);
|
||||
|
||||
/// <summary>Counts by state of a job's items; every state is present, zero included.</summary>
|
||||
Task<ExportRunSummary> GetRunSummaryAsync(long runId, CancellationToken ct = default);
|
||||
|
||||
/// <summary>Removes a job with its items. Only records: copies stay.</summary>
|
||||
Task DeleteRunAsync(long runId, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
/// <summary>A page of the items of an export job.</summary>
|
||||
public sealed record ExportItemQuery
|
||||
{
|
||||
public required long RunId { get; init; }
|
||||
|
||||
public ExportItemState? State { get; init; }
|
||||
|
||||
public long AfterId { get; init; }
|
||||
|
||||
public int Limit { get; init; } = 500;
|
||||
}
|
||||
|
||||
/// <summary>Counts of the items of an export job.</summary>
|
||||
public sealed record ExportRunSummary(int Total, IReadOnlyDictionary<ExportItemState, int> ByState);
|
||||
@@ -30,6 +30,12 @@ public interface IFebeStorage : IAsyncDisposable
|
||||
|
||||
IImportStore Imports { get; }
|
||||
|
||||
IExportStore Exports { get; }
|
||||
|
||||
IVideoAnalysisStore VideoAnalyses { get; }
|
||||
|
||||
IMediaConversionStore Conversions { get; }
|
||||
|
||||
ISettingsStore Settings { get; }
|
||||
|
||||
IDatabaseMaintenance Maintenance { get; }
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using Febe.Core.Domain;
|
||||
|
||||
namespace Febe.Core.Storage;
|
||||
|
||||
/// <summary>
|
||||
/// Converted files added to entries by the conversion for the library (spec §4.10, §8.3 <c>media_conversion</c>).
|
||||
/// Only records: no method touches a file.
|
||||
/// </summary>
|
||||
public interface IMediaConversionStore
|
||||
{
|
||||
/// <summary>
|
||||
/// Records a conversion. <see cref="DuplicateRecordException"/> when the file already has a current (Pending,
|
||||
/// Converted or Failed) conversion in that format.
|
||||
/// </summary>
|
||||
Task<MediaConversion> AddAsync(MediaConversion conversion, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Writes state, path, bytes, SHA-256, times and error. <see cref="KeyNotFoundException"/> for a missing id;
|
||||
/// <see cref="DuplicateRecordException"/> when the new state collides with another current conversion (as in <see cref="AddAsync"/>).
|
||||
/// </summary>
|
||||
Task UpdateAsync(MediaConversion conversion, CancellationToken ct = default);
|
||||
|
||||
Task<MediaConversion?> GetAsync(long id, CancellationToken ct = default);
|
||||
|
||||
/// <summary>The conversions of one library file, in creation order.</summary>
|
||||
Task<IReadOnlyList<MediaConversion>> ListByMediaAsync(long mediaId, CancellationToken ct = default);
|
||||
|
||||
/// <summary>Conversions whose converted file has this SHA-256 (a converted file found again is never a duplicate).</summary>
|
||||
Task<IReadOnlyList<MediaConversion>> FindBySha256Async(string sha256, CancellationToken ct = default);
|
||||
|
||||
/// <summary>The queue of the conversion, in order, by key.</summary>
|
||||
Task<IReadOnlyList<MediaConversion>> ListPendingAsync(long afterId = 0, int limit = 500, CancellationToken ct = default);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Febe.Core.Domain;
|
||||
|
||||
namespace Febe.Core.Storage;
|
||||
|
||||
/// <summary>
|
||||
/// Outcomes of «È un video fermo?» by SHA-256 of the video and number of the algorithm (spec §4.10, §8.3
|
||||
/// <c>video_analysis</c>). No link to the library: an outcome outlives deletion and re-import of the same file.
|
||||
/// </summary>
|
||||
public interface IVideoAnalysisStore
|
||||
{
|
||||
/// <summary>The analysis with the highest algorithm number for this SHA-256, or null.</summary>
|
||||
Task<VideoAnalysis?> GetAsync(string sha256, CancellationToken ct = default);
|
||||
|
||||
/// <summary>The analysis with the highest algorithm number for each SHA-256 that has one, keyed by lower-case SHA-256.</summary>
|
||||
Task<IReadOnlyDictionary<string, VideoAnalysis>> GetManyAsync(IReadOnlyCollection<string> sha256s, CancellationToken ct = default);
|
||||
|
||||
/// <summary>Stores (or replaces) the outcome of one algorithm for one SHA-256.</summary>
|
||||
Task SetAsync(VideoAnalysis analysis, CancellationToken ct = default);
|
||||
}
|
||||
Reference in new issue
Block a user