public override void AddLogicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> before, List <AlterOperation> after, AlterPlan plan, IDatabaseSource targetDb) { base.AddLogicalDependencies(caps, opts, before, after, plan, targetDb); var pk = OldObject as IPrimaryKey; if (pk != null) { ParentTable.LoadStructure(TableStructureMembers.ReferencedFrom, targetDb); foreach (var col in pk.Columns) { foreach (ForeignKey fk in ParentTable.GetReferencedFrom()) { bool fkdeleted = false; for (int i = 0; i < fk.PrimaryKeyColumns.Count; i++) { if (fk.PrimaryKeyColumns[i].ColumnName == col.ColumnName) { fkdeleted = true; break; } } if (fkdeleted) { opts.AlterLogger.Warning(Texts.Get("s_dropped_reference$table$fk", "table", fk.Table.FullName, "fk", fk.Name)); before.Add(new AlterOperation_DropConstraint { ParentTable = ParentTable, OldObject = fk }); } } } } }
public override void AddLogicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> before, List <AlterOperation> after, AlterPlan plan, IDatabaseSource targetDb) { ParentTable.LoadStructure(TableStructureMembers.ReferencedFrom, targetDb); var oldcol = OldObject as ColumnStructure; var newcol = NewObject as ColumnStructure; List <IForeignKey> recreateFks = new List <IForeignKey>(); var changeCols = new List <Tuple <IColumnStructure, IColumnStructure> >(); foreach (ForeignKey fk in ParentTable.GetReferencedFrom()) { for (int i = 0; i < fk.PrimaryKeyColumns.Count; i++) { if (fk.PrimaryKeyColumns[i].ColumnName == oldcol.ColumnName) { //plan.RecreateObject(fk, null); TableStructure table = (TableStructure)fk.Table; table.LoadStructure(TableStructureMembers.Columns, targetDb); ColumnStructure othercol = table.Columns[fk.Columns[i].ColumnName] as ColumnStructure; // compare types with ignoring autoincrement flag // HACK: ignore specific attributes var opts2 = opts.Clone(); opts2.IgnoreSpecificData = true; DbTypeBase dt1 = othercol.DataType.Clone(), dt2 = newcol.DataType.Clone(); dt1.SetAutoincrement(false); dt2.SetAutoincrement(false); if (!DbDiffTool.EqualTypes(dt1, dt2, opts2)) { after.Add(new AlterOperation_ChangeColumn { ParentTable = table, OldObject = othercol, NewObject = new ColumnStructure(othercol) { DataType = dt2 } }); } opts.AlterLogger.Warning(Texts.Get("s_changed_referenced_column$table$column", "table", fk.Table.FullName, "column", othercol.ColumnName)); } } } }
public override void AddPhysicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> before, List <AlterOperation> after, AlterPlan plan, IDatabaseSource targetDb) { var oldcol = OldObject as ColumnStructure; if (caps.DepCaps.ChangeColumn_Constraint || caps.DepCaps.ChangeColumn_Index) { ParentTable.LoadStructure(TableStructureMembers.Constraints, targetDb); foreach (var cnt in ParentTable.Constraints) { var cc = cnt as ColumnsConstraint; if (cc == null) { continue; } if (cc.Columns.Any(c => c.ColumnName == oldcol.ColumnName)) { if ( (cc is IIndex && caps.DepCaps.ChangeColumn_Index) || (!(cc is IIndex) && caps.DepCaps.ChangeColumn_Constraint)) { plan.RecreateObject(cc, null); } } } } if (caps.DepCaps.ChangeColumn_Reference) { ParentTable.LoadStructure(TableStructureMembers.ReferencedFrom, targetDb); foreach (ForeignKey fk in ParentTable.GetReferencedFrom()) { for (int i = 0; i < fk.PrimaryKeyColumns.Count; i++) { if (fk.PrimaryKeyColumns[i].ColumnName == oldcol.ColumnName) { plan.RecreateObject(fk, null); } } } } }
public override void AddPhysicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> before, List <AlterOperation> after, AlterPlan alterPlan, IDatabaseSource targetDb) { base.AddPhysicalDependencies(caps, opts, before, after, alterPlan, targetDb); ParentTable.LoadStructure(TableStructureMembers.Columns | TableStructureMembers.PrimaryKey, targetDb); }