public static VimSchema Create(Document doc) { var r = new VimSchema(); r.Version = doc.Header.ObjectModelVersion.ToString(); foreach (var et in doc.EntityTables.Values.ToEnumerable()) { var t = new Table() { Name = et.Name.SimplifiedName() }; r.Tables.Add(t); foreach (var c in et.IndexColumns.Values.ToEnumerable()) { t.AddColumn(c.Name, ColumnType.Index); } foreach (var c in et.NumericColumns.Values.ToEnumerable()) { t.AddColumn(c.Name, ColumnType.Numeric); } foreach (var c in et.StringColumns.Values.ToEnumerable()) { t.AddColumn(c.Name, ColumnType.String); } } return(r); }
public VimSchema AddedOrChanged(VimSchema previous, bool changedOnly) { var r = new VimSchema(); r.Version = $"{previous.Version} => {Version}"; foreach (var t in Tables) { var previousTable = previous.FindTable(t.Name); if (previousTable == null && !changedOnly) { r.Tables.Add(t); } else if (previousTable != null) { var newTable = new Table() { Name = t.Name }; foreach (var c in t.Columns) { var previousColumn = previousTable.FindColumn(c.Name); if (previousColumn == null && !changedOnly) { newTable.Columns.Add(c); } if (previousColumn != null && changedOnly && c.Type != previousColumn.Type) { newTable.Columns.Add(c); } } // If there are any new columns if (newTable.Columns.Count > 0) { r.Tables.Add(newTable); } } } return(r); }
public static bool SameSchema(VimSchema vim1, VimSchema vim2) => vim1.IsSame(vim2);
public bool IsSame(VimSchema vs) => Added(vs).Tables.Count == 0 && Removed(vs).Tables.Count == 0 && Modified(vs).Tables.Count == 0;
public VimSchema Modified(VimSchema previous) => AddedOrChanged(previous, true);
public VimSchema Removed(VimSchema previous) => previous.Added(this);
public VimSchema Added(VimSchema previous) => AddedOrChanged(previous, false);