Пример #1
0
        private async Task MigrateAsync(
            MyCatDatabaseHost node,
            string targetMigration = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var connection = _connection.CreateNodeConnection(node);

            _logger.LogDebug(RelationalStrings.UsingConnection(connection.DbConnection.Database, connection.DbConnection.DataSource));

            if (!await _historyRepository.ExistsAsync(connection, cancellationToken))
            {
                if (!await _databaseCreator.ExistsAsync(connection, cancellationToken))
                {
                    await _databaseCreator.CreateAsync(node, cancellationToken);
                }

                var command = _rawSqlCommandBuilder.Build(_historyRepository.GetCreateScript());

                await command.ExecuteNonQueryAsync(connection, cancellationToken : cancellationToken);
            }

            var commandLists = GetMigrationCommandLists(
                await _historyRepository.GetAppliedMigrationsAsync(connection, cancellationToken),
                targetMigration);

            foreach (var commandList in commandLists)
            {
                await _migrationCommandExecutor.ExecuteNonQueryAsync(commandList(), connection, cancellationToken);
            }
        }
Пример #2
0
 public async Task <bool> ExistsAsync(MyCatRelationalConnection conn, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await _databaseCreator.ExistsAsync(conn, cancellationToken) &&
            InterpretExistsResult(
                await _rawSqlCommandBuilder.Build(ExistsSql).ExecuteScalarAsync(conn, cancellationToken: cancellationToken)));
 }