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