Exemplo n.º 1
0
        public static List <IdentityMigration> CompareIdentity(SqlColumn columnOriginal, SqlColumn columnNew)
        {
            var comparer = new ComparerIdentity();
            var changes  = comparer.CompareProperties(columnOriginal, columnNew);

            return(changes);
        }
Exemplo n.º 2
0
        private static List <IMigration> CompareColumns(SqlTable tableOriginal, SqlTable tableNew)
        {
            var changes = new List <IMigration>();

            foreach (var columnOriginal in tableOriginal.Columns)
            {
                tableNew.Columns.TryGetValue(columnOriginal.Name, out var columnNew);
                if (columnNew == null)
                {
                    changes.Add(new ColumnDelete()
                    {
                        SqlColumn = columnOriginal
                    });
                }
            }

            foreach (var columnNew in tableNew.Columns)
            {
                tableOriginal.Columns.TryGetValue(columnNew.Name, out var columnOriginal);
                if (columnOriginal == null)
                {
                    changes.Add(new ColumnNew()
                    {
                        SqlColumn = columnNew
                    });
                }
                else
                {
                    var columnChange = new ColumnChange()
                    {
                        SqlColumn      = columnOriginal,
                        NewNameAndType = columnNew
                    };

                    var propertyChanges = ComparerIdentity.CompareIdentity(columnOriginal, columnNew);

                    if (propertyChanges.Any() ||
                        ColumnChanged(columnNew, columnOriginal))
                    {
                        columnChange.NewNameAndType = columnNew.CopyTo(new SqlColumn());
                        columnChange.SqlColumnPropertyMigrations.AddRange(propertyChanges);
                        changes.Add(columnChange);
                    }
                }
            }

            return(changes);
        }