Exemplo n.º 1
0
        public void Execute(DatabaseTable databaseTable, DatabaseTable compareTable)
        {
            var firstTriggers  = databaseTable.Triggers;
            var secondTriggers = compareTable.Triggers;

            foreach (var trigger in firstTriggers)
            {
                var indexName = trigger.Name;
                var match     = secondTriggers.FirstOrDefault(c => c.Name == indexName);
                if (match == null)
                {
                    CreateResult(ResultType.Delete, databaseTable, indexName,
                                 _writer.DropTrigger(databaseTable, trigger));
                    continue;
                }
                if (trigger.TriggerBody != match.TriggerBody ||
                    trigger.TriggerType != match.TriggerType ||
                    trigger.TriggerEvent != match.TriggerEvent)
                {
                    CreateResult(ResultType.Change, databaseTable, indexName,
                                 _writer.DropTrigger(databaseTable, trigger) + Environment.NewLine +
                                 _writer.AddTrigger(databaseTable, match));
                }
            }

            foreach (var trigger in secondTriggers)
            {
                var indexName       = trigger.Name;
                var firstConstraint = firstTriggers.FirstOrDefault(c => c.Name == indexName);
                if (firstConstraint == null)
                {
                    CreateResult(ResultType.Add, databaseTable, indexName,
                                 _writer.AddTrigger(databaseTable, trigger));
                }
            }
        }