Table of Contents

Class TableSyncService

Namespace
CL.MySQL2.Services
Assembly
CL.MySQL2.dll

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

connectionManager ConnectionManager

The connection manager to use for database access.

dataDirectory string

Base data directory (for backup and migration storage).

logger ILogger

Optional logger.

events IEventBus

Optional event bus for publishing sync events.

configLookup Func<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

BackupManager

GetMigrationTracker()

Returns the MigrationTracker used by this service.

public MigrationTracker GetMigrationTracker()

Returns

MigrationTracker

GetSchemaStateStore()

Returns the SchemaStateStore (the __schema_state sentinel).

public SchemaStateStore GetSchemaStateStore()

Returns

SchemaStateStore

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

createBackup bool

Whether to back up the current schema before making changes.

connectionId string

The connection ID to use.

ct CancellationToken

Cancellation 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

entityTypes IEnumerable<Type>

Entity types to sync.

createBackup bool

Whether to back up schemas before altering.

connectionId string

The connection ID to use.

ct CancellationToken

Cancellation token.

Returns

Task<Result<Dictionary<string, SyncResult>>>