E1: schema dell'esportazione, migrazione 0003, archivi ed ExportSettings (#58)
verifica / controlli (push) Successful in 19s
verifica / prove (push) Canceled after 10m59s
verifica / installatore (push) Canceled after 0s
verifica / immagine (push) Canceled after 0s

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:
Alby96andClaude Opus 5.5 committed 2026-11-26 19:29:14 +01:00
1 parent dc92cabe5c
commit ea4666d49b
23 files changed
+3756 -7

No files matched your search

+176
View File
@@ -0,0 +1,176 @@
using Febe.Core.Domain;
using Febe.Data;
using Febe.Tests.Support;
using Microsoft.Data.Sqlite;
namespace Febe.Tests.Data;
/// <summary>
/// Two accounts with the same post (a post of marta.demo, a tagged post of luca.demo, same SHA-256), the general
/// folder and the own folder of marta.demo: the starting point of the export tests.
/// </summary>
internal sealed record ExportWorld(long Marta, long Luca, long MartaEntry, long MartaMedia, long LucaEntry, long LucaMedia, long General, long Own)
{
public static async Task<ExportWorld> CreateAsync(FebeDatabase db, string generalRoot = @"E:\Copie")
{
var marta = await db.Accounts.AddAsync(Make.Account("marta.demo", "100"));
var luca = await db.Accounts.AddAsync(Make.Account("luca.demo", "200"));
var post = await db.Entries.AddAsync(Make.Entry(marta.Id, "555", Make.T0), [Make.Stored(Make.Photo(), Make.Sha(1), "post/a.jpg")]);
var tagged = await db.Entries.AddAsync(Make.Entry(luca.Id, "555", Make.T0, EntryKind.Tagged), [Make.Stored(Make.Photo(), Make.Sha(1), "taggati/a.jpg")]);
var general = await db.Exports.AddDestinationAsync(Destination(ExportScope.General, null, generalRoot));
var own = await db.Exports.AddDestinationAsync(Destination(ExportScope.Account, marta.Id, @"F:\Marta"));
return new ExportWorld(marta.Id, luca.Id, post.Stored.Entry.Id, post.Stored.Media[0].Id, tagged.Stored.Entry.Id, tagged.Stored.Media[0].Id, general.Id, own.Id);
}
public static ExportDestination Destination(ExportScope scope, long? accountId, string root) => new()
{
Scope = scope,
AccountId = accountId,
RootPath = root,
ContentTypes = ContentTypes.All,
CreatedAt = Make.T0,
};
/// <summary>A whole copy of the shared photo for marta.demo in the general folder, at <paramref name="path"/>.</summary>
public ExportCopy WholeCopy(string path, long? destination = null, long? account = null, long? media = null) => new()
{
DestinationId = destination ?? General,
AccountId = account ?? Marta,
MediaId = media ?? MartaMedia,
SourceSha256 = Make.Sha(1),
Variant = ExportVariant.Whole,
State = ExportCopyState.Copied,
RelativePath = path,
Bytes = 1000,
CopySha256 = Make.Sha(1),
CopiedAt = Make.T0.AddHours(1),
};
/// <summary>A raw row of export_copy (the whole copy above), with changes.</summary>
public Dictionary<string, object?> CopyRow(params (string Column, object? Value)[] changes) => Row(
new()
{
["destination_id"] = General,
["account_id"] = Marta,
["media_id"] = MartaMedia,
["source_sha256"] = Make.Sha(1),
["variant"] = "Whole",
["format"] = "Original",
["frame_at_ms"] = null,
["state"] = "Copied",
["superseded_by_sha256"] = null,
["origin"] = "Written",
["relative_path"] = "marta.demo/a.jpg",
["bytes"] = 1000L,
["copy_sha256"] = Make.Sha(1),
["copied_at"] = 0L,
},
changes);
/// <summary>A raw row of export_destination: a retired general folder, with changes.</summary>
public static Dictionary<string, object?> DestinationRow(params (string Column, object? Value)[] changes) => Row(
new()
{
["scope"] = "General",
["account_id"] = null,
["removed_account_username"] = null,
["root_path"] = @"G:\Altra",
["content_types"] = 63L,
["photo_format"] = null,
["video_format"] = null,
["automatic"] = 0L,
["automatic_since"] = null,
["created_at"] = 0L,
["removed_at"] = 1L,
},
changes);
public Dictionary<string, object?> RunRow(params (string Column, object? Value)[] changes) => Row(
new() { ["destination_id"] = General, ["kind"] = "Copy", ["origin"] = "Manual", ["state"] = "Running", ["started_at"] = 0L },
changes);
public Dictionary<string, object?> ItemRow(long runId, params (string Column, object? Value)[] changes) => Row(
new()
{
["run_id"] = runId,
["media_id"] = MartaMedia,
["account_id"] = Marta,
["source_sha256"] = Make.Sha(1),
["variant"] = "Whole",
["format"] = "Original",
["frame_at_ms"] = null,
["state"] = "Pending",
},
changes);
public static Dictionary<string, object?> AnalysisRow(params (string Column, object? Value)[] changes) => Row(
new() { ["sha256"] = Make.Sha(5), ["algorithm"] = 1L, ["outcome"] = "Still", ["analyzed_at"] = 0L },
changes);
public Dictionary<string, object?> ConversionRow(params (string Column, object? Value)[] changes) => Row(
new() { ["media_id"] = MartaMedia, ["format"] = "Jpg", ["state"] = "Pending", ["source_sha256"] = Make.Sha(1), ["created_at"] = 0L },
changes);
/// <summary>Inserts a raw row and returns its rowid.</summary>
public static Task<long> InsertAsync(FebeDatabase db, string table, IReadOnlyDictionary<string, object?> row) =>
db.WriteAsync(
w =>
{
var c = w.Command($"INSERT INTO {table} ({string.Join(", ", row.Keys)}) VALUES ({string.Join(", ", row.Keys.Select(k => "@" + k))})");
foreach (var (column, value) in row)
{
c.With("@" + column, value);
}
c.ExecuteNonQuery();
return w.LastInsertRowId();
},
default);
/// <summary>The row breaks a constraint (SQLITE_CONSTRAINT) and is not written.</summary>
public static async Task RejectedAsync(FebeDatabase db, string table, IReadOnlyDictionary<string, object?> row, string because)
{
var error = await Assert.ThrowsExactlyAsync<SqliteException>(() => InsertAsync(db, table, row), because);
Assert.AreEqual(19, error.SqliteErrorCode, because);
}
public static Task<int> ExecuteAsync(FebeDatabase db, string sql, params (string Name, object? Value)[] parameters) =>
db.WriteAsync(
w =>
{
var c = w.Command(sql);
foreach (var (name, value) in parameters)
{
c.With(name, value);
}
return c.ExecuteNonQuery();
},
default);
public static Task<long> ScalarAsync(FebeDatabase db, string sql, params (string Name, object? Value)[] parameters) =>
db.ReadAsync(
c =>
{
var command = c.Command(sql);
foreach (var (name, value) in parameters)
{
command.With(name, value);
}
return command.ScalarInt64();
},
default);
public static Task<long> ForeignKeyProblemsAsync(FebeDatabase db) => ScalarAsync(db, "SELECT COUNT(*) FROM pragma_foreign_key_check");
private static Dictionary<string, object?> Row(Dictionary<string, object?> row, (string Column, object? Value)[] changes)
{
foreach (var (column, value) in changes)
{
row[column] = value;
}
return row;
}
}