using Flypaper.Storage; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Shouldly; namespace Flypaper.Tests.Storage; public sealed class MigrationTests : IDisposable { private readonly string _dbPath = Path.Combine(Path.GetTempPath(), $"flypaper-migration-{Guid.NewGuid():N}.db"); [Fact] public async Task Removes_obsolete_drip_interval_override_from_existing_databases() { await using var db = new FlypaperDbContext(new DbContextOptionsBuilder().UseSqlite($"Data Source={_dbPath}").Options); var migrator = db.GetService(); await migrator.MigrateAsync("AddOrigin"); await db.Database.ExecuteSqlRawAsync( "INSERT INTO \"Settings\" (\"Key\", \"Value\") VALUES ('Flypaper:Drip:Interval', '00:00:10'), ('Flypaper:MaxConnections', '50')"); await db.Database.MigrateAsync(); (await db.Settings.Select(s => s.Key).ToListAsync()).ShouldBe(["Flypaper:MaxConnections"]); } public void Dispose() { SqliteConnection.ClearAllPools(); foreach (var suffix in new[] { "", "-wal", "-shm" }) { File.Delete(_dbPath + suffix); } } }