Path: redb/redb.Core/Providers/ISchemeSyncProvider.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.Core/Providers/ISchemeSyncProvider.cs ---- using System; using System.Threading; using System.Threading.Tasks; using redb.Core.Caching; using redb.Core.Models.Contracts; using redb.Core.Models.Entities; using System.Collections.Generic; namespace redb.Core.Providers { /// /// Provider for scheme and structure management (Code-First). /// public interface ISchemeSyncProvider { /// /// Domain-bound metadata cache for this provider. /// GlobalMetadataCache Cache { get; } /// /// Domain-bound list cache for this provider. /// GlobalListCache ListCache { get; } /// /// Domain-bound props/object cache for this provider. /// GlobalPropsCache PropsCache { get; } // ===== METHODS WITH CONTRACTS ===== /// /// Create/get scheme by name from Props type. /// If schemeName = null, uses TProps class name. /// Task EnsureSchemeFromTypeAsync(CancellationToken cancellationToken = default) where TProps : class; /// /// Synchronize scheme structures from Props type (by default deletes extra fields). /// Task> SyncStructuresFromTypeAsync(IRedbScheme scheme, bool strictDeleteExtra = true, CancellationToken cancellationToken = default) where TProps : class; /// /// Simplified scheme synchronization method with auto-detection of name and alias. /// Scheme name and alias determined from RedbSchemeAttribute. /// Task SyncSchemeAsync(CancellationToken cancellationToken = default) where TProps : class; /// /// The structures of 's scheme that the class does not declare (fields it removed, /// or a newer build added), with their stored values. The sync keeps them unless the class raised /// ; this call deletes them on request, under the scheme lock, /// values included. With (the default) it only reports. Refused with /// when the class's version is lower than the database's. /// Task DropUnknownStructuresAsync(bool dryRun = true, CancellationToken cancellationToken = default) where TProps : class; // ===== SCHEME SEARCH ===== /// /// Get scheme by ID. /// Task GetSchemeByIdAsync(long schemeId, CancellationToken cancellationToken = default); /// /// Synchronous for the thread-pool-free load path (the synchronous /// Load<T> and lazy getters): every database call runs on the calling thread. There is no /// blocking fallback over the async form - it would bring the thread pool back into exactly that path. /// IRedbScheme? GetSchemeById(long schemeId) => throw new NotSupportedException( $"{GetType().Name} does not implement the synchronous GetSchemeById that the synchronous load path needs."); /// /// Get scheme by name. /// Task GetSchemeByNameAsync(string schemeName, CancellationToken cancellationToken = default); /// /// Get scheme by C# class type. /// Uses class name for scheme search. /// Task GetSchemeByTypeAsync(CancellationToken cancellationToken = default) where TProps : class; /// /// Get scheme from cache synchronously (no DB call). /// Returns null if not in cache. Use after InitializeAsync() to ensure cache is warm. /// IRedbScheme? GetSchemeFromCache() where TProps : class; /// /// Get scheme from cache synchronously (no DB call). /// Returns null if not in cache. /// IRedbScheme? GetSchemeFromCache(string schemeName); /// /// Get scheme by C# class type. /// Uses class name for scheme search. /// Task GetSchemeByTypeAsync(Type type, CancellationToken cancellationToken = default); /// /// Load scheme by C# class type (throws exception if not found). /// Task LoadSchemeByTypeAsync(CancellationToken cancellationToken = default) where TProps : class; /// /// Load scheme by C# class type (throws exception if not found). /// Task LoadSchemeByTypeAsync(Type type, CancellationToken cancellationToken = default); /// /// Get all schemes. /// Task> GetSchemesAsync(CancellationToken cancellationToken = default); /// /// Get scheme structures. /// Task> GetStructuresAsync(IRedbScheme scheme, CancellationToken cancellationToken = default); /// /// Get scheme structures by C# class type. /// Task> GetStructuresByTypeAsync(CancellationToken cancellationToken = default) where TProps : class; /// /// Get scheme structures by C# class type. /// Task> GetStructuresByTypeAsync(Type type, CancellationToken cancellationToken = default); // ===== SCHEME EXISTENCE CHECKS ===== /// /// Check if scheme exists for C# class type. /// Task SchemeExistsForTypeAsync(CancellationToken cancellationToken = default) where TProps : class; /// /// Check if scheme exists for C# class type. /// Task SchemeExistsForTypeAsync(Type type, CancellationToken cancellationToken = default); /// /// Check if scheme exists by name. /// Task SchemeExistsByNameAsync(string schemeName, CancellationToken cancellationToken = default); // ===== UTILITY METHODS ===== /// /// Get scheme name for C# class type. /// Considers attributes and namespaces. /// string GetSchemeNameForType() where TProps : class; /// /// Get scheme name for C# class type. /// Considers attributes and namespaces. /// string GetSchemeNameForType(Type type); /// /// Get scheme alias for C# class type. /// Extracts from RedbSchemeAttribute. /// string? GetSchemeAliasForType() where TProps : class; /// /// Get scheme alias for C# class type. /// Extracts from RedbSchemeAttribute. /// string? GetSchemeAliasForType(Type type); // ===== OBJECT SCHEME (NON-GENERIC) ===== /// /// Get or create scheme for Object type (without Props). /// Used for non-generic RedbObject that stores only base _objects fields. /// Scheme will have _type = Object (not Class). /// /// Scheme name (e.g. "RedbObject" or custom name) /// Cancels the operation (OCE only; a rollback in flight always completes). Task EnsureObjectSchemeAsync(string name, CancellationToken cancellationToken = default); /// /// Get scheme for Object type by name. /// Returns null if not found. /// Task GetObjectSchemeAsync(string name, CancellationToken cancellationToken = default); // ===== TYPE MIGRATION ===== /// /// Migrate data when changing structure type (e.g. String -> Long). /// Moves data from old type column to new type column. /// /// Structure ID to migrate /// Old type name (e.g. "String") /// New type name (e.g. "Long") /// If true, only returns count without actual migration /// Migration result with affected rows count /// Cancels the operation (OCE only; a rollback in flight always completes). Task MigrateStructureTypeAsync(long structureId, string oldTypeName, string newTypeName, bool dryRun = false, CancellationToken cancellationToken = default); /// /// Recompute the stored unique keys of one [RedbUnique] property and report duplicates /// (rows left outside the unique index). The automatic triggers run the same algorithm at /// scheme synchronisation; this is the explicit form (UNIQUE plan 2.8). /// Task RecomputeUniqueAsync(string propertyName, CancellationToken cancellationToken = default) where TProps : class; // ===== STRUCTURE TREE CACHE ===== /// /// Get structure tree for scheme (cached). /// Task> GetStructureTreeAsync(long schemeId, CancellationToken cancellationToken = default); /// /// Get subtree starting from parent structure (cached). /// Task> GetSubtreeAsync(long schemeId, long? parentStructureId, CancellationToken cancellationToken = default); /// /// Invalidate structure tree cache for scheme. /// void InvalidateStructureTreeCache(long schemeId); /// /// Get structure tree cache statistics. /// (int TreesCount, int SubtreesCount, long MemoryEstimate) GetStructureTreeCacheStats(); } /// /// Result of data type migration. /// public class TypeMigrationResult { public int AffectedRows { get; set; } public int SuccessCount { get; set; } public int ErrorCount { get; set; } public string? Errors { get; set; } } }