E4: video_analysis con istante del fotogramma e nota (migrazione 0005)
«Salva il fotogramma» deve salvare il fotogramma scelto dall'analisi (il più nitido, mai uno nero) e il visualizzatore deve dire perché un video è «Non analizzabile». La migrazione 0005 aggiunge a video_analysis frame_at_ms e note, con i CHECK nello schema: un «Fermo» ha sempre il suo istante e nessun altro esito ne ha uno, un «Non analizzabile» ha sempre la nota. Un indice parziale sugli esiti fermi serve al filtro «Video fermi». Le righe impossibili (scritte a mano: nessun Febe prima di E4 scrive la tabella) si tolgono prima, così la migrazione non si ferma. VideoAnalysis ha FrameAt e Note; VideoAnalysisNotes elenca i codici, compreso SingleColor per il video tutto di un colore (risposta 42 di Alberto: tutto nero o di un colore è «Non analizzabile»). L'archivio legge e scrive le colonne nuove e rifiuta le forme che lo schema rifiuta, e una nota che non sia fatta di codici. Prove: versione dello schema 5, aggiornamento dalla 4, la 0005 cambia solo video_analysis, vincoli e archivio. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b3c15da821
commit
0cd842a518
8 files changed
+278
-20
No files matched your search
@@ -37,6 +37,8 @@ public sealed class MigrationTests
|
||||
Assert.AreEqual("schema", migrations[0].Name);
|
||||
Assert.AreEqual("ordine_scaricamento", migrations[1].Name);
|
||||
Assert.AreEqual("esportazione", migrations[2].Name);
|
||||
Assert.AreEqual("esportazione_filtro", migrations[3].Name);
|
||||
Assert.AreEqual("video_fermi", migrations[4].Name);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -167,6 +169,9 @@ public sealed class MigrationTests
|
||||
[TestMethod]
|
||||
public async Task DatabaseAtVersion3IsUpgradedWithForeignKeysClean() => await UpgradeKeepsEverything(3);
|
||||
|
||||
[TestMethod]
|
||||
public async Task DatabaseAtVersion4IsUpgradedWithForeignKeysClean() => await UpgradeKeepsEverything(4);
|
||||
|
||||
[TestMethod]
|
||||
public void MigrationThreeChangesNoExistingTable()
|
||||
{
|
||||
@@ -213,6 +218,68 @@ public sealed class MigrationTests
|
||||
StringAssert.Contains(plan, "COVERING INDEX ix_media_sha256_entry", plan);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Migration 5 (tappa E4) adds to video_analysis only the columns frame_at_ms and note and the partial index of the
|
||||
/// still outcomes: every other table, column and index stays the same, and the «Video fermi» filter reads the index.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void MigrationFiveOnlyAddsTheFrameTheNoteAndTheStillIndex()
|
||||
{
|
||||
using var temp = new TempFolder();
|
||||
var path = temp.Combine("dati", FebeDatabase.FileName);
|
||||
var all = MigrationRunner.LoadEmbedded();
|
||||
Assert.IsGreaterThanOrEqualTo(5, all.Count);
|
||||
Close(FebeDatabase.Open(path, all.Take(4).ToList()));
|
||||
var tables = TablesOf(path);
|
||||
var others = tables.Where(t => t != "video_analysis").ToList();
|
||||
var before = SchemaOf(path, others);
|
||||
var shapesBefore = TableShapes(path, others);
|
||||
var columnsBefore = ColumnsOf(path, ["video_analysis"])["video_analysis"];
|
||||
|
||||
Close(FebeDatabase.Open(path, all.Take(5).ToList()));
|
||||
|
||||
CollectionAssert.AreEqual(tables, TablesOf(path), "nessuna tabella nuova");
|
||||
CollectionAssert.AreEqual(before, SchemaOf(path, others), "le altre tabelle non cambiano");
|
||||
CollectionAssert.AreEqual(shapesBefore, TableShapes(path, others), "colonne e indici delle altre tabelle restano gli stessi");
|
||||
CollectionAssert.AreEqual(
|
||||
columnsBefore.Concat(["frame_at_ms", "note"]).ToList(),
|
||||
ColumnsOf(path, ["video_analysis"])["video_analysis"],
|
||||
"due colonne in fondo");
|
||||
var indexes = TableShapes(path, ["video_analysis"]).Where(s => s.Contains(" index ", StringComparison.Ordinal)).ToList();
|
||||
CollectionAssert.Contains(indexes, "video_analysis index ix_video_analysis_still 0 c 1", string.Join(" | ", indexes));
|
||||
using var connection = Connect(path);
|
||||
var plan = string.Join(" | ", ReadColumn(connection,
|
||||
"EXPLAIN QUERY PLAN SELECT m.entry_id FROM video_analysis va JOIN media m ON m.sha256 = va.sha256 WHERE va.outcome = 'Still'", 3));
|
||||
StringAssert.Contains(plan, "ix_video_analysis_still", plan);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// No Febe before tappa E4 wrote video_analysis; a row written there by hand anyway does not stop migration 5: an
|
||||
/// «In movimento» stays, a «Fermo» without its instant and a «Non analizzabile» without its reason go.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void MigrationFiveKeepsOnlyTheRowsItCanKeep()
|
||||
{
|
||||
using var temp = new TempFolder();
|
||||
var path = temp.Combine("dati", FebeDatabase.FileName);
|
||||
var all = MigrationRunner.LoadEmbedded();
|
||||
Close(FebeDatabase.Open(path, all.Take(4).ToList()));
|
||||
using (var connection = Connect(path))
|
||||
{
|
||||
connection.Command($"""
|
||||
INSERT INTO video_analysis (sha256, algorithm, outcome, analyzed_at)
|
||||
VALUES ('{Make.Sha(1)}', 1, 'Still', 1000), ('{Make.Sha(2)}', 1, 'Moving', 2000), ('{Make.Sha(3)}', 1, 'NotAnalyzable', 3000);
|
||||
""").ExecuteNonQuery();
|
||||
}
|
||||
|
||||
Close(FebeDatabase.Open(path, all));
|
||||
|
||||
using var after = Connect(path);
|
||||
var rows = ReadColumn(after, "SELECT sha256 || ' ' || outcome || ' ' || analyzed_at || ' ' || ifnull(frame_at_ms, '-') || ' ' || ifnull(note, '-') FROM video_analysis", 0);
|
||||
CollectionAssert.AreEqual(new[] { $"{Make.Sha(2)} Moving 2000 - -" }, rows);
|
||||
Assert.AreEqual("ok", after.Command("PRAGMA integrity_check").ExecuteScalar());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task DatabaseOneVersionNewerIsRefusedAndLeftUntouched()
|
||||
{
|
||||
@@ -251,7 +318,7 @@ public sealed class MigrationTests
|
||||
await using (var db = FebeDatabase.Open(path, all))
|
||||
{
|
||||
Assert.AreEqual(all.Count, db.SchemaVersion);
|
||||
Assert.AreEqual(4, db.SchemaVersion);
|
||||
Assert.AreEqual(5, db.SchemaVersion);
|
||||
}
|
||||
|
||||
using var connection = Connect(path);
|
||||
|
||||
Reference in new issue
Block a user