public DbDiffChangeLoggerContext(DbDiffOptions opts, IMessageLogger logger, DbDiffOptsLogger ltype) { m_opts = opts; m_ltype = ltype; m_oldValue = m_opts.DiffLogger; m_opts.SetLogger(m_ltype, logger); }
public override void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> replacement, AlterPlan plan) { if (!caps.PermuteColumns) { TransformToRecreateTable(caps, replacement, plan); } }
public override void AddLogicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> before, List <AlterOperation> after, AlterPlan plan) { base.AddLogicalDependencies(caps, opts, before, after, plan); var pk = OldObject as PrimaryKeyInfo; if (pk != null) { foreach (var col in pk.Columns) { foreach (var fk in ParentTable.GetReferences()) { bool fkdeleted = false; for (int i = 0; i < fk.RefColumns.Count; i++) { if (fk.RefColumns[i].Name == col.Name) { fkdeleted = true; break; } } if (fkdeleted) { opts.AlterLogger.Warning(String.Format("Dropped reference {0} on table {1}", fk.ConstraintName, fk.OwnerTable.FullName)); before.Add(new AlterOperation_DropConstraint { ParentTable = ParentTable, OldObject = fk }); } } } } }
public static bool EqualTypes(ColumnInfo a, ColumnInfo b, DbDiffOptions opts) { if (a.DataType != b.DataType) { opts.DiffLogger.Trace("Column {0}, {1}: different types: {2}; {3}", a, b, a.DataType, b.DataType); return(false); } //if (a.Length != b.Length) //{ // opts.DiffLogger.Trace("Column {0}, {1}: different lengths: {2}; {3}", a, b, a.Length, b.Length); // return false; //} //if (a.Precision != b.Precision) //{ // opts.DiffLogger.Trace("Column {0}, {1}: different lengths: {2}; {3}", a, b, a.Precision, b.Precision); // return false; //} //if (a.Scale != b.Scale) //{ // opts.DiffLogger.Trace("Column {0}, {1}: different scale: {2}; {3}", a, b, a.Scale, b.Scale); // return false; //} return(true); }
public DbDiffChangeLoggerContext(DbDiffOptions opts, IMessageLogger logger, DbDiffOptsLogger ltype) { m_opts = opts; m_ltype = ltype; m_oldValue = m_opts.DiffLogger; m_opts.SetLogger(m_ltype, logger); }
//public void EndFixedOrder() //{ // m_fixedOrderCounter++; //} //public void BeginFixedOrder() //{ // m_fixedOrderCounter--; //} public void AddLogicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts) { for (int index = 0; index < Operations.Count; index++) { var before = new List <AlterOperation>(); var after = new List <AlterOperation>(); Operations[index].AddLogicalDependencies(caps, opts, before, after, this); Operations.InsertRange(index, before); index += before.Count; Operations.InsertRange(index + 1, after); index += after.Count; } for (int index = Operations.Count - 1; index >= 0; index--) { for (int j = index - 1; j >= 0; j--) { if (Operations[index].IsDuplicateOf(Operations[j])) { Operations.RemoveAt(index); break; } } } }
public override void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> replacement, AlterPlan plan) { //if (!caps[OldObject).ObjectType].Change) //{ plan.RecreateObject(OldObject, NewObject); replacement.Clear(); //} }
public static bool EqualFullNames(NameWithSchema lft, NameWithSchema rgt, DbDiffOptions options) { if (lft == null || rgt == null) { return(lft == rgt); } return(EqualSchemas(lft.Schema, rgt.Schema, options) && EqualNames(lft.Name, rgt.Name, options)); }
public override void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> replacement, AlterPlan plan) { var c = GetConstraintCaps(caps, OldObject); if (!c.Drop) { TransformToRecreateTable(caps, replacement, plan); } }
public static bool EqualTables(TableInfo tsrc, TableInfo tdst, DbDiffOptions options, DbObjectPairing pairing, bool testNames) { if (options.IgnoreColumnOrder) { if (tsrc.Columns.Count != tdst.Columns.Count) { return(false); } foreach (var scol in tsrc.Columns) { var dcol = (from c in tdst.Columns where c.GroupId == scol.GroupId select c).FirstOrDefault(); if (dcol == null) { return(false); } using (var ctx = new DbDiffChangeLoggerContext(options, NopMessageLogger.Instance, DbDiffOptsLogger.DiffLogger)) { if (!EqualsColumns(scol, dcol, true, true, options, pairing)) { return(false); } } } } else { using (var ctx = new DbDiffChangeLoggerContext(options, NopMessageLogger.Instance, DbDiffOptsLogger.DiffLogger)) { if (!tsrc.Columns.EqualSequence(tdst.Columns, (c1, c2) => EqualsColumns(c1, c2, true, true, options, pairing))) { return(false); } } } var csrc = new List <ConstraintInfo>(tsrc.Constraints); var cdst = new List <ConstraintInfo>(tdst.Constraints); csrc.Sort(CompareConstraints); cdst.Sort(CompareConstraints); if (!csrc.EqualSequence(cdst, (c1, c2) => EqualsConstraints(c1, c2, options, true, pairing))) { return(false); } if (testNames && !EqualFullNames(tsrc.FullName, tdst.FullName, options)) { return(false); } if (GetTableAlteredOptions(tsrc, tdst, options).Count > 0) { return(false); } return(true); }
public DatabaseDiff(DatabaseInfo src, DatabaseInfo dst, DbDiffOptions options, IDatabaseFactory factory) { _factory = factory; _src = src.CloneDatabase(); _dst = dst.CloneDatabase(); _actions = new DbDiffAction(this); //m_actions = new DiffActionDatabase(this, m_src, m_dst); _options = options; RebuildGroupIdDictionary(); if (_src.GroupId != _dst.GroupId) CreatePairing(); CreateActions(); }
public override void Run(IAlterProcessor proc, DbDiffOptions opts) { var newtbl = ParentTable.CloneTable(); var dbs = new DatabaseInfo(); dbs.Tables.Add(newtbl); foreach (var op in AlterTableOps) { op.Run(new DatabaseInfoAlterProcessor(dbs), opts); } proc.RecreateTable(ParentTable, newtbl); opts.AlterLogger.Info(String.Format("Recreated table {0}", ParentTable.FullName)); }
public override void Run(IAlterProcessor proc, DbDiffOptions opts) { base.Run(proc, opts); if (Data != null) { if (Data.MainChanges != null) { proc.UpdateData((TableInfo)NewObject, Data.MainChanges, null); } if (Data.LinkedChanges != null) { proc.UpdateData(Data.LinkedChanges, null); } } }
public DatabaseDiff(DatabaseInfo src, DatabaseInfo dst, DbDiffOptions options, IDatabaseFactory factory) { _factory = factory; _src = src.CloneDatabase(); _dst = dst.CloneDatabase(); _actions = new DbDiffAction(this); //m_actions = new DiffActionDatabase(this, m_src, m_dst); _options = options; RebuildGroupIdDictionary(); if (_src.GroupId != _dst.GroupId) { CreatePairing(); } CreateActions(); }
public override void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> replacement, AlterPlan plan) { replacement.Clear(); replacement.Add(this); var table = (TableInfo)NewObject; foreach (var fk in new List <ForeignKeyInfo>(table.ForeignKeys)) { table.ForeignKeys.Remove(fk); fk.SetDummyTable(table.FullName); replacement.Add(new AlterOperation_CreateConstraint { NewObject = fk }); } }
public override void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> replacement, AlterPlan plan) { var c = GetConstraintCaps(caps, NewObject); if (!c.Change) { if (c.Create && c.Drop) { plan.RecreateObject(OldObject, NewObject); replacement.Clear(); } else { TransformToRecreateTable(caps, replacement, plan); } } }
public override void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> replacement, AlterPlan plan) { if (!caps.ChangeColumn) { TransformToRecreateTable(caps, replacement, plan); return; } if (!caps.ChangeAutoIncrement && ((ColumnInfo)OldObject).AutoIncrement != ((ColumnInfo)NewObject).AutoIncrement) { TransformToRecreateTable(caps, replacement, plan); return; } if (!caps.ChangeComputedColumnExpression && ((ColumnInfo)NewObject).ComputedExpression != null) { plan.RecreateObject(OldObject, NewObject); replacement.Clear(); } }
public override void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> replacement, AlterPlan plan) { var c = GetConstraintCaps(caps, OldObject); if (!c.Rename) { if (c.Create && c.Drop) { var newobj = OldObject.CloneObject(null); ((ConstraintInfo)newobj).ConstraintName = NewName.Name; plan.RecreateObject(OldObject, newobj); replacement.Clear(); } else { TransformToRecreateTable(caps, replacement, plan); } } }
public void Run(IAlterProcessor proc, DbDiffOptions opts) { //foreach (var dep in RecreatedItems) //{ // opts.AlterLogger.Info(Texts.Get("s_recreated_object$object", "object", dep.RecreatedObject)); //} //foreach (var cls in RecreatedItem.DropClassOrder) //{ // foreach (var dep in RecreatedItems) // { // if (dep.ItemClass != cls) continue; // dep.RunDrop(proc, opts); // } //} var dmp = proc as ISqlDumper; if (dmp != null) { dmp.AlterProlog(); dmp.BeginTransaction(); } foreach (var op in Operations) { op.Run(proc, opts); using (DbDiffChangeLoggerContext ctx = new DbDiffChangeLoggerContext(opts, NopMessageLogger.Instance, DbDiffOptsLogger.AlterLogger)) { if (op.MustRunOnParalelStructure()) { // run operation paralel on Structure, so that we have actual object names op.Run(new DatabaseInfoAlterProcessor(Structure), opts); } } } if (dmp != null) { dmp.CommitTransaction(); dmp.AlterEpilog(); } }
public override void AddLogicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> before, List <AlterOperation> after, AlterPlan plan) { var oldcol = OldObject as ColumnInfo; var newcol = NewObject as ColumnInfo; //var recreateFks = new List<ForeignKeyInfo>(); //var changeCols = new List<Tuple<ColumnInfo, ColumnInfo>>(); if (caps.DropConstraint) { foreach (var fk in ParentTable.GetReferences()) { for (int i = 0; i < fk.RefColumns.Count; i++) { if (fk.RefColumns[i].Name == oldcol.Name) { //plan.RecreateObject(fk, null); var table = fk.OwnerTable; var othercol = table.ColumnByName(fk.Columns[i].Name); // compare types with ignoring autoincrement flag // HACK: ignore specific attributes var opts2 = opts.Clone(); opts2.IgnoreSpecificData = true; if (!DbDiffTool.EqualTypes(othercol, newcol, opts2)) { var othercolNewType = othercol.CloneColumn(); CopyDataType(othercolNewType, newcol); after.Add(new AlterOperation_ChangeColumn { ParentTable = table, OldObject = othercol, NewObject = othercolNewType, }); } opts.AlterLogger.Warning(String.Format("Changed referenced column {0}.{1}", fk.OwnerTable.FullName, othercol.Name)); } } } } }
public static bool EqualSchemas(string lschema, string rschema, DbDiffOptions options) { if (options.SchemaMode == DbDiffSchemaMode.Ignore) { lschema = null; } if (options.SchemaMode == DbDiffSchemaMode.IngoreImplicit && lschema == options.LeftImplicitSchema) { lschema = null; } if (options.SchemaMode == DbDiffSchemaMode.Ignore) { rschema = null; } if (options.SchemaMode == DbDiffSchemaMode.IngoreImplicit && rschema == options.RightImplicitSchema) { rschema = null; } return(EqualNames(lschema, rschema, options)); }
public override void AddPhysicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> before, List <AlterOperation> after, AlterPlan plan) { var oldcol = OldObject as ColumnInfo; if (caps.DepCaps.ChangeColumn_Constraint || caps.DepCaps.ChangeColumn_Index) { foreach (var cnt in ParentTable.Constraints) { var cc = cnt as ColumnsConstraintInfo; if (cc == null) { continue; } if (cc.Columns.Any(c => c.Name == oldcol.Name)) { if ( (cc is IndexInfo && caps.DepCaps.ChangeColumn_Index) || (!(cc is IndexInfo) && caps.DepCaps.ChangeColumn_Constraint)) { plan.RecreateObject(cc, null); } } } } if (caps.DepCaps.ChangeColumn_Reference) { foreach (ForeignKeyInfo fk in ParentTable.GetReferences()) { for (int i = 0; i < fk.RefColumns.Count; i++) { if (fk.RefColumns[i].Name == oldcol.Name) { plan.RecreateObject(fk, null); } } } } }
public static bool EqualsColumns(ColumnInfo a, ColumnInfo b, bool checkName, bool checkDefault, DbDiffOptions opts, DbObjectPairing pairing) { if (checkName && !DbDiffTool.EqualNames(a.Name, b.Name, opts)) { opts.DiffLogger.Trace("Column, different name: {0}; {1}", a, b); return false; } //if (!DbDiffTool.EqualFullNames(a.Domain, b.Domain, opts)) //{ // opts.DiffLogger.Trace("Column {0}, {1}: different domain: {2}; {3}", a, b, a.Domain, b.Domain); // return false; //} if (a.ComputedExpression != b.ComputedExpression) { opts.DiffLogger.Trace("Column {0}, {1}: different computed expression: {2}; {3}", a, b, a.ComputedExpression, b.ComputedExpression); return false; } if (a.ComputedExpression != null) { return true; } if (checkDefault) { if (a.DefaultValue == null) { if (a.DefaultValue != b.DefaultValue) { opts.DiffLogger.Trace("Column {0}, {1}: different default values: {2}; {3}", a, b, a.DefaultValue, b.DefaultValue); return false; } } else { if (!a.DefaultValue.Equals(b.DefaultValue)) { opts.DiffLogger.Trace("Column {0}, {1}: different default values: {2}; {3}", a, b, a.DefaultValue, b.DefaultValue); return false; } } if (a.DefaultConstraint != b.DefaultConstraint) { opts.DiffLogger.Trace("Column {0}, {1}: different default constraint names: {2}; {3}", a, b, a.DefaultConstraint, b.DefaultConstraint); return false; } } if (a.NotNull != b.NotNull) { opts.DiffLogger.Trace("Column {0}, {1}: different nullable: {2}; {3}", a, b, a.NotNull, b.NotNull); return false; } if (a.AutoIncrement != b.AutoIncrement) { opts.DiffLogger.Trace("Column {0}, {1}: different autoincrement: {2}; {3}", a, b, a.AutoIncrement, b.AutoIncrement); return false; } if (a.IsSparse != b.IsSparse) { opts.DiffLogger.Trace("Column {0}, {1}: different is_sparse: {2}; {3}", a, b, a.IsSparse, b.IsSparse); return false; } if (!EqualTypes(a, b, opts)) { return false; } //var btype = b.DataType; //var atype = a.DataType; //if (pairing != null && pairing.Target != null && pairing.Source.Dialect != null) //{ // btype = pairing.Source.Dialect.MigrateDataType(b, btype, pairing.Source.Dialect.GetDefaultMigrationProfile(), null); // btype = pairing.Source.Dialect.GenericTypeToSpecific(btype).ToGenericType(); // // normalize type // atype = pairing.Source.Dialect.GenericTypeToSpecific(atype).ToGenericType(); //} //if (!EqualTypes(atype, btype, opts)) //{ // opts.DiffLogger.Trace("Column {0}, {1}: different types: {2}; {3}", a, b, a.DataType, b.DataType); // return false; //} //if (!opts.IgnoreColumnCollation && a.Collation != b.Collation) //{ // opts.DiffLogger.Trace("Column {0}, {1}: different collations: {2}; {3}", a, b, a.Collation, b.Collation); // return false; //} //if (!opts.IgnoreColumnCharacterSet && a.CharacterSet != b.CharacterSet) //{ // opts.DiffLogger.Trace("Column {0}, {1}: different character sets: {2}; {3}", a, b, a.CharacterSet, b.CharacterSet); // return false; //} return true; }
public static bool EqualsSpecificObjects(SpecificObjectInfo src, SpecificObjectInfo dst, DbDiffOptions options) { if (!EqualFullNames(src.FullName, dst.FullName, options)) return false; if (src.ObjectType != dst.ObjectType) return false; if (src.CreateSql == null || dst.CreateSql == null) { if (src.CreateSql != dst.CreateSql) return false; } else { //if (src.SpecificDialect == dst.SpecificDialect && src.SpecificDialect != null) //{ // var dialect = (ISqlDialect)DialectAddonType.Instance.FindHolder(src.SpecificDialect).CreateInstance(); // return dialect.EqualSpecificObjects(src.ObjectType, src.CreateSql, dst.CreateSql); //} //else //{ // if (src.CreateSql.Trim() != dst.CreateSql.Trim()) return false; //} if (src.CreateSql.Trim() != dst.CreateSql.Trim()) return false; } return true; }
public static bool EqualFullNames(NameWithSchema lft, NameWithSchema rgt, DbDiffOptions options) { if (lft == null || rgt == null) return lft == rgt; return EqualSchemas(lft.Schema, rgt.Schema, options) && EqualNames(lft.Name, rgt.Name, options); }
public static bool EqualTables(TableInfo tsrc, TableInfo tdst, DbDiffOptions options, DbObjectPairing pairing, bool testNames) { if (options.IgnoreColumnOrder) { if (tsrc.Columns.Count != tdst.Columns.Count) return false; foreach (var scol in tsrc.Columns) { var dcol = (from c in tdst.Columns where c.GroupId == scol.GroupId select c).FirstOrDefault(); if (dcol == null) return false; using (var ctx = new DbDiffChangeLoggerContext(options, NopMessageLogger.Instance, DbDiffOptsLogger.DiffLogger)) { if (!EqualsColumns(scol, dcol, true, true, options, pairing)) return false; } } } else { using (var ctx = new DbDiffChangeLoggerContext(options, NopMessageLogger.Instance, DbDiffOptsLogger.DiffLogger)) { if (!tsrc.Columns.EqualSequence(tdst.Columns, (c1, c2) => EqualsColumns(c1, c2, true, true, options, pairing))) return false; } } var csrc = new List<ConstraintInfo>(tsrc.Constraints); var cdst = new List<ConstraintInfo>(tdst.Constraints); csrc.Sort(CompareConstraints); cdst.Sort(CompareConstraints); if (!csrc.EqualSequence(cdst, (c1, c2) => EqualsConstraints(c1, c2, options, true, pairing))) return false; if (testNames && !EqualFullNames(tsrc.FullName, tdst.FullName, options)) return false; if (GetTableAlteredOptions(tsrc, tdst, options).Count > 0) return false; return true; }
/// alters table, decomposes to alter actions; doesn't transform alter plan /// proc must be able to run all logical operations public static void DecomposeAlterTable(this IAlterProcessor proc, TableInfo oldTable, TableInfo newTable, DbDiffOptions options) { DbObjectPairing pairing = CreateTablePairing(oldTable, newTable); // decompose to alter actions AlterPlan plan = new AlterPlan(oldTable.OwnerDatabase); AlterTable(plan, oldTable, newTable, options, pairing); var run = plan.CreateRunner(); run.Run(proc, options); }
public static bool GenerateRename(NameWithSchema oldName, NameWithSchema newName, Action<NameWithSchema, string> changeSchema, Action<NameWithSchema, string> rename, bool allowChangeSchema, bool allowRename, DbDiffOptions opts) { newName = GenerateNewName(oldName, newName, opts); if (DbDiffTool.EqualFullNames(oldName, newName, opts)) return true; if (!EqualSchemas(oldName.Schema, newName.Schema, opts) && !allowChangeSchema) return false; if (oldName.Name != newName.Name && !allowRename) return false; if (!EqualSchemas(oldName.Schema, newName.Schema, opts)) changeSchema(oldName, newName.Schema); if (oldName.Name != newName.Name) rename(new NameWithSchema(newName.Schema, oldName.Name), newName.Name); return true; }
public static void AlterDatabase(this IAlterProcessor proc, DatabaseInfo src, DatabaseInfo dst, DatabaseInfo targetDb, DbDiffOptions opts) { proc.AlterDatabase(src, dst, targetDb, opts, null); }
public static void AlterDatabase(this IAlterProcessor proc, DatabaseInfo src, DatabaseInfo dst, DatabaseInfo targetDb, DbDiffOptions opts, Action<AlterPlan> extendPlan) { AlterPlan plan = new AlterPlan(targetDb); DbDiffTool.AlterDatabase(plan, src, dst, opts); if (extendPlan != null) extendPlan(plan); plan.Transform(proc.AlterCaps, opts); var run = plan.CreateRunner(); run.Run(proc, opts); }
public static bool GenerateRenameSpecificObject(SpecificObjectInfo oldObj, NameWithSchema newName, Action<SpecificObjectInfo, string> changeSchema, Action<SpecificObjectInfo, string> rename, bool allowChangeSchema, bool allowRename, DbDiffOptions opts) { newName = GenerateNewName(oldObj.FullName, newName, opts); if (DbDiffTool.EqualFullNames(oldObj.FullName, newName, opts)) return true; if (!EqualSchemas(oldObj.FullName.Schema, newName.Schema, opts) && !allowChangeSchema) return false; if (oldObj.FullName.Name != newName.Name && !allowRename) return false; if (!EqualSchemas(oldObj.FullName.Schema, newName.Schema, opts)) changeSchema(oldObj, newName.Schema); if (oldObj.FullName.Name != newName.Name) { var tmpo = oldObj.CloneSpecificObject(); tmpo.FullName = new NameWithSchema(newName.Schema, oldObj.FullName.Name); rename(tmpo, newName.Name); } return true; }
public static void AlterSpecificObject(SpecificObjectInfo osrc, SpecificObjectInfo odst, AlterPlan plan, DbDiffOptions opts, DbObjectPairing pairing) { //bool altered = false; if (osrc.CreateSql == odst.CreateSql) { plan.RenameSpecificObject(osrc, odst.FullName); //altered = GenerateRename(osrc.ObjectName, odst.ObjectName, // (old, sch) => // { // var o2 = new SpecificObjectStructure(osrc); // o2.ObjectName = old; // proc.ChangeSpecificObjectSchema(o2, sch); // }, // (old, nam) => // { // var o2 = new SpecificObjectStructure(osrc); // o2.ObjectName = old; // proc.RenameSpecificObject(o2, nam); // }, caps[osrc.ObjectType].ChangeSchema, caps[osrc.ObjectType].Rename, opts); } else { plan.ChangeSpecificObject(osrc, odst); } //if (!altered) //{ // proc.DropSpecificObject(osrc); // SpecificObjectStructure odst2 = new SpecificObjectStructure(odst); // odst2.ObjectName = GenerateNewName(osrc.ObjectName, odst.ObjectName, opts); // proc.CreateSpecificObject(odst); //} }
public static bool EqualsConstraints(ConstraintInfo csrc, ConstraintInfo cdst, DbDiffOptions options, bool checkNames, DbObjectPairing pairing) { if (checkNames && !options.IgnoreConstraintNames) { if (!EqualNames(csrc.ConstraintName, cdst.ConstraintName, options)) { return(false); //if (csrc is PrimaryKeyInfo && cdst is PrimaryKeyInfo) // && (pairing.Source.Dialect.DialectCaps.AnonymousPrimaryKey || pairing.Target.Dialect.DialectCaps.AnonymousPrimaryKey)) //{ // // do nothing //} //else //{ // return false; //} } } if (csrc.GetType() != cdst.GetType()) { return(false); } if (csrc is IndexInfo srcIndex && cdst is IndexInfo dstIndex) { if (srcIndex.IsUnique != dstIndex.IsUnique) { return(false); } if (srcIndex.IndexType != dstIndex.IndexType) { return(false); } } if (csrc is ColumnsConstraintInfo) { TableInfo tsrc = pairing.Source.FindTable(csrc.OwnerTable.FullName); TableInfo tdst = pairing.Target.FindTable(cdst.OwnerTable.FullName); if (!EqualsColumnRefs(tsrc, tdst, ((ColumnsConstraintInfo)csrc).Columns, ((ColumnsConstraintInfo)cdst).Columns)) { return(false); } //if (!((ColumnsConstraint)csrc).Columns.EqualSequence(((ColumnsConstraint)cdst).Columns)) return false; if (csrc is ForeignKeyInfo) { var fsrc = (ForeignKeyInfo)csrc; var fdst = (ForeignKeyInfo)cdst; if (!EqualFullNames(fsrc.RefTableFullName, fdst.RefTableFullName, options)) { return(false); } TableInfo psrc = pairing.Source.FindTable(fsrc.RefTableFullName); TableInfo pdst = pairing.Target.FindTable(fdst.RefTableFullName); if (!EqualsColumnRefs(psrc, pdst, fsrc.RefColumns, fdst.RefColumns)) { return(false); } if (fsrc.OnDeleteAction != fdst.OnDeleteAction) { return(false); } if (fsrc.OnUpdateAction != fdst.OnUpdateAction) { return(false); } } //if (csrc is IIndex) //{ // var isrc = (IndexConstraint)csrc; // var idst = (IndexConstraint)cdst; // if (isrc.IsUnique != idst.IsUnique) return false; //} } //if (csrc is CheckConstraint) //{ // if (((CheckConstraint)csrc).Expression != ((CheckConstraint)cdst).Expression) return false; //} return(true); }
public static NameWithSchema GenerateNewName(NameWithSchema oldName, NameWithSchema newName, DbDiffOptions opts) { //if (oldName == null) //{ // if (opts.SchemaMode != DbDiffSchemaMode.Strict) return new NameWithSchema(null, newName.Name); // return newName; //} NameWithSchema res = oldName; if (!EqualSchemas(oldName.Schema, newName.Schema, opts)) res = new NameWithSchema(newName.Schema, res.Name); if (oldName.Name != newName.Name) res = new NameWithSchema(res.Schema, newName.Name); return res; }
public static bool EqualsSpecificObjects(SpecificObjectInfo src, SpecificObjectInfo dst, DbDiffOptions options) { if (!EqualFullNames(src.FullName, dst.FullName, options)) { return(false); } if (src.ObjectType != dst.ObjectType) { return(false); } if (src.CreateSql == null || dst.CreateSql == null) { if (src.CreateSql != dst.CreateSql) { return(false); } } else { //if (src.SpecificDialect == dst.SpecificDialect && src.SpecificDialect != null) //{ // var dialect = (ISqlDialect)DialectAddonType.Instance.FindHolder(src.SpecificDialect).CreateInstance(); // return dialect.EqualSpecificObjects(src.ObjectType, src.CreateSql, dst.CreateSql); //} //else //{ // if (src.CreateSql.Trim() != dst.CreateSql.Trim()) return false; //} if (src.CreateSql.Trim() != dst.CreateSql.Trim()) { return(false); } } return(true); }
public static Dictionary<string, string> GetDatabaseAlteredOptions(DatabaseInfo oldDb, DatabaseInfo newDb, DbDiffOptions opts) { Dictionary<string, string> alteredOptions = new Dictionary<string, string>(); if (opts.IgnoreAllDatabaseProperties) return alteredOptions; //foreach (string key in newDb.SpecificData.Keys) //{ // if (opts.IgnoreDatabaseProperties.Contains(key)) continue; // if (oldDb.SpecificData.Get(key) != newDb.SpecificData[key]) // alteredOptions[key] = newDb.SpecificData[key]; //} return alteredOptions; }
//public static bool EqualTypes(DbTypeBase t1, DbTypeBase t2, DbDiffOptions opts) //{ // if (!opts.IgnoreSpecificData && !t1.SpecificData.EqualsDictionary(t2.SpecificData, opts.IgnoreDataTypeProperties)) // { // opts.DiffLogger.Trace("Types {0}, {1}: different specific data: {2}; {3}", t1, t2, t1.SpecificData.Format(), t2.SpecificData.Format()); // return false; // } // if (t1.Code != t2.Code) // { // opts.DiffLogger.Trace("Types {0}, {1}: different type code: {2}; {3}", t1, t2, t1.Code, t2.Code); // return false; // } // if (!XmlTool.PropertiesEquals(t1, t2, opts.DiffLogger)) return false; // return true; //} public static bool EqualTables(TableInfo tsrc, TableInfo tdst, DbDiffOptions options, DbObjectPairing pairing) { return EqualTables(tsrc, tdst, options, pairing, true); }
public static void AlterDatabase(this IAlterProcessor proc, DatabaseInfo src, DatabaseInfo dst, DatabaseInfo targetDb, DbDiffOptions opts) { proc.AlterDatabase(src, dst, targetDb, opts, null); }
public static bool EqualSchemas(string lschema, string rschema, DbDiffOptions options) { if (options.SchemaMode == DbDiffSchemaMode.Ignore) lschema = null; if (options.SchemaMode == DbDiffSchemaMode.IngoreImplicit && lschema == options.LeftImplicitSchema) lschema = null; if (options.SchemaMode == DbDiffSchemaMode.Ignore) rschema = null; if (options.SchemaMode == DbDiffSchemaMode.IngoreImplicit && rschema == options.RightImplicitSchema) rschema = null; return EqualNames(lschema, rschema, options); }
//RenameSpecificObject public static void RenameObject(this IAlterProcessor proc, DatabaseObjectInfo obj, DbDiffOptions opts, NameWithSchema newName) { bool renameOk = false; //var dom = obj as IDomainStructure; //if (dom != null) //{ // renameOk = DbDiffTool.GenerateRename(dom.FullName, newName, // (old, sch) => proc.ChangeDomainSchema(old, sch), // (old, nam) => proc.RenameDomain(old, nam), // proc.AlterCaps.ChangeTableSchema, proc.AlterCaps.RenameDomain, opts); //} var tbl = obj as TableInfo; if (tbl != null) { renameOk = DbDiffTool.GenerateRename(tbl.FullName, newName, (old, sch) => proc.ChangeTableSchema(new TableInfo(null) {FullName = old}, sch), (old, nam) => proc.RenameTable(new TableInfo(null) {FullName = old}, nam), proc.AlterCaps.ChangeTableSchema, proc.AlterCaps.RenameTable, opts); } var col = obj as ColumnInfo; if (col != null) { if (proc.AlterCaps.RenameColumn) { proc.RenameColumn(col, newName.Name); renameOk = true; } } var cnt = obj as ConstraintInfo; if (cnt != null) { if (proc.AlterCaps.RenameConstraint) { proc.RenameConstraint(cnt, newName.Name); renameOk = true; } } var spec = obj as SpecificObjectInfo; if (spec != null) { renameOk = DbDiffTool.GenerateRenameSpecificObject(spec, newName, (old, sch) => proc.ChangeSpecificObjectSchema(old, sch), (old, nam) => proc.RenameSpecificObject(old, nam), proc.AlterCaps.GetSpecificObjectCaps(spec.ObjectType).ChangeSchema, proc.AlterCaps.GetSpecificObjectCaps(spec.ObjectType).Rename, opts); } if (!renameOk) throw new AlterNotPossibleError(); }
public static bool EqualsConstraints(ConstraintInfo csrc, ConstraintInfo cdst, DbDiffOptions options, bool checkNames, DbObjectPairing pairing) { if (checkNames && !options.IgnoreConstraintNames) { if (!EqualNames(csrc.ConstraintName, cdst.ConstraintName, options)) { return false; //if (csrc is PrimaryKeyInfo && cdst is PrimaryKeyInfo) // && (pairing.Source.Dialect.DialectCaps.AnonymousPrimaryKey || pairing.Target.Dialect.DialectCaps.AnonymousPrimaryKey)) //{ // // do nothing //} //else //{ // return false; //} } } if (csrc.GetType() != cdst.GetType()) return false; if (csrc is ColumnsConstraintInfo) { TableInfo tsrc = pairing.Source.FindTable(csrc.OwnerTable.FullName); TableInfo tdst = pairing.Target.FindTable(cdst.OwnerTable.FullName); if (!EqualsColumnRefs(tsrc, tdst, ((ColumnsConstraintInfo)csrc).Columns, ((ColumnsConstraintInfo)cdst).Columns)) return false; //if (!((ColumnsConstraint)csrc).Columns.EqualSequence(((ColumnsConstraint)cdst).Columns)) return false; if (csrc is ForeignKeyInfo) { var fsrc = (ForeignKeyInfo)csrc; var fdst = (ForeignKeyInfo)cdst; if (!EqualFullNames(fsrc.RefTableFullName, fdst.RefTableFullName, options)) return false; TableInfo psrc = pairing.Source.FindTable(fsrc.RefTableFullName); TableInfo pdst = pairing.Target.FindTable(fdst.RefTableFullName); if (!EqualsColumnRefs(psrc, pdst, fsrc.RefColumns, fdst.RefColumns)) return false; if (fsrc.OnDeleteAction != fdst.OnDeleteAction) return false; if (fsrc.OnUpdateAction != fdst.OnUpdateAction) return false; } //if (csrc is IIndex) //{ // var isrc = (IndexConstraint)csrc; // var idst = (IndexConstraint)cdst; // if (isrc.IsUnique != idst.IsUnique) return false; //} } //if (csrc is CheckConstraint) //{ // if (((CheckConstraint)csrc).Expression != ((CheckConstraint)cdst).Expression) return false; //} return true; }
public static Dictionary <string, string> GetTableAlteredOptions(TableInfo oldTable, TableInfo newTable, DbDiffOptions opts) { Dictionary <string, string> alteredOptions = new Dictionary <string, string>(); if (opts.IgnoreAllTableProperties) { return(alteredOptions); } //foreach (string key in newTable.SpecificData.Keys) //{ // if (opts.IgnoreTableProperties.Contains(key)) continue; // if (oldTable.SpecificData.Get(key) != newTable.SpecificData[key]) // alteredOptions[key] = newTable.SpecificData[key]; //} return(alteredOptions); }
public static bool EqualNames(string a, string b, DbDiffOptions opts) { return String.Compare(a, b, opts.IgnoreCase) == 0; }
//public static bool EqualTypes(DbTypeBase t1, DbTypeBase t2, DbDiffOptions opts) //{ // if (!opts.IgnoreSpecificData && !t1.SpecificData.EqualsDictionary(t2.SpecificData, opts.IgnoreDataTypeProperties)) // { // opts.DiffLogger.Trace("Types {0}, {1}: different specific data: {2}; {3}", t1, t2, t1.SpecificData.Format(), t2.SpecificData.Format()); // return false; // } // if (t1.Code != t2.Code) // { // opts.DiffLogger.Trace("Types {0}, {1}: different type code: {2}; {3}", t1, t2, t1.Code, t2.Code); // return false; // } // if (!XmlTool.PropertiesEquals(t1, t2, opts.DiffLogger)) return false; // return true; //} public static bool EqualTables(TableInfo tsrc, TableInfo tdst, DbDiffOptions options, DbObjectPairing pairing) { return(EqualTables(tsrc, tdst, options, pairing, true)); }
//RenameSpecificObject public static void RenameObject(this IAlterProcessor proc, DatabaseObjectInfo obj, DbDiffOptions opts, NameWithSchema newName) { bool renameOk = false; //var dom = obj as IDomainStructure; //if (dom != null) //{ // renameOk = DbDiffTool.GenerateRename(dom.FullName, newName, // (old, sch) => proc.ChangeDomainSchema(old, sch), // (old, nam) => proc.RenameDomain(old, nam), // proc.AlterCaps.ChangeTableSchema, proc.AlterCaps.RenameDomain, opts); //} var tbl = obj as TableInfo; if (tbl != null) { renameOk = DbDiffTool.GenerateRename(tbl.FullName, newName, (old, sch) => proc.ChangeTableSchema(new TableInfo(null) { FullName = old }, sch), (old, nam) => proc.RenameTable(new TableInfo(null) { FullName = old }, nam), proc.AlterCaps.ChangeTableSchema, proc.AlterCaps.RenameTable, opts); } var col = obj as ColumnInfo; if (col != null) { if (proc.AlterCaps.RenameColumn) { proc.RenameColumn(col, newName.Name); renameOk = true; } } var cnt = obj as ConstraintInfo; if (cnt != null) { if (proc.AlterCaps.RenameConstraint) { proc.RenameConstraint(cnt, newName.Name); renameOk = true; } } var spec = obj as SpecificObjectInfo; if (spec != null) { renameOk = DbDiffTool.GenerateRenameSpecificObject(spec, newName, (old, sch) => proc.ChangeSpecificObjectSchema(old, sch), (old, nam) => proc.RenameSpecificObject(old, nam), proc.AlterCaps.GetSpecificObjectCaps(spec.ObjectType).ChangeSchema, proc.AlterCaps.GetSpecificObjectCaps(spec.ObjectType).Rename, opts); } if (!renameOk) { throw new AlterNotPossibleError(); } }
public static void AlterDatabase(AlterPlan plan, DatabaseInfo src, DatabaseInfo dst, DbDiffOptions opts) { AlterDatabase(plan, new DbObjectPairing(src, dst), opts); }
public static void AlterDatabase(this IAlterProcessor proc, DatabaseInfo src, DatabaseInfo dst, DatabaseInfo targetDb, DbDiffOptions opts, Action <AlterPlan> extendPlan) { AlterPlan plan = new AlterPlan(targetDb); DbDiffTool.AlterDatabase(plan, src, dst, opts); if (extendPlan != null) { extendPlan(plan); } plan.Transform(proc.AlterCaps, opts); var run = plan.CreateRunner(); run.Run(proc, opts); }
//public void EndFixedOrder() //{ // m_fixedOrderCounter++; //} //public void BeginFixedOrder() //{ // m_fixedOrderCounter--; //} public void AddLogicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts) { for (int index = 0; index < Operations.Count; index++) { var before = new List<AlterOperation>(); var after = new List<AlterOperation>(); Operations[index].AddLogicalDependencies(caps, opts, before, after, this); Operations.InsertRange(index, before); index += before.Count; Operations.InsertRange(index + 1, after); index += after.Count; } }
public static void AlterTable(AlterPlan plan, TableInfo oldTable, TableInfo newTable, DbDiffOptions opts, DbObjectPairing pairing) { //plan.BeginFixedOrder(); if (oldTable == null) { throw new ArgumentNullException("oldTable", "DBSH-00141 oldTable is null"); } if (newTable == null) { throw new ArgumentNullException("newTable", "DBSH-00142 newTable is null"); } //bool processed; //proc.AlterTable(oldTable, newTable, out processed); //if (processed) return; //InMemoryTableOperation dataOps = null; //if (oldTable.FixedData != null) dataOps = new InMemoryTableOperation(oldTable.FixedData.Structure); NameWithSchema newTableName = GenerateNewName(oldTable.FullName, newTable.FullName, opts); bool permuteColumns = false; bool insertColumns = false; //bool renameColumns = false; List <int> columnMap = new List <int>(); List <int> constraintMap = new List <int>(); foreach (var col in newTable.Columns) { columnMap.Add(oldTable.Columns.IndexOfIf(c => c.GroupId == col.GroupId)); } foreach (var cnt in newTable.Constraints) { int cindex = oldTable.Constraints.IndexOfIf(c => c.GroupId == cnt.GroupId); if (cindex < 0 && cnt is PrimaryKeyInfo) { // primary keys for one table are equal cindex = oldTable.Constraints.IndexOfIf(c => c is PrimaryKeyInfo); } constraintMap.Add(cindex); } if (!opts.IgnoreColumnOrder) { // count alter requests int lastcol = -1; foreach (int col in columnMap) { if (col < 0) { continue; } if (col < lastcol) { permuteColumns = true; } lastcol = col; } bool wasins = false; foreach (int col in columnMap) { if (col < 0) { wasins = true; } if (col >= 0 && wasins) { insertColumns = true; } } } int index; // drop constraints index = 0; foreach (var cnt in oldTable.Constraints) { if (constraintMap.IndexOf(index) < 0) { plan.DropConstraint(cnt); } index++; } // drop columns index = 0; foreach (var col in oldTable.Columns) { if (columnMap.IndexOf(index) < 0) { plan.DropColumn(col); //if (dataOps != null) dataOps.DropColumn(col.ColumnName); } index++; } if (!DbDiffTool.EqualFullNames(oldTable.FullName, newTable.FullName, opts)) { plan.RenameTable(oldTable, newTable.FullName); } // create columns index = 0; foreach (var col in newTable.Columns) { if (columnMap[index] < 0) { var newcol = col.CloneColumn(); plan.CreateColumn(oldTable, newcol); //if (dataOps != null) dataOps.CreateColumn(newcol); } index++; } // change columns index = 0; foreach (var col in newTable.Columns) { if (columnMap[index] >= 0) { var src = oldTable.Columns[columnMap[index]]; if (!DbDiffTool.EqualsColumns(src, col, true, true, opts, pairing)) { using (var ctx = new DbDiffChangeLoggerContext(opts, NopMessageLogger.Instance, DbDiffOptsLogger.DiffLogger)) { if (DbDiffTool.EqualsColumns(src, col, false, true, opts, pairing)) { plan.RenameColumn(src, col.Name); } else { plan.ChangeColumn(src, col); } //if (dataOps != null && src.ColumnName != col.ColumnName) dataOps.RenameColumn(src.ColumnName, col.ColumnName); } } } index++; } //// create fixed data script //var script = AlterFixedData(oldTable.FixedData, newTable.FixedData, dataOps, opts); //if (script != null) plan.UpdateData(oldTable.FullName, script); // change constraints index = 0; foreach (var cnt in newTable.Constraints) { if (constraintMap[index] >= 0) { var src = oldTable.Constraints[constraintMap[index]]; if (DbDiffTool.EqualsConstraints(src, cnt, opts, false, pairing) && src.ConstraintName != cnt.ConstraintName) { //if (cnt is IPrimaryKey && (pairing.Source.Dialect.DialectCaps.AnonymousPrimaryKey || pairing.Target.Dialect.DialectCaps.AnonymousPrimaryKey)) //{ // // do nothing //} //else //{ plan.RenameConstraint(src, cnt.ConstraintName); //} } else { if (!DbDiffTool.EqualsConstraints(src, cnt, opts, true, pairing)) { plan.ChangeConstraint(src, cnt); } } } index++; } // create constraints index = 0; foreach (var cnt in newTable.Constraints) { if (constraintMap[index] < 0) { plan.CreateConstraint(oldTable, cnt); } index++;; } if (permuteColumns || insertColumns) { plan.ReorderColumns(oldTable, new List <string>((from c in newTable.Columns select c.Name))); } var alteredOptions = GetTableAlteredOptions(oldTable, newTable, opts); if (alteredOptions.Count > 0) { plan.ChangeTableOptions(oldTable, alteredOptions); } //plan.EndFixedOrder(); }
public void Transform(AlterProcessorCaps caps, DbDiffOptions opts) { // transform operations for (int index = 0; index < Operations.Count; ) { var list = new List<AlterOperation>(); list.Add(Operations[index]); Operations[index].TransformToImplementedOps(caps, opts, list, this); if (list.Count == 1) { Operations[index] = list[0]; index++; } else { Operations.RemoveAt(index); Operations.InsertRange(index, list); index += list.Count; } } // add physical dependencies for (int index = 0; index < Operations.Count; index++) { var before = new List<AlterOperation>(); var after = new List<AlterOperation>(); Operations[index].AddPhysicalDependencies(caps, opts, before, after, this); Operations.InsertRange(index, before); index += before.Count; Operations.InsertRange(index + 1, after); index += after.Count; } // join recreate table operations for (int index = 0; index < Operations.Count; index++) { var rop = Operations[index] as AlterOperation_RecreateTable; if (rop != null) { for (int i = index - 1; i >= 0; i--) { if (Operations[i].ParentTable == rop.ParentTable) { rop.InsertOp(Operations[i]); Operations.RemoveAt(i); index--; } } for (int i = index + 1; i < Operations.Count; ) { if (Operations[i].ParentTable == rop.ParentTable) { rop.AppendOp(Operations[i]); Operations.RemoveAt(i); } else { i++; } } } } // absorb operatios for (int index = 0; index < Operations.Count; index++) { if (Operations[index].MustRunAbsorbTest(caps)) { for (int i = 0; i < Operations.Count; i++) { if (i == index) continue; if (Operations[index].AbsorbOperation(caps, Operations[i])) { Operations.RemoveAt(i); if (i < index) index--; } } } } // remove recreates which are dropped for (int index = 0; index < RecreatedItems.Count; ) { bool remove = false; foreach (var op in Operations) { if (op.GetDropObject() == RecreatedItems[index].RecreatedObject) { remove = true; } } if (remove) { RecreatedItems.RemoveAt(index); } else { index++; } } // transform recreations into regular operations so that they can be sorted foreach (var dep in RecreatedItems) { opts.AlterLogger.Info(String.Format("Recreated object {0}", dep.RecreatedObject)); } foreach (var cls in RecreatedItem.DropClassOrder) { foreach (var dep in RecreatedItems) { if (dep.ItemClass != cls) continue; dep.PlanDrop(this, opts); } } foreach (var cls in RecreatedItem.DropClassOrder) { foreach (var dep in RecreatedItems) { if (dep.ItemClass != cls) continue; dep.PlanCreate(this, opts); } } // reorder operations // foreign key creation should be at last // simulate stable order (List.Sort is not stable!!) for (int i = 0; i < Operations.Count; i++) Operations[i].m_tmpOrder = i; Operations.Sort(OrderGroupCompare); foreach (var op in Operations) { if (op.DenyTransaction()) DenyTransaction = true; } }
public static void AlterDatabase(AlterPlan plan, DbObjectPairing pairing, DbDiffOptions opts) { var src = pairing.Source; var dst = pairing.Target; //var caps = proc.AlterCaps; //// domains //foreach (IDomainStructure dsrc in src.Domains) //{ // IDomainStructure ddst = pairing.FindPair(dsrc); // if (ddst == null) // { // plan.DropDomain(dsrc); // } // else if (!DbDiffTool.EqualDomains(dsrc, ddst, opts, true)) // { // if (DbDiffTool.EqualDomains(dsrc, ddst, opts, false)) // { // plan.RenameDomain(dsrc, ddst.FullName); // } // else // { // plan.ChangeDomain(dsrc, ddst); // } // } //} //foreach (IDomainStructure ddst in dst.Domains) //{ // if (!pairing.IsPaired(ddst)) plan.CreateDomain(ddst); //} // drop tables foreach (TableInfo tsrc in new List<TableInfo>(src.Tables)) { TableInfo tdst = pairing.FindPair(tsrc); if (tdst == null) { plan.DropTable(tsrc); } } // change tables foreach (TableInfo tsrc in new List<TableInfo>(src.Tables)) { TableInfo tdst = pairing.FindPair(tsrc); if (tdst == null) continue; if (!DbDiffTool.EqualTables(tsrc, tdst, opts, pairing)) { DbDiffTool.AlterTable(plan, tsrc, tdst, opts, pairing); } //else //{ // DbDiffTool.AlterFixedData(plan, tsrc, tdst, opts); //} } // create tables foreach (TableInfo tdst in dst.Tables) { if (!pairing.IsPaired(tdst)) { //var script = DbDiffTool.AlterFixedData(null, tdst.FixedData, null, opts); plan.CreateTable(tdst); //if (script != null) plan.UpdateData(tdst.FullName, script); } } // specific objects foreach (var osrc in src.GetAllSpecificObjects()) { //var repr = SpecificRepresentationAddonType.Instance.FindRepresentation(osrc.ObjectType); //if (!repr.UseInSynchronization) continue; var odst = pairing.FindPair(osrc); if (odst == null) { plan.DropSpecificObject(osrc); //proc.DropSpecificObject(osrc); } else if (!DbDiffTool.EqualsSpecificObjects(osrc, odst, opts)) { DbDiffTool.AlterSpecificObject(osrc, odst, plan, opts, pairing); } } foreach (var odst in dst.GetAllSpecificObjects()) { //var repr = SpecificRepresentationAddonType.Instance.FindRepresentation(odst.ObjectType); //if (!repr.UseInSynchronization) continue; if (!pairing.IsPaired(odst)) { plan.CreateSpecificObject(odst); //proc.CreateSpecificObject(odst); } } //foreach (ISchemaStructure ssrc in src.Schemata) //{ // ISchemaStructure sdst = pairing.FindPair(ssrc); // if (sdst == null) // { // plan.DropSchema(ssrc); // } // else if (ssrc.SchemaName != sdst.SchemaName) // { // plan.RenameSchema(ssrc, sdst.SchemaName); // //if (caps.RenameSchema) proc.RenameSchema(ssrc, sdst.SchemaName); // //else // //{ // // proc.DropSchema(ssrc); // // proc.CreateSchema(sdst); // //} // } //} //foreach (ISchemaStructure sdst in dst.Schemata) //{ // if (!pairing.IsPaired(sdst)) plan.CreateSchema(sdst); //} //var alteredOptions = GetDatabaseAlteredOptions(src, dst, opts); //if (alteredOptions.Count > 0) plan.ChangeDatabaseOptions(null, alteredOptions); //if (opts.SchemaMode == DbDiffSchemaMode.Ignore) //{ // plan.RunNameTransformation(new SetSchemaNameTransformation(null)); //} }
public void Run(IAlterProcessor proc, DbDiffOptions opts) { //foreach (var dep in RecreatedItems) //{ // opts.AlterLogger.Info(Texts.Get("s_recreated_object$object", "object", dep.RecreatedObject)); //} //foreach (var cls in RecreatedItem.DropClassOrder) //{ // foreach (var dep in RecreatedItems) // { // if (dep.ItemClass != cls) continue; // dep.RunDrop(proc, opts); // } //} foreach (var op in Operations) { op.Run(proc, opts); using (DbDiffChangeLoggerContext ctx = new DbDiffChangeLoggerContext(opts, NopMessageLogger.Instance, DbDiffOptsLogger.AlterLogger)) { if (op.MustRunOnParalelStructure()) { // run operation paralel on Structure, so that we have actual object names op.Run(new DatabaseInfoAlterProcessor(Structure), opts); } } } }
public virtual void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List<AlterOperation> replacement, AlterPlan plan) { }
//public void RunDrop(IAlterProcessor proc, DbDiffOptions opts) //{ // proc.DropObject(RecreatedObject); //} //public void RunCreate(IAlterProcessor proc, DbDiffOptions opts) //{ // if (NewVersion != null && NewVersion is TableObjectStructure) // { // TableObjectStructure obj2 = NewVersion.CloneObject() as TableObjectStructure; // obj2.SetDummyTable(((ITableObjectStructure)RecreatedObject).Table.FullName); // proc.CreateObject(obj2); // } // else // { // proc.CreateObject(RecreatedObject); // } //} public void PlanDrop(AlterPlan plan, DbDiffOptions opts) { plan.RecreateObject_Drop(RecreatedObject); }
public virtual void AddLogicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts, List<AlterOperation> before, List<AlterOperation> after, AlterPlan plan) { }
public void PlanCreate(AlterPlan plan, DbDiffOptions opts) { plan.RecreateObject_Create(RecreatedObject, NewVersion ?? RecreatedObject); }
public static bool EqualNames(string a, string b, DbDiffOptions opts) { return(String.Compare(a, b, opts.IgnoreCase) == 0); }
public static bool EqualTypes(ColumnInfo a, ColumnInfo b, DbDiffOptions opts) { if (a.DataType != b.DataType) { opts.DiffLogger.Trace("Column {0}, {1}: different types: {2}; {3}", a, b, a.DataType, b.DataType); return false; } if (a.Length != b.Length) { opts.DiffLogger.Trace("Column {0}, {1}: different lengths: {2}; {3}", a, b, a.Length, b.Length); return false; } if (a.Precision != b.Precision) { opts.DiffLogger.Trace("Column {0}, {1}: different lengths: {2}; {3}", a, b, a.Precision, b.Precision); return false; } if (a.Scale != b.Scale) { opts.DiffLogger.Trace("Column {0}, {1}: different scale: {2}; {3}", a, b, a.Scale, b.Scale); return false; } return true; }
public static bool EqualsColumns(ColumnInfo a, ColumnInfo b, bool checkName, bool checkDefault, DbDiffOptions opts, DbObjectPairing pairing) { if (checkName && !DbDiffTool.EqualNames(a.Name, b.Name, opts)) { opts.DiffLogger.Trace("Column, different name: {0}; {1}", a, b); return(false); } //if (!DbDiffTool.EqualFullNames(a.Domain, b.Domain, opts)) //{ // opts.DiffLogger.Trace("Column {0}, {1}: different domain: {2}; {3}", a, b, a.Domain, b.Domain); // return false; //} if (a.ComputedExpression != b.ComputedExpression) { opts.DiffLogger.Trace("Column {0}, {1}: different computed expression: {2}; {3}", a, b, a.ComputedExpression, b.ComputedExpression); return(false); } if (a.ComputedExpression != null) { return(true); } if (checkDefault) { if (a.DefaultValue == null) { if (a.DefaultValue != b.DefaultValue) { opts.DiffLogger.Trace("Column {0}, {1}: different default values: {2}; {3}", a, b, a.DefaultValue, b.DefaultValue); return(false); } } else { if (!a.DefaultValue.Equals(b.DefaultValue)) { opts.DiffLogger.Trace("Column {0}, {1}: different default values: {2}; {3}", a, b, a.DefaultValue, b.DefaultValue); return(false); } } if (a.DefaultConstraint != b.DefaultConstraint) { opts.DiffLogger.Trace("Column {0}, {1}: different default constraint names: {2}; {3}", a, b, a.DefaultConstraint, b.DefaultConstraint); return(false); } } if (a.NotNull != b.NotNull) { opts.DiffLogger.Trace("Column {0}, {1}: different nullable: {2}; {3}", a, b, a.NotNull, b.NotNull); return(false); } if (a.AutoIncrement != b.AutoIncrement) { opts.DiffLogger.Trace("Column {0}, {1}: different autoincrement: {2}; {3}", a, b, a.AutoIncrement, b.AutoIncrement); return(false); } if (a.IsSparse != b.IsSparse) { opts.DiffLogger.Trace("Column {0}, {1}: different is_sparse: {2}; {3}", a, b, a.IsSparse, b.IsSparse); return(false); } if (!EqualTypes(a, b, opts)) { return(false); } //var btype = b.DataType; //var atype = a.DataType; //if (pairing != null && pairing.Target != null && pairing.Source.Dialect != null) //{ // btype = pairing.Source.Dialect.MigrateDataType(b, btype, pairing.Source.Dialect.GetDefaultMigrationProfile(), null); // btype = pairing.Source.Dialect.GenericTypeToSpecific(btype).ToGenericType(); // // normalize type // atype = pairing.Source.Dialect.GenericTypeToSpecific(atype).ToGenericType(); //} //if (!EqualTypes(atype, btype, opts)) //{ // opts.DiffLogger.Trace("Column {0}, {1}: different types: {2}; {3}", a, b, a.DataType, b.DataType); // return false; //} //if (!opts.IgnoreColumnCollation && a.Collation != b.Collation) //{ // opts.DiffLogger.Trace("Column {0}, {1}: different collations: {2}; {3}", a, b, a.Collation, b.Collation); // return false; //} //if (!opts.IgnoreColumnCharacterSet && a.CharacterSet != b.CharacterSet) //{ // opts.DiffLogger.Trace("Column {0}, {1}: different character sets: {2}; {3}", a, b, a.CharacterSet, b.CharacterSet); // return false; //} return(true); }
public static AlterPlan PlanAlterTable(TableInfo oldTable, TableInfo newTable, DbDiffOptions opts, DatabaseInfo currentStructure) { AlterPlan plan = new AlterPlan(currentStructure); if (oldTable == null) { plan.CreateTable(newTable); } else { DbObjectPairing pairing = CreateTablePairing(oldTable, newTable); AlterTable(plan, oldTable, newTable, opts, pairing); } return plan; }