示例#1
0
        public override List <SynchronizationItem> GetCreateItems()
        {
            var items = new List <SynchronizationItem>();
            var item  = new SynchronizationItem(databaseObject);

            items.Add(item);
            item.Differences.Add(new Difference()
            {
                PropertyName = Difference.CREATE
            });
            item.AddScript(2, getCreateScript());

            foreach (var fk in databaseObject.ForeignKeys)
            {
                items.AddRange(new ForeignKeySynchronization(fk).GetCreateItems());
            }

            items.AddRange(getIndexCreateUpdateItems(null));
            items.AddRange(getDefaultConstraintCreateUpdateItems(null));
            items.AddRange(getTriggerUpdateItems(null));
            foreach (var column in databaseObject.Columns)
            {
                items.AddRange(ExtendedPropertySynchronization.GetExtendedProperties(column, null));
            }

            return(items);
        }
示例#2
0
        public static List <SynchronizationItem> GetExtendedProperties(DatabaseObjectWithExtendedProperties sourceObject, DatabaseObjectWithExtendedProperties targetObject)
        {
            var items = new List <SynchronizationItem>();
            var skips = new List <string>();

            if (targetObject != null)
            {
                foreach (var toProperty in targetObject.ExtendedProperties)
                {
                    var fromProp = sourceObject.ExtendedProperties.FirstOrDefault(p => p.PropName == toProperty.PropName);
                    if (fromProp == null)
                    {
                        items.AddRange(new ExtendedPropertySynchronization(toProperty).GetDropItems());
                    }
                    else
                    {
                        var toItems = new ExtendedPropertySynchronization(fromProp).GetSynchronizationItems(toProperty);
                        if (toItems.Any())
                        {
                            items.AddRange(toItems);
                        }

                        skips.Add(toProperty.PropName);
                    }
                }
            }

            foreach (var fromProperty in sourceObject.ExtendedProperties)
            {
                if (skips.Contains(fromProperty.PropName))
                {
                    continue;
                }

                items.AddRange(new ExtendedPropertySynchronization(fromProperty).GetCreateItems());
            }

            return(items);
        }
示例#3
0
        public override List <SynchronizationItem> GetAlterItems(DatabaseObjectBase target)
        {
            var targetTable = target as Table;

            var items = new List <SynchronizationItem>();


            bool recreate = false;

            foreach (var fc in databaseObject.Columns)
            {
                var tc = targetTable.Columns.FirstOrDefault(c => c.ColumnName.ToLower() == fc.ColumnName.ToLower());
                if (tc != null && tc.IsIdentity != fc.IsIdentity)
                {
                    var item = getRecreateTableItem(targetTable);
                    item.Differences.Add(new Difference()
                    {
                        PropertyName = "IsIdentity",
                        SourceValue  = fc.IsIdentity.ToString(),
                        TargetValue  = tc.IsIdentity.ToString()
                    });
                    items.Add(item);
                    recreate    = true;
                    targetTable = null;
                    break;
                }

                if (tc != null && tc.DataType == "timestamp")
                {
                    var diff = new ColumnSynchronization(fc).GetPropertyDifferences(tc);
                    if (diff.Any())
                    {
                        var item = getRecreateTableItem(targetTable);
                        item.Differences.AddRange(diff);
                        items.Add(item);
                        recreate    = true;
                        targetTable = null;
                        break;
                    }
                }
            }

            if (!recreate)
            {
                foreach (var tk in targetTable.ForeignKeys)
                {
                    if (!databaseObject.ForeignKeys.Any(k => k.ForeignKeyName.ToLower() == tk.ForeignKeyName.ToLower()))
                    {
                        items.AddRange(new ForeignKeySynchronization(tk).GetDropItems());
                    }
                }

                foreach (var fk in databaseObject.ForeignKeys)
                {
                    var tk = targetTable.ForeignKeys.FirstOrDefault(x => x.ObjectName == fk.ObjectName);
                    if (tk != null)
                    {
                        items.AddRange(new ForeignKeySynchronization(fk).GetSynchronizationItems(tk));
                    }
                    else
                    {
                        items.AddRange(new ForeignKeySynchronization(fk).GetCreateItems());
                    }
                }

                foreach (var tc in targetTable.Columns)
                {
                    if (!databaseObject.Columns.Any(c => c.ColumnName.ToLower() == tc.ColumnName.ToLower()))
                    {
                        items.AddRange(new ColumnSynchronization(tc).GetDropItems());
                    }
                }

                _createdColumns = new List <string>();
                _alteredColumns = new List <string>();

                foreach (var fc in databaseObject.Columns)
                {
                    var tc = targetTable.Columns.FirstOrDefault(c => c.ColumnName.ToLower() == fc.ColumnName.ToLower());
                    if (tc == null)
                    {
                        items.AddRange(new ColumnSynchronization(fc).GetAddAlterItems(null));
                        _createdColumns.Add(fc.ColumnName);
                    }
                    else
                    {
                        var alteredItems = new ColumnSynchronization(fc).GetSynchronizationItems(tc);
                        if (alteredItems.Any())
                        {
                            items.AddRange(alteredItems);
                            _alteredColumns.Add(fc.ColumnName);
                        }
                    }
                }
            }

            if (!recreate)
            {
                items.AddRange(getKeyConstraintUpdateItems(targetTable));
            }

            items.AddRange(getIndexCreateUpdateItems(targetTable));
            items.AddRange(getDefaultConstraintCreateUpdateItems(targetTable));
            items.AddRange(getTriggerUpdateItems(targetTable));
            foreach (var column in databaseObject.Columns)
            {
                items.AddRange(ExtendedPropertySynchronization.GetExtendedProperties(column, targetTable == null ? null : targetTable.Columns.FirstOrDefault(c => c.ColumnName == column.ColumnName)));
            }
            return(items);
        }