AzurePoolCrossDbGenerator/GenerateAltColumnsScript.cs
/// <summary>
/// Use an arbitrary template to generate an SQL script. 
/// </summary>
/// <param name="configFile"></param>
Use an arbitrary template to generate an SQL script.
Use an arbitrary template to generate an SQL script .
public static void GenerateAltColumnsScript(Configs.AllTables[] config)
        {
            Configs.AllTables sharedConfig = new Configs.AllTables();
            for (int i = 0; i < config.Length; i++)
            {
                sharedConfig = (Configs.AllTables)config[i].Merge(sharedConfig);
                var tableCols = DbAccess.GetIncompatibleTableColumns(config[i].masterCS, config[i].masterTableOrSP);
                var sb = new System.Text.StringBuilder();
                foreach (DbAccess.ColumnDefinition colDef in tableCols)
                {
                    string altLine = "";
                    switch (colDef.colType.ToLower())
                    {
                        case "image":
                            {
                                altLine = $"ALTER TABLE {config[i].masterTableOrSP} ALTER COLUMN {colDef.colName} varbinary(max)\nGO";
                                break;
                            }
                        case "text":
                            {
                                altLine = $"ALTER TABLE {config[i].masterTableOrSP} ALTER COLUMN {colDef.colName} nvarchar(max)\nGO";
                                break;
                            }
                        default:
                            {
                                break;
                            }
                    }
                    sb.AppendLine(altLine);
                }
                if (sb.Length == 0) continue;
                string outputContents = sb.ToString();
                string fileSuffix = string.Format(Program.FileNames.OutputFileNameMaskRunOnMaster, "x", config[i].masterDB, config[i].masterTableOrSP);
                string outputFileName = $"AlterTableColumns__{fileSuffix}{fileExtSQL}";
                Generators.SaveGeneratedScript(outputContents, outputFileName, i);
            }
        }
public static void GenerateAltColumnsScript ( Configs . AllTables [ ] config ) { Configs . AllTables sharedConfig = new Configs . AllTables ( ) ; for ( int i = 0 ; i < config . Length ; i ++ ) { sharedConfig = ( Configs . AllTables ) config [ i ] . Merge ( sharedConfig ) ; var tableCols = DbAccess . GetIncompatibleTableColumns ( config [ i ] . masterCS , config [ i ] . masterTableOrSP ) ; var sb = new System . Text . StringBuilder ( ) ; foreach ( DbAccess . ColumnDefinition colDef in tableCols ) { string altLine = " " ; switch ( colDef . colType . ToLower ( ) ) { case " " : { altLine = $" ALTER TABLE  { config [ i ] . masterTableOrSP }  ALTER COLUMN  { colDef . colName }  varbinary(max) \n GO " ; break ; } case " " : { altLine = $" ALTER TABLE  { config [ i ] . masterTableOrSP }  ALTER COLUMN  { colDef . colName }  nvarchar(max) \n GO " ; break ; } default : { break ; } } sb . AppendLine ( altLine ) ; } if ( sb . Length == 0 ) continue ; string outputContents = sb . ToString ( ) ; string fileSuffix = string . Format ( Program . FileNames . OutputFileNameMaskRunOnMaster , " " , config [ i ] . masterDB , config [ i ] . masterTableOrSP ) ; string outputFileName = $" AlterTableColumns__ { fileSuffix } { fileExtSQL } " ; Generators . SaveGeneratedScript ( outputContents , outputFileName , i ) ; } }
Use an arbitrary template to generate an SQL script.
Use an arbitrary template to generate an SQL script .
// load config data // generate output one file at a time // merge with the previous full version of the config // get the column list if there is {3} group in the template // generate one script file  // do nothing? // are there any columns to alter at all? // save one file per table
config
Configs.AllTables[]
configFile
None