Ejemplo n.º 1
0
        public static List <PrimaryKeyMigration> ComparePrimaryKeys(SqlTable tableOriginal, SqlTable tableNew)
        {
            var comparer = new ComparerPrimaryKey();
            var changes  = comparer.CompareIndexes(tableOriginal, tableNew);

            return(changes);
        }
Ejemplo n.º 2
0
        public List <IMigration> Compare(DatabaseDefinition originalDd, DatabaseDefinition newDd)
        {
            // TODO needs to be ordered
            var changes = new List <IMigration>();

            // Compare tables
            // handle renamed tables - needs parameter / external info
            foreach (var tableOriginal in originalDd.GetTables())
            {
                if (!newDd.Contains(tableOriginal.SchemaAndTableName))
                {
                    var tableDelete = new TableDelete
                    {
                        SchemaAndTableName = tableOriginal.SchemaAndTableName
                    };

                    changes.Add(tableDelete);
                }
            }

            foreach (var tableNewDd in newDd.GetTables())
            {
                if (!originalDd.Contains(tableNewDd.SchemaAndTableName))
                {
                    var tableNew = new TableNew(tableNewDd);
                    changes.Add(tableNew);
                }
            }

            foreach (var tableOriginal in originalDd.GetTables())
            {
                // not deleted
                if (newDd.Contains(tableOriginal.SchemaAndTableName))
                {
                    var tableNew = newDd.Tables[tableOriginal.SchemaAndTableName];
                    changes.AddRange(CompareColumns(tableOriginal, tableNew));
                    changes.AddRange(ComparerPrimaryKey.ComparePrimaryKeys(tableOriginal, tableNew));
                    changes.AddRange(ComparerForeignKey.CompareForeignKeys(tableOriginal, tableNew));
                    changes.AddRange(ComparerIndex.CompareIndexes(tableOriginal, tableNew));
                    changes.AddRange(ComparerUniqueConstraint.CompareUniqueConstraints(tableOriginal, tableNew));
                }
            }

            return(changes);
        }