Path: redb/redb.Tests.Integration/Tests/Sqlite/SqliteIndexRepairTests.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/Sqlite/SqliteIndexRepairTests.cs
----
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.DependencyInjection;
using redb.Core.Extensions;
using redb.Core.Models.Configuration;
using redb.SQLite.Data;
using redb.SQLite.Extensions;
using redb.Tests.Integration.Fixtures;
using redb.Tests.Integration.Tests.Base;
namespace redb.Tests.Integration.Tests.Sqlite;
/// The index check and its repair on a SQLite file, see .
public class SqliteIndexRepairTests : IndexRepairTestsBase
{
private readonly Dictionary _files = new();
protected override Task CreateDatabaseAsync(string name)
{
SqliteDataSource.NativeExtensionPath ??= SqliteTestSupport.ResolveNativeExtension();
var path = Path.Combine(Path.GetTempPath(), name + ".db");
_files[name] = path;
return Task.FromResult($"Data Source={path}");
}
protected override Task DropDatabaseAsync(string name)
{
SqliteConnection.ClearAllPools();
if (_files.TryGetValue(name, out var path))
foreach (var file in new[] { path, path + "-wal", path + "-shm" })
{
try { if (File.Exists(file)) File.Delete(file); }
catch (IOException) { }
}
return Task.CompletedTask;
}
protected override void AddRedb(IServiceCollection services, string connectionString, Action configure)
=> services.AddRedb(o => o.UseSqlite(connectionString).Configure(configure));
protected override string DropIndexSql(string table, string index) => $"DROP INDEX \"{index}\"";
protected override string CreateOtherIndexSql(string index) => $"CREATE INDEX \"{index}\" ON _objects (_note)";
}