コード例 #1
0
        public override void Perform(SchemaChanges changes, IOutput output)
        {
            var renames = from rename in TableRenameType.AllFrom(changes.Desired)
                          where changes.Current.ContainsRoot(TableType.Identifier(rename.Name))
                          group rename by rename.State.ToTable into destination
                          select destination;

            foreach (var rename in renames)
            {
                var toTable = rename.Key;

                if (rename.Count() > 1)
                {
                    changes.Fail("Rename conflict: Multiple tables (" + string.Join(", ", from source in rename select source.Name) + ") wish to be renamed to " + toTable.Name);
                    continue;
                }
                var fromTable = TableType.Identifier(rename.Single().Name);

                if (changes.Current.ContainsRoot(toTable))
                {
                    changes.Fail("Rename conflict: " + fromTable + " wishes to be renamed to " + rename.Key.Name + ", but that table already exists.");
                    continue;
                }

                if (changes.Desired.ContainsRoot(fromTable))
                {
                    changes.Fail("Rename conflict: " + fromTable + " wishes to be renamed to " + rename.Key.Name + " but also to continue existing with its current name.");
                    continue;
                }

                if (!changes.Desired.ContainsRoot(toTable))
                {
                    changes.Fail("Rename conflict: " + fromTable + " wishes to be renamed to " + rename.Key.Name + " but that table is not supposed to exist.");
                    continue;
                }

                changes.Rename(changes.SchemaDriver.GetRenameTableSql(fromTable.Name, toTable.Name), fromTable, toTable);
            }
        }
コード例 #2
0
        public override void Perform(SchemaChanges changes, IOutput output)
        {
            foreach (var desired in FieldType.AllFrom(changes.Desired))
            {
                // We don't need to set it notnull if it's supposed to be nullable
                if (desired.State.IsNullable)
                {
                    continue;
                }

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

                // This shouldn't happen because fields have been created by this point
                if (current == null)
                {
                    changes.Fail("Trying to set " + desired + " not null but it hasn't been added yet!");
                    continue;
                }

                // This shouldn't happen either because field types have been altered by this point
                if (!FieldType.IsTypeEqual(desired.State, current.State, changes.SchemaDriver.IsSequencedPartOfFieldDeclaration))
                {
                    changes.Fail("Trying to set " + desired + " not null but its type is still wrong!");
                    continue;
                }

                // We don't need to set it notnull if it already is
                if (!current.State.IsNullable)
                {
                    continue;
                }

                // Update the field to notnull
                changes.Put(changes.SchemaDriver.GetSetFieldNotNullSql(desired.ParentName, desired.Name, desired.State.DataType, desired.State.IsSequencedPkey, desired.State.SequenceName),
                            desired);
            }
        }