Exemplo n.º 1
0
        public static bool FkeyHasChanged(SchemaChanges changes, SubObjectState <FkeyType, FkeyType.State> current)
        {
            if (current == null)
            {
                return(true);
            }

            var desired = changes.Desired.Get(current);

            // The foreign key doesn't exist in the desired schema at all
            if (desired == null)
            {
                return(true);
            }

            // The destination table has changed
            if (desired.State.ToTable != current.State.ToTable)
            {
                return(true);
            }

            // Either the from or to table might need to be dropped entirely to reorder fields
            if (FieldType.IsFieldReorderPossiblyNeeded(changes, current.ParentIdentifier) ||
                FieldType.IsFieldReorderPossiblyNeeded(changes, current.State.ToTable))
            {
                return(true);
            }

            // It's changed from cascading to not or vice versa
            if (desired.State.IsCascadeDelete != current.State.IsCascadeDelete)
            {
                return(true);
            }

            // The sequence of field name pairs don't match
            if (!Enumerable.SequenceEqual(desired.State.Joins, current.State.Joins, FieldPair.GetComparer(changes.DbDriver)))
            {
                return(true);
            }

            // Any of the fields in either table are changing
            if (current.State.Joins.Any(field =>
                                        FieldType.FieldHasChanged(changes, current.ParentIdentifier, FieldType.Identifier(field.FromFieldName)) ||
                                        FieldType.FieldHasChanged(changes, current.State.ToTable, FieldType.Identifier(field.ToFieldName))))
            {
                return(true);
            }

            // The unique index on the destination table that corresponds to the destination fields is changing
            var ukey = UniqueIndexType.ChildrenFrom(changes.Current, current.State.ToTable)
                       .SingleOrDefault(key => new HashSet <Identifier>(key.State.IndexState.Fields).SetEquals(from field in current.State.Joins
                                                                                                               select FieldType.Identifier(field.ToFieldName)));

            if (ukey != null && UniqueIndexType.IndexHasChanged(changes, ukey))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        internal static bool FulltextIndexHasChanged(SchemaChanges changes, SubObjectState <FulltextIndexType, State> current)
        {
            if (current == null)
            {
                return(true);
            }

            var desired = changes.Desired.Get(current);

            // The fulltext index doesn't exist in the desired schema at all
            if (desired == null)
            {
                return(true);
            }

            // The key index name has changed
            if (desired.State.KeyName != current.State.KeyName)
            {
                return(true);
            }

            // The set of affected columns has changed (in some way other than just the ordering)
            if (!ImmutableHashSet.CreateRange(changes.DbDriver.DbStringComparer, desired.State.Columns).SetEquals(current.State.Columns))
            {
                return(true);
            }

            var table = TableType.Identifier(desired.Name);

            // Any of the columns in the fulltext index have changed
            if (desired.State.Columns.Any(col => FieldType.FieldHasChanged(changes, table, FieldType.Identifier(col))))
            {
                return(true);
            }

            // The key index is to be dropped
            // This includes the case where the table itself may be dropped for reordering
            if (UniqueIndexType.IndexHasChanged(changes, UniqueIndexType.GetFrom(changes.Current, table, UniqueIndexType.Identifier(current.State.KeyName))))
            {
                return(true);
            }

            return(false);
        }