예제 #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;
                }
            }
        }
예제 #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;
                }
            }
        }
예제 #3
0
 public void WriteRestorationOfPreviousState(DdlRules rules, TextWriter writer)
 {
     Actual.WriteCreateStatement(rules, writer);
 }
예제 #4
0
 public virtual void WriteRollback(DdlRules rules, TextWriter writer)
 {
     Expected.WriteDropStatement(rules, writer);
     Actual.WriteCreateStatement(rules, writer);
 }
예제 #5
0
 public abstract void WriteUpdate(DdlRules rules, TextWriter writer);
예제 #6
0
파일: Sequence.cs 프로젝트: JasperFx/weasel
 public void WriteDropStatement(DdlRules rules, TextWriter writer)
 {
     writer.WriteLine($"DROP SEQUENCE IF EXISTS {Identifier};");
 }
예제 #7
0
 public void WriteDropStatement(DdlRules rules, TextWriter writer)
 {
     writer.WriteLine($"DROP EXTENSION IF EXISTS {ExtensionName} CASCADE;");
 }
예제 #8
0
 public void WriteCreateStatement(DdlRules rules, TextWriter writer)
 {
     writer.WriteLine($"CREATE EXTENSION IF NOT EXISTS {ExtensionName};");
 }