Class TableSyncService
Synchronizes database table schema with entity class definitions. Uses CL.MySQL2.Core.SchemaAnalyzer to detect and apply CREATE/ALTER TABLE statements.
public sealed class TableSyncService
- Inheritance
-
TableSyncService
- Inherited Members
Constructors
TableSyncService(ConnectionManager, string, ILogger?, IEventBus?, Func<string, MySqlDatabaseConfig?>?)
public TableSyncService(ConnectionManager connectionManager, string dataDirectory, ILogger? logger = null, IEventBus? events = null, Func<string, MySqlDatabaseConfig?>? configLookup = null)
Parameters
connectionManagerConnectionManagerThe connection manager to use for database access.
dataDirectorystringBase data directory (for backup and migration storage).
loggerILoggerOptional logger.
eventsIEventBusOptional event bus for publishing sync events.
configLookupFunc<string, MySqlDatabaseConfig>Optional delegate resolving per-connection config so the service can read SchemaSyncLevel. When null, sync operates at Safe.
Methods
GetBackupManager()
Returns the BackupManager used by this service.
public BackupManager GetBackupManager()
Returns
GetMigrationTracker()
Returns the MigrationTracker used by this service.
public MigrationTracker GetMigrationTracker()
Returns
GetSchemaStateStore()
Returns the SchemaStateStore (the __schema_state sentinel).
public SchemaStateStore GetSchemaStateStore()
Returns
SyncTableAsync<T>(bool, string, CancellationToken)
Synchronizes the table schema for entity type T.
Creates the table if it doesn't exist, or alters it to add missing columns/indexes.
public Task<Result<SyncResult>> SyncTableAsync<T>(bool createBackup = true, string connectionId = "Default", CancellationToken ct = default) where T : class
Parameters
createBackupboolWhether to back up the current schema before making changes.
connectionIdstringThe connection ID to use.
ctCancellationTokenCancellation token.
Returns
- Task<Result<SyncResult>>
Type Parameters
T
SyncTablesAsync(IEnumerable<Type>, bool, string, CancellationToken)
Synchronizes multiple entity types as one pass. Brackets the whole pass in a single cross-node SchemaSyncLock, applies the CRC fast-path per table, and — in Migration — emits the "already current, switch back to Production" warning when nothing needed doing.
public Task<Result<Dictionary<string, SyncResult>>> SyncTablesAsync(IEnumerable<Type> entityTypes, bool createBackup = true, string connectionId = "Default", CancellationToken ct = default)
Parameters
entityTypesIEnumerable<Type>Entity types to sync.
createBackupboolWhether to back up schemas before altering.
connectionIdstringThe connection ID to use.
ctCancellationTokenCancellation token.
Returns
- Task<Result<Dictionary<string, SyncResult>>>