Example #1
0
        public async Task ApplyAll(SqlConnection conn, DdlRules rules, AutoCreate autoCreate,
                                   Action <string> logSql = null, Action <SqlCommand, Exception> onFailure = null)
        {
            if (autoCreate == AutoCreate.None)
            {
                return;
            }

            if (Difference == SchemaPatchDifference.None)
            {
                return;
            }

            if (!_deltas.Any())
            {
                return;
            }

            var writer = new StringWriter();

            if (_schemas.Any())
            {
                SchemaGenerator.WriteSql(_schemas, writer);
            }


            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;
                }
            }
        }
Example #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;
                }
            }
        }
Example #3
0
 public void WriteRestorationOfPreviousState(DdlRules rules, TextWriter writer)
 {
     Actual.WriteCreateStatement(rules, writer);
 }
Example #4
0
 public virtual void WriteRollback(DdlRules rules, TextWriter writer)
 {
     Expected.WriteDropStatement(rules, writer);
     Actual.WriteCreateStatement(rules, writer);
 }
Example #5
0
 public abstract void WriteUpdate(DdlRules rules, TextWriter writer);
Example #6
0
 public void WriteDropStatement(DdlRules rules, TextWriter writer)
 {
     writer.WriteLine($"DROP SEQUENCE IF EXISTS {Identifier};");
 }
Example #7
0
 public void WriteDropStatement(DdlRules rules, TextWriter writer)
 {
     writer.WriteLine($"DROP EXTENSION IF EXISTS {ExtensionName} CASCADE;");
 }
Example #8
0
 public void WriteCreateStatement(DdlRules rules, TextWriter writer)
 {
     writer.WriteLine($"CREATE EXTENSION IF NOT EXISTS {ExtensionName};");
 }