예제 #1
0
        public void Execute(DatabaseTable databaseTable, DatabaseTable compareTable)
        {
            var firstIndexes  = databaseTable.Indexes;
            var secondIndexes = compareTable.Indexes;

            foreach (var index in firstIndexes)
            {
                if (index.IsUniqueKeyIndex(databaseTable))
                {
                    continue;
                }

                var indexName = index.Name;
                var match     = secondIndexes.FirstOrDefault(c => c.Name == indexName);
                if (match == null)
                {
                    CreateResult(ResultType.Delete, databaseTable, indexName,
                                 _writer.DropIndex(databaseTable, index));
                    continue;
                }
                if (!ColumnsEqual(index, match) || (index.IndexType != match.IndexType))
                {
                    CreateResult(ResultType.Add, databaseTable, indexName,
                                 _writer.DropIndex(databaseTable, index) + Environment.NewLine +
                                 _writer.AddIndex(databaseTable, match));
                }
            }

            foreach (var index in secondIndexes)
            {
                if (index.IsUniqueKeyIndex(compareTable))
                {
                    continue;
                }

                var indexName       = index.Name;
                var firstConstraint = firstIndexes.FirstOrDefault(c => c.Name == indexName);
                if (firstConstraint == null)
                {
                    CreateResult(ResultType.Add, databaseTable, indexName,
                                 _writer.AddIndex(databaseTable, index));
                }
            }
        }