Пример #1
0
        private SchemaPatchDifference determinePatchDifference()
        {
            if (Actual.PartitionStrategy != Expected.PartitionStrategy)
            {
                return(SchemaPatchDifference.Invalid);
            }

            if (!Actual.PartitionExpressions.SequenceEqual(Expected.PartitionExpressions))
            {
                return(SchemaPatchDifference.Invalid);
            }


            if (!HasChanges())
            {
                return(SchemaPatchDifference.None);
            }


            // If there are any columns that are different and at least one cannot
            // automatically generate an `ALTER TABLE` statement, the patch is invalid
            if (Columns.Different.Any(x => !x.Expected.CanAlter(x.Actual)))
            {
                return(SchemaPatchDifference.Invalid);
            }

            // If there are any missing columns and at least one
            // cannot generate an `ALTER TABLE * ADD COLUMN` statement
            if (Columns.Missing.Any(x => !x.CanAdd()))
            {
                return(SchemaPatchDifference.Invalid);
            }

            var differences = new SchemaPatchDifference[]
            {
                Columns.Difference(),
                ForeignKeys.Difference(),
                Indexes.Difference(),
                PrimaryKeyDifference
            };

            return(differences.Min());
        }