Пример #1
0
        protected virtual void ScriptAlteredSproc(IProcedure srcSproc)
        {
            IProcedure targetSproc = targetDB.Procedures[srcSproc.Name];

            if (srcSproc.ProcedureText != targetSproc.ProcedureText)
            {
                messageManager.OnScriptMessage(
                    string.Format("Scripting alter sproc {0}", srcSproc.Name));

                script += scriptBuilder.Alter(srcSproc);
            }
        }
Пример #2
0
        protected virtual void ScriptRemovedColumns(ITable table)
        {
            foreach (IColumn column in table.Columns)
            {
                if (!dbComparer.Column(column).ExistsIn(sourceDB))
                {
                    messageManager.OnScriptMessage(
                        string.Format("Scripting drop column {0} for table {1}", column.Name, table.Name));

                    script += scriptBuilder.Drop(column);
                }
            }
        }
Пример #3
0
        protected virtual void ScriptNewColumns(ITable table)
        {
            foreach (IColumn column in table.Columns)
            {
                if (!dbComparer.Column(column).ExistsIn(targetDB))
                {
                    messageManager.OnScriptMessage(
                        string.Format("Scripting missing column {0} for table {1}", column.Name, table.Name));

                    script += scriptBuilder.Create(column);
                }
            }
        }
Пример #4
0
        protected void ScriptSproc(IProcedure sproc, IScriptWriter writer)
        {
            Throw.If(sproc, "sproc").IsNull();
            Throw.If(writer, "writer").IsNull();

            string name = DbObjectName.CreateDbObjectName(sproc);

            string msg = string.Format("Scripting stored procedure {0}", name);

            messageManager.OnScriptMessage(msg);

            SqlScript script = scriptBuilder.Create(sproc);

            writer.WriteSprocScript(name, script.ToScript());
        }
Пример #5
0
        protected void ScriptView(IView view, IScriptWriter writer)
        {
            Throw.If(view, "view").IsNull();
            Throw.If(writer, "writer").IsNull();

            string name = DbObjectName.CreateDbObjectName(view);

            string msg = string.Format("Scripting view {0}", name);

            messageManager.OnScriptMessage(msg);

            SqlScript script = scriptBuilder.Create(view);

            writer.WriteViewScript(name, script.ToScript());
        }
Пример #6
0
        protected void ScriptTableSchema(ITable table, IScriptWriter writer)
        {
            Throw.If(table, "table").IsNull();
            Throw.If(writer, "writer").IsNull();

            string tableName = DbObjectName.CreateDbObjectName(table);

            string msg = string.Format("Scripting {0} table schema", tableName);

            messageManager.OnScriptMessage(msg);

            SqlScript script = scriptBuilder.Create(table);

            writer.WriteTableScript(tableName, script.ToScript());
        }
Пример #7
0
        protected virtual void ScriptRemovedIndexes()
        {
            messageManager.OnScriptMessage("Starting removed indexes scripting...");

            foreach (ITable targetTable in targetDB.Tables)
            {
                foreach (IIndex index in targetTable.Indexes)
                {
                    if (!dbComparer.Index(index).ExistsIn(sourceDB))
                    {
                        messageManager.OnScriptMessage(
                            string.Format("Scripting drop index {0} for table {1}", index.Name, targetTable.Name));

                        script += scriptBuilder.Drop(index);
                    }
                }
            }
        }
Пример #8
0
        protected virtual void ScriptRemovedForeignKeys()
        {
            messageManager.OnScriptMessage("Starting removed foreign key scripting.");

            foreach (ITable table in targetDB.Tables)
            {
                foreach (IForeignKey fk in table.ForeignKeys)
                {
                    if (!dbComparer.ForeignKey(fk).ExistsIn(sourceDB))
                    {
                        messageManager.OnScriptMessage(
                            string.Format("Scripting drop foreign key {0} for table {1}", fk.Name, table.Name));

                        script += scriptBuilder.Drop(fk);
                    }
                }
            }
        }
Пример #9
0
        protected virtual void ScriptNewIndexes()
        {
            messageManager.OnScriptMessage("Starting new foreign key scripting...");

            foreach (ITable srcTable in sourceDB.Tables)
            {
                foreach (IIndex index in srcTable.Indexes)
                {
                    if (!dbComparer.Index(index).ExistsIn(targetDB))
                    {
                        messageManager.OnScriptMessage(
                            string.Format("Scripting missing index {0} for table {1}", index.Name, srcTable.Name));

                        script += scriptBuilder.Create(index);
                    }
                }
            }
        }
Пример #10
0
        protected virtual void ScriptNewForeignKeys()
        {
            messageManager.OnScriptMessage("Starting new foreign key scripting...");

            foreach (ITable srcTable in sourceDB.Tables)
            {
                foreach (IForeignKey fk in srcTable.ForeignKeys)
                {
                    if (!dbComparer.ForeignKey(fk).ExistsIn(targetDB))
                    {
                        messageManager.OnScriptMessage(
                            string.Format("Scripting missing foreign key {0} for table {1}", fk.Name, srcTable.Name));

                        script += scriptBuilder.Create(fk);
                    }
                }
            }
        }
Пример #11
0
        protected virtual void ScriptRemovedTablesAndColumns()
        {
            messageManager.OnScriptMessage("Starting removed tables scripting...");

            foreach (ITable targetTable in targetDB.Tables)
            {
                if (!dbComparer.Table(targetTable).ExistsIn(sourceDB))
                {
                    messageManager.OnScriptMessage(
                        string.Format("Scripting drop table {0}", targetTable.Name));

                    script += scriptBuilder.Drop(targetTable);
                }
                else
                {
                    ScriptRemovedColumns(targetTable);
                }
            }
        }
Пример #12
0
        // TODO: This stuff probably needs to be refactored to use IScriptWriter etc.

        protected virtual void ScriptNewTablesAndColumns()
        {
            messageManager.OnScriptMessage("Starting new table and column scripting...");

            foreach (ITable srcTable in sourceDB.Tables)
            {
                if (!dbComparer.Table(srcTable).ExistsIn(targetDB))
                {
                    messageManager.OnScriptMessage(
                        string.Format("Scripting missing table {0}", srcTable.Name));

                    script += scriptBuilder.Create(srcTable);
                }
                else
                {
                    ScriptNewColumns(srcTable);
                }
            }
        }
Пример #13
0
        /// <summary>
        /// Generates table data inserts and updates to sync two tables in
        /// different databases.
        /// </summary>
        /// <param name="migrator">The data migrator instance.</param>
        /// <param name="source">The source table to script all data from.</param>
        /// <param name="writer">The script writer strategy.</param>
        protected virtual void ScriptTableData(IDataMigrator migrator, ITable source, IScriptWriter writer)
        {
            Throw.If(source, "source").IsNull();
            Throw.If(writer, "writer").IsNull();

            string name = DbObjectName.CreateDbObjectName(source);

            messageManager.OnScriptMessage(
                string.Format("Starting table data scripting on table {0}.",
                              name));

            script = new SqlScript();

            script = migrator.ScriptAllData(source, script);
            writer.WriteTableDataScript(name, script.ToScript());

            messageManager.OnScriptMessage(
                string.Format("Finished table data scripting on table {0}.",
                              name));
        }
Пример #14
0
        protected virtual void ScriptTableDataDifferences(ITable sourceTable, ITable targetTable, IScriptWriter writer)
        {
            Throw.If(sourceTable, "sourceTable").IsNull();
            Throw.If(targetTable, "targetTable").IsNull();
            Throw.If(writer, "writer").IsNull();

            string name = DbObjectName.CreateDbObjectName(sourceTable);

            messageManager.OnScriptMessage(
                string.Format("Starting table data difference scripting on table {0}.",
                              name));

            script = new SqlScript();

            DifferentialDataMigrator migrator = new DifferentialDataMigrator();

            script = migrator.ScriptDataDifferences(sourceTable, targetTable, script);
            writer.WriteTableDataScript(name, script.ToScript());

            messageManager.OnScriptMessage(
                string.Format("Finished table data difference scripting on table {0}.",
                              name));
        }
Пример #15
0
        protected void ScriptTableIndexes(ITable table, IScriptWriter writer)
        {
            Throw.If(table, "table").IsNull();
            Throw.If(writer, "writer").IsNull();

            string tableName = DbObjectName.CreateDbObjectName(table);

            string msg = string.Format("Scripting {0} indexes", tableName);

            messageManager.OnScriptMessage(msg);

            SqlScript script = new SqlScript();

            foreach (IIndex index in table.Indexes)
            {
                msg = string.Format("Scripting index {0}", index.Name);
                messageManager.OnScriptMessage(msg);

                script += scriptBuilder.Create(index);
            }

            writer.WriteIndexScript(tableName, script.ToScript());
        }
Пример #16
0
 public SqlScript Append(SqlScript scriptToAppend)
 {
     script.Append(scriptToAppend.script);
     return(this);
 }