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); }
public static bool TriggerHasChanged(SchemaChanges changes, SubObjectState <TriggerType, State> current) { if (current == null) { return(true); } var desired = changes.Desired.Get(current); // The trigger doesn't exist in the desired schema at all if (desired == null) { return(true); } // The trigger's contents are different if (current.State.Timing != desired.State.Timing || current.State.Events != desired.State.Events || !Nstring.DBEquivalentComparer.Equals(current.State.Body, desired.State.Body)) { return(true); } // The table might need to be dropped entirely to reorder the columns if (FieldType.IsFieldReorderPossiblyNeeded(changes, current.ParentIdentifier)) { return(true); } return(false); }
public static bool IndexHasChanged(SchemaChanges changes, SubObjectState <UniqueIndexType, UniqueIndexType.State> current) { if (current == null) { return(true); } var desired = changes.Desired.Get(current); // The index doesn't exist in the desired schema at all if (desired == null) { return(true); } // It's changed from primary key to not or vice versa if (desired.State.IsPrimaryKey != current.State.IsPrimaryKey) { return(true); } // The index fields are different if (IndexState.IndexStateHasChanged(changes, current.ParentIdentifier, current.State.IndexState, desired.State.IndexState)) { return(true); } return(false); }
private bool isSequencedPkeyToBeDropped(SchemaChanges changes, SubObjectState <FieldType, FieldType.State> current) { if (current.State.IsSequencedPkey) { var desiredTable = TableType.GetDesiredIdentifier(changes, current.ParentIdentifier); return(desiredTable != null && FieldType.ChildrenFrom(changes.Desired, desiredTable).Any(field => field.State.IsSequencedPkey)); } return(false); }
public static bool IndexHasChanged(SchemaChanges changes, SubObjectState <NonUniqueIndexType, IndexState> current) { var desired = changes.Desired.Get(current); // The index doesn't exist in the desired schema at all if (desired == null) { return(true); } // The index fields are different if (IndexState.IndexStateHasChanged(changes, current.ParentIdentifier, current.State, desired.State)) { return(true); } return(false); }
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); }
public static SubObjectState <FieldType, State> GetDesired(SchemaChanges changes, SubObjectState <FieldType, State> current) { var desiredTable = TableType.GetDesiredIdentifier(changes, current.ParentIdentifier); if (desiredTable == null) { return(null); } return(GetFrom(changes.Desired, desiredTable, current.Identifier)); }