示例#1
0
        private bool ApplyMigration(Migration migration, ClickHouseNode node, ClickHouseConnection connection)
        {
            _logger.LogInformation($"Applying {migration}...");

            var success = migration.Process(node, connection) && ClickHouseDbProvider.MakeMigrationRecord(connection, migration.DbEntity, _migrationSettings.MigrationsTableName);

            if (success)
            {
                _logger.LogInformation($"{migration} applied");
            }
            else
            {
                _logger.LogError($"Can't apply {migration}");
            }

            return(success);
        }
示例#2
0
        private bool TryApplyMigrations(ClickHouseNode node, Assembly assembly)
        {
            try
            {
                using (var connection = new ClickHouseConnection(node.ConnectionSettings))
                {
                    _logger.LogInformation($"Applying migrations for the node {node.Name}");
                    connection.Open();
                    ClickHouseDbProvider.CreateMigrationTableIfNotExists(connection,
                                                                         _migrationSettings.MigrationsTableName);

                    var migrations        = _locator.Locate(assembly);
                    var appliedMigrations =
                        ClickHouseDbProvider.GetAppliedMigrations(connection, _migrationSettings.MigrationsTableName);

                    var notAppliedMigrations = GetNotAppliedMigrations(migrations.ToList(), appliedMigrations).ToList();

                    _logger.LogInformation(
                        $"Not applied migrations:{Environment.NewLine}{string.Join(Environment.NewLine, notAppliedMigrations.Select(m => m.ToString()))}");

                    var success = TryApplyMigrations(notAppliedMigrations, node, connection);
                    if (success)
                    {
                        _logger.LogInformation($"All migrations for the node {node.Name} successfully applied");
                    }
                    else
                    {
                        _logger.LogError($"Migrations for {node.Name} were not applied");
                    }

                    return(success);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Migration applying error.");
                return(false);
            }
        }
示例#3
0
        private bool TryApplyMigrations(IEnumerable <Migration> notAppliedMigrations, ClickHouseNode node, ClickHouseConnection connection)
        {
            foreach (var migration in notAppliedMigrations)
            {
                try
                {
                    if (!ApplyMigration(migration, node, connection))
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, $"Exception was thrown while trying to apply {migration.DbEntity}");
                    return(false);
                }
            }

            return(true);
        }
示例#4
0
 /// <summary>
 /// Processing method for applying the migration.
 /// </summary>
 /// <param name="node">Node over which migration will be applied.</param>
 /// <param name="connection">OPENED connection to DB.</param>
 /// <returns>Was processing successful or not.</returns>
 public abstract bool Process([NotNull] ClickHouseNode node, [NotNull] ClickHouseConnection connection);