Exemplo n.º 1
0
        protected virtual void ScriptTableForeignKeys(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} foreign keys", tableName);

            messageManager.OnScriptMessage(msg);

            SqlScript script = new SqlScript();

            foreach (IForeignKey fk in table.ForeignKeys)
            {
                // only script fks on fk table
                if (fk.PrimaryTable == table)
                {
                    continue;
                }

                msg = string.Format("Scripting foreign key {0}", fk.Name);
                messageManager.OnScriptMessage(msg);

                script += scriptBuilder.Create(fk);
            }

            writer.WriteForeignKeyScript(tableName, script.ToScript());
        }
Exemplo n.º 2
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());
        }
Exemplo n.º 3
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());
        }
Exemplo n.º 4
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());
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
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());
        }