示例#1
0
        private static void Main(string[] args)
        {
            Console.WriteLine(Header);

            SM.DatabaseServer datasource = JsonConvert.DeserializeObject <SM.DatabaseServer>(System.IO.File.ReadAllText(FilePath));

            Server server = new Server(ConnectionManager.GetConnection(datasource));

            server.ConnectionContext.AutoDisconnectMode = AutoDisconnectMode.NoAutoDisconnect;
            server.ConnectionContext.Connect();

            var database = server.Databases[datasource.Database];

            foreach (var tableItem in datasource.Tables)
            {
                CreateTable table     = new CreateTable(database, tableItem.Schema, tableItem.Name);
                DropTable   dropTable = new DropTable(database, tableItem);

                table.IncludeTable()
                .IncludePrimaryKey()
                .IncludeForeignKey()
                .IncludeUniqueKey()
                .IncludeDefaultConstraints()
                .WriteToFile(GetOutputPath(datasource.OutputFolder, "table_" + tableItem.Name));

                dropTable.IncludeForeignKey()
                .IncludePrimaryKey()
                .IncludeUniqueKey()
                .IncludeDefaultConstraints()
                .IncludeTable()
                .WriteToFile(GetOutputPath(datasource.RollbackOutputFolder, "ROLLBACK_table_" + tableItem.Name));

                Console.WriteLine(string.Format("[{0}].[{1}] Completed.", tableItem.Schema, tableItem.Name));
            }

            foreach (var sp in datasource.StoredProcedures)
            {
                CreateSp createSp = new CreateSp(database, sp.Name, sp.Schema);
                createSp.IncludeSp().WriteToFile(GetOutputPath(datasource.OutputFolder, "sp_" + sp));
                DropSp dropSp = new DropSp(database.Name, sp.Name, sp.Schema);
                dropSp.IncludeSp().WriteToFile(GetOutputPath(datasource.RollbackOutputFolder, "ROLLBACK_sp_" + sp));
            }

            server.ConnectionContext.Disconnect();

            Console.WriteLine(Finish);
            Console.ReadLine();
        }