Ejemplo n.º 1
0
        public async Task ApplyAll(NpgsqlConnection conn, DdlRules rules, AutoCreate autoCreate, Action <string> logSql = null, Action <NpgsqlCommand, Exception> onFailure = null)
        {
            if (autoCreate == AutoCreate.None)
            {
                return;
            }
            if (Difference == SchemaPatchDifference.None)
            {
                return;
            }
            if (!_deltas.Any())
            {
                return;
            }

            var writer = new StringWriter();

            foreach (var schema in _schemas)
            {
                await writer.WriteLineAsync(CreateSchemaStatementFor(schema));
            }



            WriteAllUpdates(writer, rules, autoCreate);

            var cmd = conn.CreateCommand(writer.ToString());

            logSql?.Invoke(cmd.CommandText);

            try
            {
                await cmd
                .ExecuteNonQueryAsync();
            }
            catch (Exception e)
            {
                if (onFailure != null)
                {
                    onFailure(cmd, e);
                }
                else
                {
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public void WriteAllRollbacks(TextWriter writer, DdlRules rules)
        {
            foreach (var delta in _deltas)
            {
                switch (delta.Difference)
                {
                case SchemaPatchDifference.None:
                    continue;

                case SchemaPatchDifference.Create:
                    delta.SchemaObject.WriteDropStatement(rules, writer);
                    break;

                case SchemaPatchDifference.Update:
                    delta.WriteRollback(rules, writer);
                    break;

                case SchemaPatchDifference.Invalid:
                    delta.SchemaObject.WriteDropStatement(rules, writer);
                    delta.WriteRestorationOfPreviousState(rules, writer);
                    break;
                }
            }
        }
Ejemplo n.º 3
0
 public void WriteRestorationOfPreviousState(DdlRules rules, TextWriter writer)
 {
     Actual.WriteCreateStatement(rules, writer);
 }
Ejemplo n.º 4
0
 public virtual void WriteRollback(DdlRules rules, TextWriter writer)
 {
     Expected.WriteDropStatement(rules, writer);
     Actual.WriteCreateStatement(rules, writer);
 }
Ejemplo n.º 5
0
 public abstract void WriteUpdate(DdlRules rules, TextWriter writer);
Ejemplo n.º 6
0
 public void WriteDropStatement(DdlRules rules, TextWriter writer)
 {
     writer.WriteLine($"DROP EXTENSION IF EXISTS {ExtensionName} CASCADE;");
 }
Ejemplo n.º 7
0
 public void WriteCreateStatement(DdlRules rules, TextWriter writer)
 {
     writer.WriteLine($"CREATE EXTENSION IF NOT EXISTS {ExtensionName};");
 }
Ejemplo n.º 8
0
 public void WriteDropStatement(DdlRules rules, TextWriter writer)
 {
     writer.WriteLine($"DROP SEQUENCE IF EXISTS {Identifier};");
 }