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 override void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> replacement, AlterPlan plan) { if (!caps.PermuteColumns) { TransformToRecreateTable(caps, replacement, plan); } }
//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 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 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 bool AbsorbOperation(AlterProcessorCaps caps, AlterOperation op) { var cop = op as AlterOperation_Create; if (cop != null) { var pk = cop.NewObject as PrimaryKeyInfo; if (pk != null && pk.Columns.Count == 1 && pk.Columns[0].Name == ((ColumnInfo)NewObject).Name) { pk = pk.ClonePrimaryKey(); pk.SetDummyTable(ParentTable.FullName); AdditionalConstraints.Add(pk); return(true); } } return(base.AbsorbOperation(caps, op)); }
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); } } }
protected void TransformToRecreateTable(AlterProcessorCaps caps, List <AlterOperation> replacement, AlterPlan plan) { replacement.Clear(); var op = new AlterOperation_RecreateTable { ParentTable = ParentTable }; //ParentTable.LoadStructure(TableStructureMembers.All, targetDb); if (caps.DropConstraint) { foreach (var fk in ParentTable.GetReferences()) { plan.RecreateObject(fk, null); } } op.AppendOp(this); replacement.Add(op); }
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 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 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); } } } } }
protected static ObjectOperationCaps GetConstraintCaps(AlterProcessorCaps caps, DatabaseObjectInfo obj) { if (obj is IndexInfo) { return new ObjectOperationCaps { Create = caps.AddIndex, Drop = caps.DropIndex, Rename = caps.RenameIndex, Change = caps.ChangeIndex, }; } else { return new ObjectOperationCaps { Create = caps.AddConstraint, Drop = caps.DropConstraint, Rename = caps.RenameConstraint, Change = caps.ChangeConstraint, }; } }
protected static ObjectOperationCaps GetConstraintCaps(AlterProcessorCaps caps, DatabaseObjectInfo obj) { if (obj is IndexInfo) { return(new ObjectOperationCaps { Create = caps.AddIndex, Drop = caps.DropIndex, Rename = caps.RenameIndex, Change = caps.ChangeIndex, }); } else { return(new ObjectOperationCaps { Create = caps.AddConstraint, Drop = caps.DropConstraint, Rename = caps.RenameConstraint, Change = caps.ChangeConstraint, }); } }
public override void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List<AlterOperation> replacement, AlterPlan plan) { var c = GetConstraintCaps(caps, OldObject); if (!c.Drop) TransformToRecreateTable(replacement, plan); }
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(replacement, plan); } } }
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(replacement, plan); } } }
public virtual bool AbsorbOperation(AlterProcessorCaps caps, AlterOperation op) { return(false); }
public virtual bool MustRunAbsorbTest(AlterProcessorCaps caps) { return(false); }
public override bool MustRunAbsorbTest(AlterProcessorCaps caps) { return caps.ForceAbsorbPrimaryKey; }
public override void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List<AlterOperation> replacement, AlterPlan plan) { if (!caps.PermuteColumns) { TransformToRecreateTable(replacement, plan); } }
public override void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List<AlterOperation> replacement, AlterPlan plan) { if (!caps.ChangeColumn) { TransformToRecreateTable(replacement, plan); return; } if (!caps.ChangeAutoIncrement && ((ColumnInfo)OldObject).AutoIncrement != ((ColumnInfo)NewObject).AutoIncrement) { TransformToRecreateTable(replacement, plan); return; } if (!caps.ChangeComputedColumnExpression && ((ColumnInfo)NewObject).ComputedExpression != null) { plan.RecreateObject(OldObject, NewObject); replacement.Clear(); } }
public virtual void AddLogicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts, List<AlterOperation> before, List<AlterOperation> after, AlterPlan plan) { }
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) { base.TransformToImplementedOps(caps, opts, replacement, plan); //if (DbName == null) DbName = targetDb.DatabaseName; }
public override void AddPhysicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts, List<AlterOperation> before, List<AlterOperation> after, AlterPlan alterPlan) { base.AddPhysicalDependencies(caps, opts, before, after, alterPlan); //ParentTable.LoadStructure(TableStructureMembers.Columns | TableStructureMembers.PrimaryKey, targetDb); }
public override bool MustRunAbsorbTest(AlterProcessorCaps caps) { return(caps.ForceAbsorbPrimaryKey); }
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 override bool AbsorbOperation(AlterProcessorCaps caps, AlterOperation op) { var cop = op as AlterOperation_Create; if (cop != null) { var pk = cop.NewObject as PrimaryKeyInfo; if (pk != null && pk.Columns.Count == 1 && pk.Columns[0].Name == ((ColumnInfo)NewObject).Name) { pk = pk.ClonePrimaryKey(); pk.SetDummyTable(ParentTable.FullName); AdditionalConstraints.Add(pk); return true; } } return base.AbsorbOperation(caps, op); }
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 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>>(); 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.Columns[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 virtual bool MustRunAbsorbTest(AlterProcessorCaps caps) { return false; }
//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 override void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> replacement, AlterPlan plan) { base.TransformToImplementedOps(caps, opts, replacement, plan); //if (DbName == null) DbName = targetDb.DatabaseName; }
public virtual bool AbsorbOperation(AlterProcessorCaps caps, AlterOperation op) { return false; }
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 override void AddPhysicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> before, List <AlterOperation> after, AlterPlan alterPlan) { base.AddPhysicalDependencies(caps, opts, before, after, alterPlan); //ParentTable.LoadStructure(TableStructureMembers.Columns | TableStructureMembers.PrimaryKey, targetDb); }
public virtual void AddPhysicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> before, List <AlterOperation> after, AlterPlan alterPlan) { }
public virtual void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List<AlterOperation> replacement, AlterPlan plan) { }
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 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 virtual void TransformToImplementedOps(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> replacement, AlterPlan plan) { }