Exemplo n.º 1
0
        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
                            });
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        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));
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        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);
                        }
                    }
                }
            }
        }