Esempio n. 1
1
        public override SQLScriptList ToSqlDiff()
        {
            SQLScriptList list = new SQLScriptList();

            if (this.HasState(Enums.ObjectStatusType.DropStatus))
                list.Add(Drop());
            if (this.HasState(Enums.ObjectStatusType.CreateStatus))
                list.Add(Create());
            if (this.Status == Enums.ObjectStatusType.AlterStatus)
            {
                list.AddRange(Rebuild());
            }
            list.AddRange(this.ExtendedProperties.ToSqlDiff());
            return list;
        }
Esempio n. 2
0
        public override SQLScriptList ToSqlDiff()
        {
            SQLScriptList list = new SQLScriptList();

            if (this.Status == Enums.ObjectStatusType.DropStatus)
            {
                list.AddRange(RebuildDependencys());
                list.Add(Drop());
            }
            if (this.Status == Enums.ObjectStatusType.CreateStatus)
            {
                list.Add(Create());
            }
            if (this.HasState(Enums.ObjectStatusType.RebuildStatus))
            {
                list.AddRange(Rebuild());
            }
            if (this.HasState(Enums.ObjectStatusType.ChangeOwner))
            {
                list.Add(ToSQLAlterOwner(), 0, Enums.ScripActionType.AlterAssembly);
            }
            if (this.HasState(Enums.ObjectStatusType.PermisionSet))
            {
                list.Add(ToSQLAlter(), 0, Enums.ScripActionType.AlterAssembly);
            }
            if (this.HasState(Enums.ObjectStatusType.AlterStatus))
            {
                list.AddRange(Files.ToSqlDiff());
            }
            list.AddRange(this.ExtendedProperties.ToSqlDiff());
            return(list);
        }
Esempio n. 3
0
        public override SQLScriptList ToSqlDiff(System.Collections.Generic.ICollection <ISchemaBase> schemas)
        {
            SQLScriptList list = new SQLScriptList();

            if (this.Status == ObjectStatus.Drop)
            {
                list.AddRange(RebuildDependencys());
                list.Add(Drop());
            }
            if (this.Status == ObjectStatus.Create)
            {
                list.Add(Create());
            }
            if (this.HasState(ObjectStatus.Rebuild))
            {
                list.AddRange(Rebuild());
            }
            if (this.HasState(ObjectStatus.ChangeOwner))
            {
                list.Add(ToSQLAlterOwner(), 0, ScriptAction.AlterAssembly);
            }
            if (this.HasState(ObjectStatus.PermissionSet))
            {
                list.Add(ToSQLAlter(), 0, ScriptAction.AlterAssembly);
            }
            if (this.HasState(ObjectStatus.Alter))
            {
                list.AddRange(Files.ToSqlDiff());
            }
            list.AddRange(this.ExtendedProperties.ToSqlDiff());
            return(list);
        }
Esempio n. 4
0
 public SQLScriptList RebuildDependencies()
 {
     SQLScriptList list = new SQLScriptList();
     list.AddRange(RebuildConstraint());
     list.AddRange(RebuildIndex());
     list.AddRange(RebuildFullTextIndex());
     return list;
 }
Esempio n. 5
0
        private SQLScriptList ToSQLRebuild()
        {
            var listDiff = new SQLScriptList();

            listDiff.AddRange(ToSQLDropDependencis());
            listDiff.Add(ToSQLTableRebuild(), dependenciesCount, Enums.ScripActionType.RebuildTable);
            listDiff.AddRange(ToSQLCreateDependencis());
            return(listDiff);
        }
Esempio n. 6
0
        private string GetChangeScript(Database original)
        {
            Console.WriteLine("Generating SQL file");
            var listDiff = new SQLScriptList();

            listDiff.AddRange(original.UserTypes.ToSqlDiff());
            listDiff.AddRange(original.TablesTypes.ToSqlDiff());
            listDiff.AddRange(original.Tables.ToSqlDiff());
            return(listDiff.ToSQL());
        }
Esempio n. 7
0
        public override SQLScriptList ToSqlDiff()
        {
            SQLScriptList list = new SQLScriptList();
            if (this.Status != Enums.ObjectStatusType.OriginalStatus)
                RootParent.ActionMessage.Add(this);
          
            if (this.HasState(Enums.ObjectStatusType.DropStatus))
                list.Add(Drop());
            if (this.HasState(Enums.ObjectStatusType.CreateStatus))
                list.Add(Create());
            if (this.HasState(Enums.ObjectStatusType.AlterStatus))
            {
                if (this.HasState(Enums.ObjectStatusType.RebuildDependenciesStatus))
                    list.AddRange(RebuildDependencys());

                if (!this.GetWasInsertInDiffList(Enums.ScripActionType.DropFunction))
                {
                    if (this.HasState(Enums.ObjectStatusType.RebuildStatus))
                    {
                        list.Add(Drop());
                        list.Add(Create());
                    }
                    if (this.HasState(Enums.ObjectStatusType.AlterBodyStatus))
                    {
                        int iCount = DependenciesCount;
                        list.Add(ToSQLAlter(), iCount, Enums.ScripActionType.AlterFunction);
                    }
                }
            }
            return list;
        }
Esempio n. 8
0
        public SQLScriptList ToSQLDiff()
        {
            SQLScriptList listDiff = new SQLScriptList();

            this.ForEach(item => listDiff.AddRange(item.ToSQLDiff()));
            return(listDiff);
        }
Esempio n. 9
0
        public override SQLScriptList ToSqlDiff()
        {
            SQLScriptList list = new SQLScriptList();

            if (Status != Enums.ObjectStatusType.OriginalStatus)
            {
                RootParent.ActionMessage[Parent.FullName].Add(this);
            }

            if (HasState(Enums.ObjectStatusType.DropStatus))
            {
                list.Add(Drop());
            }
            if (HasState(Enums.ObjectStatusType.CreateStatus))
            {
                list.Add(Create());
            }
            if (HasState(Enums.ObjectStatusType.AlterStatus))
            {
                list.Add(Drop());
                list.Add(Create());
            }
            if (Status == Enums.ObjectStatusType.DisabledStatus)
            {
                list.Add(ToSqlEnabled(), Parent.DependenciesCount, Enums.ScripActionType.AlterIndex);
            }

            /*if (this.Status == StatusEnum.ObjectStatusType.ChangeFileGroup)
             * {
             *  listDiff.Add(this.ToSQLDrop(this.FileGroup), ((Table)Parent).DependenciesCount, StatusEnum.ScripActionType.DropIndex);
             *  listDiff.Add(this.ToSQLAdd(), ((Table)Parent).DependenciesCount, StatusEnum.ScripActionType.AddIndex);
             * }*/
            list.AddRange(ExtendedProperties.ToSqlDiff());
            return(list);
        }
Esempio n. 10
0
 private SQLScriptList ToSQLChangeColumns()
 {
     Hashtable fields = new Hashtable();
     SQLScriptList list = new SQLScriptList();
     if ((this.Status == Enums.ObjectStatusType.AlterStatus) || (this.Status == Enums.ObjectStatusType.RebuildStatus))
     {
         foreach (ObjectDependency dependency in this.Dependencys)
         {
             ISchemaBase itemDepens = ((Database)this.Parent).Find(dependency.Name);
             if (dependency.IsCodeType)
             {
                 list.AddRange(((ICode)itemDepens).Rebuild());
             }
             if (dependency.Type == Enums.ObjectType.Table)
             {
                 Column column = ((Table)itemDepens).Columns[dependency.ColumnName];
                 if ((column.Parent.Status != Enums.ObjectStatusType.DropStatus) && (column.Parent.Status != Enums.ObjectStatusType.CreateStatus) && ((column.Status != Enums.ObjectStatusType.CreateStatus)))
                 {
                     if (!fields.ContainsKey(column.FullName))
                     {
                         if (column.HasToRebuildOnlyConstraint)
                             column.Parent.Status = Enums.ObjectStatusType.RebuildDependenciesStatus;
                         list.AddRange(column.RebuildConstraint(true));
                         list.Add("ALTER TABLE " + column.Parent.FullName + " ALTER COLUMN " + column.ToSQLRedefine(null,0, "") + "\r\nGO\r\n", 0, Enums.ScripActionType.AlterColumn);
                         /*Si la columna va a ser eliminada o la tabla va a ser reconstruida, no restaura la columna*/
                         if ((column.Status != Enums.ObjectStatusType.DropStatus) && (column.Parent.Status != Enums.ObjectStatusType.RebuildStatus))
                             list.AddRange(column.Alter( Enums.ScripActionType.AlterColumnRestore));
                         fields.Add(column.FullName, column.FullName);
                     }
                 }
             }
         }
     }
     return list;
 }
Esempio n. 11
0
        private SQLScriptList RebuildIndex()
        {
            SQLScriptList list = new SQLScriptList();

            if (HasIndexDependencies)
            {
                ((Table)Parent).Indexes.ForEach(item =>
                {
                    IndexColumn ic = item.Columns.Find(this.Id);
                    if (ic != null)
                    {
                        if (item.Status != Enums.ObjectStatusType.CreateStatus)
                        {
                            list.Add(item.Drop());
                        }
                        if (item.Status != Enums.ObjectStatusType.DropStatus)
                        {
                            list.Add(item.Create());
                        }
                        list.AddRange(RebuildFullTextIndex(item.Name));
                    }
                });
            }
            return(list);
        }
Esempio n. 12
0
        public override SQLScriptList ToSqlDiff(System.Collections.Generic.ICollection <ISchemaBase> schemas)
        {
            SQLScriptList list = new SQLScriptList();

            if (this.Status != ObjectStatus.Original)
            {
                RootParent.ActionMessage[Parent.FullName].Add(this);
            }

            if (this.HasState(ObjectStatus.Drop))
            {
                list.Add(Drop());
            }
            if (this.HasState(ObjectStatus.Create))
            {
                list.Add(Create());
            }
            if (this.HasState(ObjectStatus.Alter))
            {
                list.Add(Drop());
                list.Add(Create());
            }
            if (this.Status == ObjectStatus.Disabled)
            {
                list.Add(this.ToSqlEnabled(), Parent.DependenciesCount, ScriptAction.AlterFullTextIndex);
            }

            /*if (this.Status == StatusEnum.ObjectStatusType.ChangeFileGroup)
             * {
             *  listDiff.Add(this.ToSQLDrop(this.FileGroup), ((Table)Parent).DependenciesCount, StatusEnum.ScripActionType.DropIndex);
             *  listDiff.Add(this.ToSQLAdd(), ((Table)Parent).DependenciesCount, StatusEnum.ScripActionType.AddIndex);
             * }*/
            list.AddRange(this.ExtendedProperties.ToSqlDiff());
            return(list);
        }
Esempio n. 13
0
 public override SQLScriptList ToSqlDiff()
 {
     try
     {
         var list = new SQLScriptList();
         if (Status == Enums.ObjectStatusType.DropStatus)
         {
             if (!HasAnotherUDTClass())
             {
                 list.Add(Drop());
             }
         }
         if (HasState(Enums.ObjectStatusType.CreateStatus))
         {
             list.Add(Create());
         }
         if (Status == Enums.ObjectStatusType.AlterStatus)
         {
             if (Default.Status == Enums.ObjectStatusType.CreateStatus)
             {
                 list.Add(Default.ToSQLAddBind(), 0, Enums.ScripActionType.AddUserDataType);
             }
             if (Default.Status == Enums.ObjectStatusType.DropStatus)
             {
                 list.Add(Default.ToSQLAddUnBind(), 0, Enums.ScripActionType.UnbindRuleType);
             }
             if (Rule.Status == Enums.ObjectStatusType.CreateStatus)
             {
                 list.Add(Rule.ToSQLAddBind(), 0, Enums.ScripActionType.AddUserDataType);
             }
             if (Rule.Status == Enums.ObjectStatusType.DropStatus)
             {
                 list.Add(Rule.ToSQLAddUnBind(), 0, Enums.ScripActionType.UnbindRuleType);
             }
         }
         if (Status == Enums.ObjectStatusType.RebuildStatus)
         {
             list.AddRange(ToSQLChangeColumns());
             if (!GetWasInsertInDiffList(Enums.ScripActionType.DropUserDataType))
             {
                 list.Add(ToSqlDrop() + ToSql(), 0, Enums.ScripActionType.AddUserDataType);
             }
             else
             {
                 list.Add(Create());
             }
         }
         if (HasState(Enums.ObjectStatusType.DropOlderStatus))
         {
             list.Add(SQLDropOlder(), 0, Enums.ScripActionType.AddUserDataType);
         }
         return(list);
     }
     catch (Exception ex)
     {
         _logger.ErrorException(ex.Message, ex);
         return(null);
     }
 }
Esempio n. 14
0
 public override SQLScriptList ToSqlDiff(System.Collections.Generic.ICollection <ISchemaBase> schemas)
 {
     try
     {
         var list = new SQLScriptList();
         if (Status == Enums.ObjectStatusType.DropStatus)
         {
             if (!HasAnotherUDTClass())
             {
                 list.Add(Drop());
             }
         }
         if (HasState(Enums.ObjectStatusType.CreateStatus))
         {
             list.Add(Create());
         }
         if (Status == Enums.ObjectStatusType.AlterStatus)
         {
             if (Default.Status == Enums.ObjectStatusType.CreateStatus)
             {
                 list.Add(Default.ToSQLAddBind(), 0, Enums.ScripActionType.AddUserDataType);
             }
             if (Default.Status == Enums.ObjectStatusType.DropStatus)
             {
                 list.Add(Default.ToSQLAddUnBind(), 0, Enums.ScripActionType.UnbindRuleType);
             }
             if (Rule.Status == Enums.ObjectStatusType.CreateStatus)
             {
                 list.Add(Rule.ToSQLAddBind(), 0, Enums.ScripActionType.AddUserDataType);
             }
             if (Rule.Status == Enums.ObjectStatusType.DropStatus)
             {
                 list.Add(Rule.ToSQLAddUnBind(), 0, Enums.ScripActionType.UnbindRuleType);
             }
         }
         if (Status == Enums.ObjectStatusType.RebuildStatus)
         {
             list.AddRange(ToSQLChangeColumns());
             if (!GetWasInsertInDiffList(Enums.ScripActionType.DropUserDataType))
             {
                 list.Add(ToSqlDrop() + ToSql(), 0, Enums.ScripActionType.AddUserDataType);
             }
             else
             {
                 list.Add(Create());
             }
         }
         if (HasState(Enums.ObjectStatusType.DropOlderStatus))
         {
             list.Add(SQLDropOlder(), 0, Enums.ScripActionType.AddUserDataType);
         }
         return(list);
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 15
0
File: Rule.cs Progetto: pclancy/ODBX
        /// <summary>
        /// Devuelve el schema de diferencias del Schema en formato SQL.
        /// </summary>
        public override SQLScriptList ToSqlDiff()
        {
            SQLScriptList listDiff = new SQLScriptList();

            if (this.Status == Enums.ObjectStatusType.DropStatus)
            {
                listDiff.AddRange(ToSQLUnBindAll());
                listDiff.Add(Drop());
            }
            if (this.Status == Enums.ObjectStatusType.CreateStatus)
                listDiff.Add(Create());
            if (this.Status == Enums.ObjectStatusType.AlterStatus)
            {
                listDiff.AddRange(ToSQLUnBindAll());
                listDiff.AddRange(Rebuild());
            }
            return listDiff;
        }
Esempio n. 16
0
        public override SQLScriptList ToSqlDiff()
        {
            SQLScriptList list = new SQLScriptList();

            if (this.HasState(Enums.ObjectStatusType.DropStatus))
            {
                list.Add(Drop());
            }
            if (this.HasState(Enums.ObjectStatusType.CreateStatus))
            {
                list.Add(Create());
            }
            if (this.Status == Enums.ObjectStatusType.AlterStatus)
            {
                list.AddRange(Rebuild());
            }
            list.AddRange(this.ExtendedProperties.ToSqlDiff());
            return(list);
        }
Esempio n. 17
0
        public override SQLScriptList ToSqlDiff(System.Collections.Generic.ICollection <ISchemaBase> schemas)
        {
            SQLScriptList list = new SQLScriptList();

            if (this.HasState(ObjectStatus.Drop))
            {
                list.Add(Drop());
            }
            if (this.HasState(ObjectStatus.Create))
            {
                list.Add(Create());
            }
            if (this.Status == ObjectStatus.Alter)
            {
                list.AddRange(Rebuild());
            }
            list.AddRange(this.ExtendedProperties.ToSqlDiff());
            return(list);
        }
Esempio n. 18
0
        /// <summary>
        /// Devuelve el schema de diferencias del Schema en formato SQL.
        /// </summary>
        public override SQLScriptList ToSqlDiff(System.Collections.Generic.ICollection <ISchemaBase> schemas)
        {
            SQLScriptList list = new SQLScriptList();

            if (this.Status != ObjectStatus.Original)
            {
                RootParent.ActionMessage.Add(this);
            }

            if (this.HasState(ObjectStatus.Drop))
            {
                list.Add(Drop());
            }
            if (this.HasState(ObjectStatus.Create))
            {
                list.Add(Create());
            }

            if (this.HasState(ObjectStatus.Alter))
            {
                if (this.HasState(ObjectStatus.RebuildDependencies))
                {
                    list.AddRange(RebuildDependencys());
                }
                if (this.HasState(ObjectStatus.Rebuild))
                {
                    list.Add(Drop());
                    list.Add(Create());
                }
                if (this.HasState(ObjectStatus.AlterBody))
                {
                    int iCount = DependenciesCount;
                    list.Add(ToSQLAlter(), iCount, ScriptAction.AlterView);
                }
                if (!this.GetWasInsertInDiffList(ScriptAction.DropFunction) && (!this.GetWasInsertInDiffList(ScriptAction.AddFunction)))
                {
                    list.AddRange(Indexes.ToSqlDiff());
                }

                list.AddRange(Triggers.ToSqlDiff());
            }
            return(list);
        }
Esempio n. 19
0
        /// <summary>
        /// Devuelve el schema de diferencias del Schema en formato SQL.
        /// </summary>
        public override SQLScriptList ToSqlDiff()
        {
            SQLScriptList list = new SQLScriptList();

            if (this.Status != Enums.ObjectStatusType.OriginalStatus)
            {
                RootParent.ActionMessage.Add(this);
            }

            if (this.HasState(Enums.ObjectStatusType.DropStatus))
            {
                list.Add(Drop());
            }
            if (this.HasState(Enums.ObjectStatusType.CreateStatus))
            {
                list.Add(Create());
            }

            if (this.HasState(Enums.ObjectStatusType.AlterStatus))
            {
                if (this.HasState(Enums.ObjectStatusType.RebuildDependenciesStatus))
                {
                    list.AddRange(RebuildDependencys());
                }
                if (this.HasState(Enums.ObjectStatusType.RebuildStatus))
                {
                    list.Add(Drop());
                    list.Add(Create());
                }
                if (this.HasState(Enums.ObjectStatusType.AlterBodyStatus))
                {
                    int iCount = DependenciesCount;
                    list.Add(ToSQLAlter(), iCount, Enums.ScripActionType.AlterView);
                }
                if (!this.GetWasInsertInDiffList(Enums.ScripActionType.DropFunction) && (!this.GetWasInsertInDiffList(Enums.ScripActionType.AddFunction)))
                {
                    list.AddRange(indexes.ToSqlDiff());
                }

                list.AddRange(triggers.ToSqlDiff());
            }
            return(list);
        }
Esempio n. 20
0
        public virtual SQLScriptList ToSqlDiff(ICollection <ISchemaBase> schemas)
        {
            SQLScriptList listDiff = new SQLScriptList();

            foreach (var item in this.Where(item => (schemas.Count() == 0 || schemas.FirstOrDefault(sch => sch.Id == item.Id || (sch.Parent != null && sch.Parent.Id == item.Id)) != default(ISchemaBase))))
            {
                var childrenSchemas = schemas.Where(s => s.Parent != null && s.Parent.Id == item.Id).ToList();
                listDiff.AddRange(item.ToSqlDiff(childrenSchemas).WarnMissingScript(item));
            }
            return(listDiff);
        }
Esempio n. 21
0
        /// <summary>
        /// Devuelve el schema de diferencias del Schema en formato SQL.
        /// </summary>
        public override SQLScriptList ToSqlDiff()
        {
            SQLScriptList listDiff = new SQLScriptList();

            if (this.Status == Enums.ObjectStatusType.DropStatus)
            {
                listDiff.AddRange(ToSQLUnBindAll());
                listDiff.Add(Drop());
            }
            if (this.Status == Enums.ObjectStatusType.CreateStatus)
            {
                listDiff.Add(Create());
            }
            if (this.Status == Enums.ObjectStatusType.AlterStatus)
            {
                listDiff.AddRange(ToSQLUnBindAll());
                listDiff.AddRange(Rebuild());
            }
            return(listDiff);
        }
Esempio n. 22
0
        /// <summary>
        /// Devuelve el schema de diferencias del Schema en formato SQL.
        /// </summary>
        public override SQLScriptList ToSqlDiff(System.Collections.Generic.ICollection <ISchemaBase> schemas)
        {
            SQLScriptList listDiff = new SQLScriptList();

            if (this.Status == ObjectStatus.Drop)
            {
                listDiff.AddRange(ToSQLUnBindAll());
                listDiff.Add(Drop());
            }
            if (this.Status == ObjectStatus.Create)
            {
                listDiff.Add(Create());
            }
            if (this.Status == ObjectStatus.Alter)
            {
                listDiff.AddRange(ToSQLUnBindAll());
                listDiff.AddRange(Rebuild());
            }
            return(listDiff);
        }
Esempio n. 23
0
        private SQLScriptList ToSQLChangeColumns()
        {
            Hashtable     fields = new Hashtable();
            SQLScriptList list   = new SQLScriptList();

            if ((this.Status == Enums.ObjectStatusType.AlterStatus) || (this.Status == Enums.ObjectStatusType.RebuildStatus))
            {
                foreach (ObjectDependency dependency in this.Dependencys)
                {
                    ISchemaBase itemDepens = ((Database)this.Parent).Find(dependency.Name);
                    if (dependency.IsCodeType)
                    {
                        list.AddRange(((ICode)itemDepens).Rebuild());
                    }
                    if (dependency.Type == Enums.ObjectType.Table)
                    {
                        Column column = ((Table)itemDepens).Columns[dependency.ColumnName];
                        if ((column.Parent.Status != Enums.ObjectStatusType.DropStatus) && (column.Parent.Status != Enums.ObjectStatusType.CreateStatus) && ((column.Status != Enums.ObjectStatusType.CreateStatus)))
                        {
                            if (!fields.ContainsKey(column.FullName))
                            {
                                if (column.HasToRebuildOnlyConstraint)
                                {
                                    column.Parent.Status = Enums.ObjectStatusType.RebuildDependenciesStatus;
                                }
                                list.AddRange(column.RebuildConstraint(true));
                                list.Add("ALTER TABLE " + column.Parent.FullName + " ALTER COLUMN " + column.ToSQLRedefine(null, 0, "") + "\r\nGO\r\n", 0, Enums.ScripActionType.AlterColumn);
                                /*Si la columna va a ser eliminada o la tabla va a ser reconstruida, no restaura la columna*/
                                if ((column.Status != Enums.ObjectStatusType.DropStatus) && (column.Parent.Status != Enums.ObjectStatusType.RebuildStatus))
                                {
                                    list.AddRange(column.Alter(Enums.ScripActionType.AlterColumnRestore));
                                }
                                fields.Add(column.FullName, column.FullName);
                            }
                        }
                    }
                }
            }
            return(list);
        }
Esempio n. 24
0
        private SQLScriptList RebuildDependencys(Table table)
        {
            var list = new SQLScriptList();
            List <ISchemaBase> items = ((Database)table.Parent).Dependencies.Find(table.Id);

            items.ForEach(item => {
                ISchemaBase realItem = ((Database)table.Parent).Find(item.FullName);
                if (realItem.IsCodeType)
                {
                    list.AddRange(((ICode)realItem).Rebuild());
                }
            });
            return(list);
        }
Esempio n. 25
0
 private SQLScriptList RebuildConstraint()
 {
     SQLScriptList list = new SQLScriptList();
     ((Table)Parent).Constraints.ForEach(item =>
     {
         ConstraintColumn ic = item.Columns.Find(this.Id);
         if (ic != null)
         {
             if (item.Status != ObjectStatus.Create) list.Add(item.Drop());
             if (item.Status != ObjectStatus.Drop) list.Add(item.Create());
             list.AddRange(RebuildFullTextIndex(item.Name));
         }
     });
     return list;
 }
Esempio n. 26
0
        /// <summary>
        /// Regenera el objeto, y todos sus objetos dependientes.
        /// </summary>
        /// <returns></returns>
        public SQLScriptList Rebuild()
        {
            SQLScriptList list = new SQLScriptList();

            list.AddRange(RebuildDependencys());
            if (this.Status != Enums.ObjectStatusType.CreateStatus)
            {
                list.Add(Drop(), deepMin);
            }
            if (this.Status != Enums.ObjectStatusType.DropStatus)
            {
                list.Add(Create(), deepMax);
            }
            return(list);
        }
Esempio n. 27
0
        /// <summary>
        /// Rebuilds the object and all its dependant objects.
        /// </summary>
        /// <returns></returns>
        public SQLScriptList Rebuild()
        {
            SQLScriptList list = new SQLScriptList();

            list.AddRange(RebuildDependencies());
            if (this.Status != ObjectStatus.Create)
            {
                list.Add(Drop(), deepMin);
            }
            if (this.Status != ObjectStatus.Drop)
            {
                list.Add(Create(), deepMax);
            }
            return(list);
        }
Esempio n. 28
0
        /// <summary>
        /// Devuelve el schema de diferencias del Schema en formato SQL.
        /// </summary>
        public override SQLScriptList ToSqlDiff()
        {
            SQLScriptList list = new SQLScriptList();

            if (this.Status == Enums.ObjectStatusType.DropStatus)
            {
                list.Add(ToSqlDrop(), 0, Enums.ScripActionType.DropXMLSchema);
            }
            if (this.Status == Enums.ObjectStatusType.CreateStatus)
            {
                list.Add(ToSql(), 0, Enums.ScripActionType.AddXMLSchema);
            }
            if (this.Status == Enums.ObjectStatusType.AlterStatus)
            {
                list.AddRange(ToSQLChangeColumns());
                list.Add(ToSqlDrop() + ToSql(), 0, Enums.ScripActionType.AddXMLSchema);
            }
            return(list);
        }
Esempio n. 29
0
        /// <summary>
        /// Devuelve el schema de diferencias del Schema en formato SQL.
        /// </summary>
        public override SQLScriptList ToSqlDiff(System.Collections.Generic.ICollection <ISchemaBase> schemas)
        {
            SQLScriptList list = new SQLScriptList();

            if (this.Status == ObjectStatus.Drop)
            {
                list.Add(ToSqlDrop(), 0, ScriptAction.DropXMLSchema);
            }
            if (this.Status == ObjectStatus.Create)
            {
                list.Add(ToSql(), 0, ScriptAction.AddXMLSchema);
            }
            if (this.Status == ObjectStatus.Alter)
            {
                list.AddRange(ToSQLChangeColumns());
                list.Add(ToSqlDrop() + ToSql(), 0, ScriptAction.AddXMLSchema);
            }
            return(list);
        }
Esempio n. 30
0
        public override SQLScriptList ToSqlDiff(System.Collections.Generic.ICollection <ISchemaBase> schemas)
        {
            SQLScriptList list = new SQLScriptList();

            if (this.Status != Enums.ObjectStatusType.OriginalStatus)
            {
                RootParent.ActionMessage.Add(this);
            }

            if (this.HasState(Enums.ObjectStatusType.DropStatus))
            {
                list.Add(Drop());
            }
            if (this.HasState(Enums.ObjectStatusType.CreateStatus))
            {
                list.Add(Create());
            }
            if (this.HasState(Enums.ObjectStatusType.AlterStatus))
            {
                if (this.HasState(Enums.ObjectStatusType.RebuildDependenciesStatus))
                {
                    list.AddRange(RebuildDependencys());
                }

                if (!this.GetWasInsertInDiffList(Enums.ScripActionType.DropFunction))
                {
                    if (this.HasState(Enums.ObjectStatusType.RebuildStatus))
                    {
                        list.Add(Drop());
                        list.Add(Create());
                    }
                    if (this.HasState(Enums.ObjectStatusType.AlterBodyStatus))
                    {
                        int iCount = DependenciesCount;
                        list.Add(ToSQLAlter(), iCount, Enums.ScripActionType.AlterFunction);
                    }
                }
            }
            return(list);
        }
Esempio n. 31
0
        public override SQLScriptList ToSqlDiff(System.Collections.Generic.ICollection <ISchemaBase> schemas)
        {
            SQLScriptList list = new SQLScriptList();

            if (this.Status == ObjectStatus.Drop)
            {
                list.Add(Drop());
            }
            if (this.Status == ObjectStatus.Create)
            {
                list.Add(Create());
            }
            if (this.HasState(ObjectStatus.Alter))
            {
                list.AddRange(Rebuild());
            }
            if (this.HasState(ObjectStatus.Disabled))
            {
                list.Add(this.ToSQLEnabledDisabled(), 0, ScriptAction.EnabledTrigger);
            }
            return(list);
        }
Esempio n. 32
0
        public override SQLScriptList ToSqlDiff()
        {
            SQLScriptList list = new SQLScriptList();

            if (this.Status == Enums.ObjectStatusType.DropStatus)
            {
                list.Add(Drop());
            }
            if (this.Status == Enums.ObjectStatusType.CreateStatus)
            {
                list.Add(Create());
            }
            if (this.HasState(Enums.ObjectStatusType.AlterStatus))
            {
                list.AddRange(Rebuild());
            }
            if (this.HasState(Enums.ObjectStatusType.DisabledStatus))
            {
                list.Add(this.ToSQLEnabledDisabled(), 0, Enums.ScripActionType.EnabledTrigger);
            }
            return(list);
        }
Esempio n. 33
0
        private SQLScriptList RebuildDependencys(List <string> depends, int deepMin, int deepMax)
        {
            int           newDeepMax = (deepMax != 0) ? deepMax + 1 : 0;
            int           newDeepMin = (deepMin != 0) ? deepMin - 1 : 0;
            SQLScriptList list       = new SQLScriptList();

            for (int j = 0; j < depends.Count; j++)
            {
                ISchemaBase item = ((Database)Parent).Find(depends[j]);
                if (item != null)
                {
                    if ((item.Status != Enums.ObjectStatusType.CreateStatus) && (item.Status != Enums.ObjectStatusType.DropStatus))
                    {
                        if ((item.ObjectType != Enums.ObjectType.CLRStoreProcedure) && (item.ObjectType != Enums.ObjectType.Assembly) && (item.ObjectType != Enums.ObjectType.UserDataType) && (item.ObjectType != Enums.ObjectType.View) && (item.ObjectType != Enums.ObjectType.Function))
                        {
                            newDeepMin = 0;
                            newDeepMax = 0;
                        }
                        if (item.Status != Enums.ObjectStatusType.DropStatus)
                        {
                            if (!((item.Parent.HasState(Enums.ObjectStatusType.RebuildStatus)) && (item.ObjectType == Enums.ObjectType.Trigger)))
                            {
                                list.Add(item.Drop(), newDeepMin);
                            }
                        }
                        if ((this.Status != Enums.ObjectStatusType.DropStatus) && (item.Status != Enums.ObjectStatusType.CreateStatus))
                        {
                            list.Add(item.Create(), newDeepMax);
                        }
                        if (item.IsCodeType)
                        {
                            list.AddRange(RebuildDependencys(((ICode)item).DependenciesOut, newDeepMin, newDeepMax));
                        }
                    }
                }
            }
            ;
            return(list);
        }
Esempio n. 34
0
        public override SQLScriptList ToSqlDiff(List <ISchemaBase> schemas)
        {
            var isAzure10 = this.Info.Version == DatabaseInfo.VersionTypeEnum.SQLServerAzure10;

            var listDiff = new SQLScriptList();

            listDiff.Add(new SQLScript(String.Format(@"/*

    Open DBDiff {0}
    http://opendbiff.codeplex.com/

    Script created by {1}\{2} on {3} at {4}.

    Created on:  {5}
    Source:      {6} on {7}
    Destination: {8} on {9}

*/

",
                                                     System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                                                     Environment.UserDomainName,
                                                     Environment.UserName,
                                                     DateTime.Now.ToShortDateString(),
                                                     DateTime.Now.ToLongTimeString(),
                                                     Environment.MachineName,
                                                     SourceInfo != null ? SourceInfo.Database : "Uknown",
                                                     SourceInfo != null ? SourceInfo.Server : "Uknown",
                                                     Info != null ? Info.Database : "Uknown",
                                                     Info != null ? Info.Server : "Uknown",
                                                     0), 0, Enums.ScripActionType.None));
            if (!isAzure10)
            {
                listDiff.Add("USE [" + Name + "]\r\nGO\r\n\r\n", 0, Enums.ScripActionType.UseDatabase);
                listDiff.AddRange(Assemblies.ToSqlDiff(schemas));
                listDiff.AddRange(UserTypes.ToSqlDiff(schemas));
            }
            listDiff.AddRange(TablesTypes.ToSqlDiff(schemas));
            listDiff.AddRange(Tables.ToSqlDiff(schemas));
            listDiff.AddRange(Rules.ToSqlDiff(schemas));
            listDiff.AddRange(Schemas.ToSqlDiff(schemas));
            listDiff.AddRange(XmlSchemas.ToSqlDiff(schemas));
            listDiff.AddRange(Procedures.ToSqlDiff(schemas));
            if (!isAzure10)
            {
                listDiff.AddRange(CLRProcedures.ToSqlDiff(schemas));
                listDiff.AddRange(CLRFunctions.ToSqlDiff(schemas));
                listDiff.AddRange(FileGroups.ToSqlDiff(schemas));
            }
            listDiff.AddRange(DDLTriggers.ToSqlDiff(schemas));
            listDiff.AddRange(Synonyms.ToSqlDiff(schemas));
            listDiff.AddRange(Views.ToSqlDiff(schemas));
            listDiff.AddRange(Users.ToSqlDiff(schemas));
            listDiff.AddRange(Functions.ToSqlDiff(schemas));
            listDiff.AddRange(Roles.ToSqlDiff(schemas));
            listDiff.AddRange(PartitionFunctions.ToSqlDiff(schemas));
            listDiff.AddRange(PartitionSchemes.ToSqlDiff(schemas));
            if (!isAzure10)
            {
                listDiff.AddRange(FullText.ToSqlDiff(schemas));
            }
            return(listDiff);
        }
Esempio n. 35
0
 /// <summary>
 /// Regenera el objeto, y todos sus objetos dependientes.
 /// </summary>
 /// <returns></returns>
 public SQLScriptList Rebuild()
 {
     SQLScriptList list = new SQLScriptList();
     list.AddRange(RebuildDependencys());
     if (this.Status != Enums.ObjectStatusType.CreateStatus) list.Add(Drop(), deepMin);
     if (this.Status != Enums.ObjectStatusType.DropStatus) list.Add(Create(), deepMax);
     return list;
 }
Esempio n. 36
0
        public override SQLScriptList ToSqlDiff()
        {
            SQLScriptList list = new SQLScriptList();

            if (this.Status == Enums.ObjectStatusType.DropStatus)
            {
                list.AddRange(RebuildDependencys());
                list.Add(Drop());
            }
            if (this.Status == Enums.ObjectStatusType.CreateStatus)
                list.Add(Create());
            if (this.HasState(Enums.ObjectStatusType.RebuildStatus))
                list.AddRange(Rebuild());
            if (this.HasState(Enums.ObjectStatusType.ChangeOwner))
                list.Add(ToSQLAlterOwner(), 0, Enums.ScripActionType.AlterAssembly);
            if (this.HasState(Enums.ObjectStatusType.PermisionSet))
                list.Add(ToSQLAlter(), 0, Enums.ScripActionType.AlterAssembly);
            if (this.HasState(Enums.ObjectStatusType.AlterStatus))
                list.AddRange(Files.ToSqlDiff());
            list.AddRange(this.ExtendedProperties.ToSqlDiff());
            return list;
        }
Esempio n. 37
0
 private SQLScriptList RebuildDependencys(Table table)
 {
     var list = new SQLScriptList();
     List<ISchemaBase> items = ((Database) table.Parent).Dependencies.Find(table.Id);
     items.ForEach(item =>
                       {
                           ISchemaBase realItem = ((Database) table.Parent).Find(item.FullName);
                           if (realItem.IsCodeType)
                               list.AddRange(((ICode) realItem).Rebuild());
                       });
     return list;
 }
Esempio n. 38
0
        /*public List<ISchemaBase> FindAllByColumn(String ColumnName)
        {
            this.t
        }*/

        public override SQLScriptList ToSqlDiff()
        {
            var listDiff = new SQLScriptList();
            listDiff.Add("USE [" + Name + "]\r\nGO\r\n\r\n", 0, Enums.ScripActionType.UseDatabase);
            listDiff.AddRange(Assemblies.ToSqlDiff());
            listDiff.AddRange(Defaults.ToSqlDiff());
            listDiff.AddRange(UserTypes.ToSqlDiff());
            listDiff.AddRange(TablesTypes.ToSqlDiff());
            listDiff.AddRange(Tables.ToSqlDiff());
            listDiff.AddRange(Rules.ToSqlDiff());
            listDiff.AddRange(Schemas.ToSqlDiff());
            listDiff.AddRange(XmlSchemas.ToSqlDiff());
            listDiff.AddRange(Procedures.ToSqlDiff());
            listDiff.AddRange(CLRProcedures.ToSqlDiff());
            listDiff.AddRange(CLRFunctions.ToSqlDiff());
            listDiff.AddRange(FileGroups.ToSqlDiff());
            listDiff.AddRange(DDLTriggers.ToSqlDiff());
            listDiff.AddRange(Synonyms.ToSqlDiff());
            listDiff.AddRange(Views.ToSqlDiff());
            listDiff.AddRange(Users.ToSqlDiff());
            listDiff.AddRange(Functions.ToSqlDiff());
            listDiff.AddRange(Roles.ToSqlDiff());
            listDiff.AddRange(PartitionFunctions.ToSqlDiff());
            listDiff.AddRange(PartitionSchemes.ToSqlDiff());
            listDiff.AddRange(FullText.ToSqlDiff());
            return listDiff;
        }
Esempio n. 39
0
 public override SQLScriptList ToSqlDiff()
 {
     SQLScriptList list = new SQLScriptList();
     if (this.Status == Enums.ObjectStatusType.DropStatus)
         list.Add(Drop());
     if (this.Status == Enums.ObjectStatusType.CreateStatus)
         list.Add(Create());
     if (this.HasState(Enums.ObjectStatusType.AlterStatus))
         list.AddRange(Rebuild());
     if (this.HasState(Enums.ObjectStatusType.DisabledStatus))
         list.Add(this.ToSQLEnabledDisabled(), 0, Enums.ScripActionType.EnabledTrigger);
     return list;
 }
Esempio n. 40
0
        /// <summary>
        /// Devuelve el schema de diferencias del Schema en formato SQL.
        /// </summary>
        public override SQLScriptList ToSqlDiff()
        {
            SQLScriptList list = new SQLScriptList();

            if (this.Status == Enums.ObjectStatusType.DropStatus)
            {
                list.Add(ToSqlDrop(), 0, Enums.ScripActionType.DropXMLSchema);
            }
            if (this.Status == Enums.ObjectStatusType.CreateStatus)
            {
                list.Add(ToSql(), 0, Enums.ScripActionType.AddXMLSchema);
            }
            if (this.Status == Enums.ObjectStatusType.AlterStatus)
            {
                list.AddRange(ToSQLChangeColumns());
                list.Add(ToSqlDrop() + ToSql(), 0, Enums.ScripActionType.AddXMLSchema);
            }
            return list;
        }
Esempio n. 41
0
        public override SQLScriptList ToSqlDiff(List<ISchemaBase> schemas)
        {
            var isAzure10 = this.Info.Version == DatabaseInfo.VersionTypeEnum.SQLServerAzure10;

            var listDiff = new SQLScriptList();
            listDiff.Add(new SQLScript(String.Format(@"/*

    Open DBDiff {0}
    http://opendbiff.codeplex.com/

    Script created by {1}\{2} on {3} at {4}.

    Created on:  {5}
    Source:      {6} on {7}
    Destination: {8} on {9}

*/

",
                System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                Environment.UserDomainName, 
                Environment.UserName,
                DateTime.Now.ToShortDateString(),
                DateTime.Now.ToLongTimeString(),
                Environment.MachineName,
                SourceInfo != null ? SourceInfo.Database : "Uknown",
                SourceInfo != null ? SourceInfo.Server : "Uknown",
                Info != null ? Info.Database : "Uknown",
                Info != null ? Info.Server : "Uknown",
                0), 0, Enums.ScripActionType.None));
            if (!isAzure10)
            {
                listDiff.Add("USE [" + Name + "]\r\nGO\r\n\r\n", 0, Enums.ScripActionType.UseDatabase);
                listDiff.AddRange(Assemblies.ToSqlDiff(schemas));
                listDiff.AddRange(UserTypes.ToSqlDiff(schemas));
            }
			listDiff.AddRange(TablesTypes.ToSqlDiff(schemas));
			listDiff.AddRange(Tables.ToSqlDiff(schemas));
			listDiff.AddRange(Rules.ToSqlDiff(schemas));
			listDiff.AddRange(Schemas.ToSqlDiff(schemas));
			listDiff.AddRange(XmlSchemas.ToSqlDiff(schemas));
			listDiff.AddRange(Procedures.ToSqlDiff(schemas));
            if (!isAzure10)
            {
                listDiff.AddRange(CLRProcedures.ToSqlDiff(schemas));
                listDiff.AddRange(CLRFunctions.ToSqlDiff(schemas));
                listDiff.AddRange(FileGroups.ToSqlDiff(schemas));
            }
			listDiff.AddRange(DDLTriggers.ToSqlDiff(schemas));
			listDiff.AddRange(Synonyms.ToSqlDiff(schemas));
			listDiff.AddRange(Views.ToSqlDiff(schemas));
			listDiff.AddRange(Users.ToSqlDiff(schemas));
			listDiff.AddRange(Functions.ToSqlDiff(schemas));
			listDiff.AddRange(Roles.ToSqlDiff(schemas));
			listDiff.AddRange(PartitionFunctions.ToSqlDiff(schemas));
			listDiff.AddRange(PartitionSchemes.ToSqlDiff(schemas));
            if (!isAzure10)
            {
                listDiff.AddRange(FullText.ToSqlDiff(schemas));
            }
            return listDiff;
        }
Esempio n. 42
0
 private SQLScriptList RebuildDependencys(List<string> depends, int deepMin, int deepMax)
 {
     int newDeepMax = (deepMax != 0) ? deepMax + 1 : 0;
     int newDeepMin = (deepMin != 0) ? deepMin - 1 : 0;
     SQLScriptList list = new SQLScriptList();
     for (int j = 0; j < depends.Count; j++)
     {
         ISchemaBase item = ((Database)Parent).Find(depends[j]);
         if (item != null)
         {
             if ((item.Status != Enums.ObjectStatusType.CreateStatus) && (item.Status != Enums.ObjectStatusType.DropStatus))
             {
                 if ((item.ObjectType != Enums.ObjectType.CLRStoreProcedure) && (item.ObjectType != Enums.ObjectType.Assembly) && (item.ObjectType != Enums.ObjectType.UserDataType) && (item.ObjectType != Enums.ObjectType.View) && (item.ObjectType != Enums.ObjectType.Function))
                 {
                     newDeepMin = 0;
                     newDeepMax = 0;
                 }
                 if (item.Status != Enums.ObjectStatusType.DropStatus)
                 {
                     if (!((item.Parent.HasState(Enums.ObjectStatusType.RebuildStatus)) && (item.ObjectType == Enums.ObjectType.Trigger)))
                         list.Add(item.Drop(), newDeepMin);
                 }
                 if ((this.Status != Enums.ObjectStatusType.DropStatus) && (item.Status != Enums.ObjectStatusType.CreateStatus))
                     list.Add(item.Create(), newDeepMax);
                 if (item.IsCodeType)
                     list.AddRange(RebuildDependencys(((ICode)item).DependenciesOut, newDeepMin, newDeepMax));
             }
         }
     };
     return list;
 }
Esempio n. 43
0
 private SQLScriptList ToSQLChangeColumns()
 {
     var fields = new Hashtable();
     var list = new SQLScriptList();
     var listDependencys = new SQLScriptList();
     if ((Status == Enums.ObjectStatusType.AlterStatus) || (Status == Enums.ObjectStatusType.RebuildStatus))
     {
         foreach (ObjectDependency dependency in Dependencys)
         {
             ISchemaBase itemDepens = ((Database) Parent).Find(dependency.Name);
             /*Si la dependencia es una funcion o una vista, reconstruye el objecto*/
             if (dependency.IsCodeType)
             {
                 if (itemDepens != null)
                     list.AddRange(((ICode) itemDepens).Rebuild());
             }
             /*Si la dependencia es una tabla, reconstruye los indices, constraint y columnas asociadas*/
             if (dependency.Type == Enums.ObjectType.Table)
             {
                 Column column = ((Table) itemDepens).Columns[dependency.ColumnName];
                 if ((column.Parent.Status != Enums.ObjectStatusType.DropStatus) &&
                     (column.Parent.Status != Enums.ObjectStatusType.CreateStatus) &&
                     ((column.Status != Enums.ObjectStatusType.CreateStatus) || (column.IsComputed)))
                 {
                     if (!fields.ContainsKey(column.FullName))
                     {
                         listDependencys.AddRange(RebuildDependencys((Table) itemDepens));
                         if (column.HasToRebuildOnlyConstraint)
                             //column.Parent.Status = Enums.ObjectStatusType.AlterRebuildDependenciesStatus;
                             list.AddRange(column.RebuildDependencies());
                         if (!column.IsComputed)
                         {
                             list.AddRange(column.RebuildConstraint(true));
                             list.Add(
                                 "ALTER TABLE " + column.Parent.FullName + " ALTER COLUMN " +
                                 column.ToSQLRedefine(Type, Size, null) + "\r\nGO\r\n", 0,
                                 Enums.ScripActionType.AlterColumn);
                             /*Si la columna va a ser eliminada o la tabla va a ser reconstruida, no restaura la columna*/
                             if ((column.Status != Enums.ObjectStatusType.DropStatus) &&
                                 (column.Parent.Status != Enums.ObjectStatusType.RebuildStatus))
                                 list.AddRange(column.Alter(Enums.ScripActionType.AlterColumnRestore));
                         }
                         else
                         {
                             if (column.Status != Enums.ObjectStatusType.CreateStatus)
                             {
                                 if (!column.GetWasInsertInDiffList(Enums.ScripActionType.AlterColumnFormula))
                                 {
                                     column.SetWasInsertInDiffList(Enums.ScripActionType.AlterColumnFormula);
                                     list.Add(column.ToSqlDrop(), 0, Enums.ScripActionType.AlterColumnFormula);
                                     List<ISchemaBase> drops =
                                         ((Database) column.Parent.Parent).Dependencies.Find(column.Parent.Id,
                                                                                             column.Id, 0);
                                     drops.ForEach(item =>
                                                       {
                                                           if (item.Status != Enums.ObjectStatusType.CreateStatus)
                                                               list.Add(item.Drop());
                                                           if (item.Status != Enums.ObjectStatusType.DropStatus)
                                                               list.Add(item.Create());
                                                       });
                                     /*Si la columna va a ser eliminada o la tabla va a ser reconstruida, no restaura la columna*/
                                     if ((column.Status != Enums.ObjectStatusType.DropStatus) &&
                                         (column.Parent.Status != Enums.ObjectStatusType.RebuildStatus))
                                         list.Add(column.ToSqlAdd(), 0,
                                                  Enums.ScripActionType.AlterColumnFormulaRestore);
                                 }
                             }
                         }
                         fields.Add(column.FullName, column.FullName);
                     }
                 }
             }
         }
     }
     list.AddRange(listDependencys);
     return list;
 }
Esempio n. 44
0
        public override SQLScriptList ToSqlDiff()
        {
            SQLScriptList list = new SQLScriptList();
            if (Status != Enums.ObjectStatusType.OriginalStatus)
                RootParent.ActionMessage[Parent.FullName].Add(this);

            if (HasState(Enums.ObjectStatusType.DropStatus))
                list.Add(Drop());
            if (HasState(Enums.ObjectStatusType.CreateStatus))
                list.Add(Create());
            if (HasState(Enums.ObjectStatusType.AlterStatus))
            {
                list.Add(Drop());
                list.Add(Create());
            }
            if (Status == Enums.ObjectStatusType.DisabledStatus)
            {
                list.Add(ToSqlEnabled(), Parent.DependenciesCount, Enums.ScripActionType.AlterIndex);
            }
            /*if (this.Status == StatusEnum.ObjectStatusType.ChangeFileGroup)
            {
                listDiff.Add(this.ToSQLDrop(this.FileGroup), ((Table)Parent).DependenciesCount, StatusEnum.ScripActionType.DropIndex);
                listDiff.Add(this.ToSQLAdd(), ((Table)Parent).DependenciesCount, StatusEnum.ScripActionType.AddIndex);
            }*/
            list.AddRange(ExtendedProperties.ToSqlDiff());
            return list;
        }
Esempio n. 45
0
        public override SQLScriptList ToSqlDiff(List<ISchemaBase> schemas)
        {
            var isAzure10 = this.Info.Version == DatabaseInfo.VersionTypeEnum.SQLServerAzure10;

            var listDiff = new SQLScriptList();
            listDiff.Add(new SQLScript(String.Format(@"/*

            Open DBDiff {0}
            http://opendbiff.codeplex.com/

            Script created by {1}\{2} on {3} at {4}.

            Created on:  {5}
            Source:      {6} on {7}
            Destination: {8} on {9}

            */

            ",
                System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                Environment.UserDomainName,
                Environment.UserName,
                DateTime.Now.ToShortDateString(),
                DateTime.Now.ToLongTimeString(),
                Environment.MachineName,
                SourceInfo != null ? SourceInfo.Database : "Uknown",
                SourceInfo != null ? SourceInfo.Server : "Uknown",
                Info != null ? Info.Database : "Uknown",
                Info != null ? Info.Server : "Uknown",
                0), 0, Enums.ScripActionType.None));
            listDiff.Add(new SQLScript(String.Format(@"
            SET NOEXEC OFF
            SET ANSI_WARNINGS ON
            SET XACT_ABORT ON
            SET IMPLICIT_TRANSACTIONS OFF
            SET ARITHABORT ON
            SET NOCOUNT ON
            SET QUOTED_IDENTIFIER ON
            SET NUMERIC_ROUNDABORT OFF
            SET CONCAT_NULL_YIELDS_NULL ON
            SET ANSI_NULLS ON
            SET ANSI_PADDING ON
            GO
            "), 0, Enums.ScripActionType.PreSets));
            if (!isAzure10)
            {
                listDiff.Add("USE [" + Name + "]\r\nGO\r\n\r\n", 0, Enums.ScripActionType.UseDatabase);
                listDiff.AddRange(Assemblies.ToSqlDiff(schemas));
                listDiff.AddRange(UserTypes.ToSqlDiff(schemas));
                listDiff.Add("BEGIN TRAN\r\nGO\r\n\r\n", 0, Enums.ScripActionType.BeginTransaction);
            }
            listDiff.AddRange(TablesTypes.ToSqlDiff(schemas));
            listDiff.AddRange(Tables.ToSqlDiff(schemas));
            listDiff.AddRange(Rules.ToSqlDiff(schemas));
            listDiff.AddRange(Schemas.ToSqlDiff(schemas));
            listDiff.AddRange(XmlSchemas.ToSqlDiff(schemas));
            listDiff.AddRange(Procedures.ToSqlDiff(schemas));
            if (!isAzure10)
            {
                listDiff.AddRange(CLRProcedures.ToSqlDiff(schemas));
                listDiff.AddRange(CLRFunctions.ToSqlDiff(schemas));
                listDiff.AddRange(FileGroups.ToSqlDiff(schemas));
            }
            listDiff.AddRange(DDLTriggers.ToSqlDiff(schemas));
            listDiff.AddRange(Synonyms.ToSqlDiff(schemas));
            listDiff.AddRange(Views.ToSqlDiff(schemas));
            listDiff.AddRange(Users.ToSqlDiff(schemas));
            listDiff.AddRange(Functions.ToSqlDiff(schemas));
            listDiff.AddRange(Roles.ToSqlDiff(schemas));
            listDiff.AddRange(PartitionFunctions.ToSqlDiff(schemas));
            listDiff.AddRange(PartitionSchemes.ToSqlDiff(schemas));
            if (!isAzure10)
            {
                listDiff.AddRange(FullText.ToSqlDiff(schemas));
                listDiff.Add("IF @@TRANCOUNT>0\r\n\tCOMMIT\r\nGO\r\n\r\n", 0, Enums.ScripActionType.EndTransaction);
            }
            listDiff.Add("SET NOEXEC OFF\r\n", 0, Enums.ScripActionType.PostSets);
            return listDiff;
        }
Esempio n. 46
0
 public override SQLScriptList ToSqlDiff()
 {
     try
     {
         var list = new SQLScriptList();
         if (Status == Enums.ObjectStatusType.DropStatus)
         {
             if (!HasAnotherUDTClass())
                 list.Add(Drop());
         }
         if (HasState(Enums.ObjectStatusType.CreateStatus))
         {
             list.Add(Create());
         }
         if (Status == Enums.ObjectStatusType.AlterStatus)
         {
             if (Default.Status == Enums.ObjectStatusType.CreateStatus)
                 list.Add(Default.ToSQLAddBind(), 0, Enums.ScripActionType.AddUserDataType);
             if (Default.Status == Enums.ObjectStatusType.DropStatus)
                 list.Add(Default.ToSQLAddUnBind(), 0, Enums.ScripActionType.UnbindRuleType);
             if (Rule.Status == Enums.ObjectStatusType.CreateStatus)
                 list.Add(Rule.ToSQLAddBind(), 0, Enums.ScripActionType.AddUserDataType);
             if (Rule.Status == Enums.ObjectStatusType.DropStatus)
                 list.Add(Rule.ToSQLAddUnBind(), 0, Enums.ScripActionType.UnbindRuleType);
         }
         if (Status == Enums.ObjectStatusType.RebuildStatus)
         {
             list.AddRange(ToSQLChangeColumns());
             if (!GetWasInsertInDiffList(Enums.ScripActionType.DropUserDataType))
             {
                 list.Add(ToSqlDrop() + ToSql(), 0, Enums.ScripActionType.AddUserDataType);
             }
             else
                 list.Add(Create());
         }
         if (HasState(Enums.ObjectStatusType.DropOlderStatus))
         {
             list.Add(SQLDropOlder(), 0, Enums.ScripActionType.AddUserDataType);
         }
         return list;
     }
     catch (Exception ex)
     {
         return null;
     }
 }