private void Execute(string routinesFile) { DimConsole.WriteIntro("Executing the current routines script."); if (File.Exists(routinesFile)) { DimConsole.WriteLine("Backing up existing database first."); Backups.SaveFile(base.DryRun, completedCallback : delegate(string filePath) { DimConsole.WriteLine("Backup complete:", filePath); }); if (!base.DryRun) { // using(var db = new DatabaseCommander()) // { DatabaseProvider.Manager.Execute(File.ReadAllText(routinesFile)); // } } DimConsole.WriteLine("Routines script executed!"); } else { DimConsole.WriteLine("routines.sql file does not exist."); } }
public override int Run(string[] remainingArguments) { DimConsole.WriteIntro("Initialising a new Dim project."); if (!Local.LocalConfigExists) { var config = new ConfigFile(defaultSettings: true) { Host = this.Host, Port = this.Port, Username = this.Username, Password = this.Password, Schema = this.Schema }; if (!base.DryRun) { Local.SaveConfig(config); } DimConsole.WriteLine("New config file created.", Local.LocalDimConfig); } DimConsole.WriteLine("New Dim project initialised!"); return(0); }
public override int Run(string[] remainingArguments) { if (!Program.IsCorrectlySetup()) { return(0); } DimConsole.WriteIntro("Creating a new file"); var universalNow = DateTime.Now.ToUniversalTime(); var fileName = "{0}-{1}.sql"; if (!string.IsNullOrEmpty(this.Desc)) { fileName = "{0}-{1}-{2}.sql"; } fileName = string.Format(fileName, universalNow.ToString("yyyyMMdd"), universalNow.Ticks.ToString(), this.Desc); if (!base.DryRun) { File.Create(Local.ConfigFile.Patches.GetFullPath() + @"\" + fileName); } DimConsole.WriteLine("A new file has been created for you to use. ", fileName); // TODO Allow select folder, and if RunOnce then say "Don't edit after you have shared it with others." return(0); }
private void Execute() { DimConsole.WriteIntro("Executing the current baseline script."); if (File.Exists(this.BaselineFilePath)) { DimConsole.WriteLine("Backing up existing database first."); Backups.SaveFile(base.DryRun, completedCallback : delegate(string filePath) { DimConsole.WriteLine("Backup completed:", filePath); }); if (!base.DryRun) { DatabaseProvider.Manager.CreateSchema(); DatabaseProvider.Manager.Execute(File.ReadAllText(this.BaselineFilePath)); } DimConsole.WriteLine("Baseline script executed!"); } else { DimConsole.WriteLine("The baseline file does not exist."); } }
public override int Run(string[] remainingArguments) { if (!Program.IsCorrectlySetup()) { return(0); } DimConsole.WriteIntro("Checking status against the database"); base.CheckRecordsTableExists(); var runFiles = DimFileProcessor.GetRunFiles(); if (runFiles.Count > 0) { // Display count of files found. DimConsole.WriteLine(string.Format("{0} script(s) found to be run.", runFiles.Count)); // Display names of files found. for (int i = 0, l = runFiles.Count; i < l; i++) { int count = i + 1; var fileName = Path.GetFileName(runFiles[i].FileName); DimConsole.WriteLine(string.Format("{0}. \"{1}\"", count, fileName)); } } else { DimConsole.WriteLine("No scripts found to be run."); } return(0); }
public override int Run(string[] remainingArguments) { if (!Program.IsCorrectlySetup()) { return(0); } DimConsole.WriteIntro("Run updates on the database"); base.CheckRecordsTableExists(); var runFiles = DimFileProcessor.GetRunFiles(); if (runFiles.Count > 0) { // Display count of files found. DimConsole.WriteLine(string.Format("{0} script(s) found to be run.", runFiles.Count)); // Display names of files found. for (int i = 0, l = runFiles.Count; i < l; i++) { int count = i + 1; var fileName = Path.GetFileName(runFiles[i].FileName); DimConsole.WriteLine(string.Format("{0}. \"{1}\"", count, fileName)); } // Backup before running anything (use for rollback) DimConsole.WriteLine("Backing up database (local backup)"); Backups.SaveFile(base.DryRun, completedCallback : delegate(string fileName) { DimConsole.WriteLine("Completed backup:", fileName); }); // Execute all new patches foreach (var file in runFiles) { DimConsole.WriteLine("Executing: \"" + Path.GetFileName(file.FileName) + "\""); DimFileProcessor.ExecuteFile(file, base.DryRun, successCallback : delegate() { DimConsole.WriteLine("Executed successfully!"); }, failureCallback : delegate(string message) { DimConsole.WriteLine("Execution failed:", message); }); } DimConsole.WriteLine("Update completed."); } else { DimConsole.WriteLine("No scripts found to be run."); } return(0); }
private void Save() { DimConsole.WriteIntro("Saving a new baseline script."); if (!this.DryRun) { File.WriteAllText(this.BaselineFilePath, DatabaseProvider.Manager.DumpSchema()); } DimConsole.WriteLine("Baseline file saved! Now you can share changes with others.", this.BaselineFilePath); }
protected void CheckRecordsTableExists() { // Check for the dimfiles if (!DatabaseProvider.Commander.DimLogExists()) { DimConsole.WriteInfoLine("Required dimfiles table doesn't exist.", "Creating empty table."); if (!this.DryRun) { DatabaseProvider.Commander.RunCreateDimLog(); } DimConsole.WriteInfoLine("New dimfiles table created."); } }
private void Save(string routinesFile) { DimConsole.WriteIntro("Saving a new routines script."); if (!this.DryRun) { // using(var db = new DatabaseCommander()) // { DatabaseProvider.Commander.DumpRoutines(routinesFile); // } } DimConsole.WriteLine("Routines Saved!", routinesFile); }
public override int Run(string[] remainingArguments) { if (!Program.IsCorrectlySetup()) { return(0); } DimConsole.WriteIntro("Running a complete backup"); //CreateBackup(base.DryRun, this.FilePath); Backups.SaveFile(base.DryRun, this.FilePath, delegate(string filePath) { DimConsole.WriteLine("Backup completed:", filePath); }); return(0); }
private void SettingValues() { DimConsole.WriteIntro("Setting fields in the local config file"); var config = Local.ConfigFile; if (!string.IsNullOrEmpty(this.Host)) { config.Host = this.Host; DimConsole.WriteLine(string.Format("'Host' has been set to '{0}'", config.Host)); } if (!string.IsNullOrEmpty(this.Port)) { config.Port = this.Port; DimConsole.WriteLine(string.Format("'Port' has been set to '{0}'", config.Port)); } if (!string.IsNullOrEmpty(this.Username)) { config.Username = this.Username; DimConsole.WriteLine(string.Format("'Username' has been set to '{0}'", config.Username)); } if (!string.IsNullOrEmpty(this.Password)) { config.Password = this.Password; DimConsole.WriteLine(string.Format("'Password' has been set to '{0}'", config.Password)); } if (!string.IsNullOrEmpty(this.Schema)) { config.Schema = this.Schema; DimConsole.WriteLine(string.Format("'Schema' has been set to '{0}'", config.Schema)); } if (!string.IsNullOrEmpty(this.MySqlPath)) { config.MySqlPath = this.MySqlPath; DimConsole.WriteLine(string.Format("'MySqlPath' has been set to '{0}'", config.MySqlPath)); } if (!base.DryRun) { Local.SaveConfig(config); } }
public override int Run(string[] remainingArguments) { DimConsole.WriteIntro("Run a test"); var allRecords = DatabaseProvider.RecordRepository.GetAll(); DimConsole.WriteLine("Read from DB (count: " + allRecords.Count + ")"); foreach (var record in allRecords) { DimConsole.WriteInfoLine("'" + record.FileName + "'", record.FileHash, record.Executed.ToString("dd-MMM-yyy hh:mm:ss")); } var filesOnSystem = DimFileProcessor.GetAllFiles(); DimConsole.WriteLine("Read from FS (count : " + filesOnSystem.Count + ")"); foreach (var file in filesOnSystem) { var hash = DimFileProcessor.GetFileHash(file); DimConsole.WriteInfoLine("'" + file.FileName + "'", file.Parent.RunKind.ToString(), hash); } var filesToRun = DimFileProcessor.GetRunFiles(); DimConsole.WriteLine("Only \"run\" files (count: " + filesToRun.Count + ")"); foreach (var file in filesToRun) { var hash = DimFileProcessor.GetFileHash(file); DimConsole.WriteInfoLine("'" + file.FileName + "'", file.Parent.RunKind.ToString(), hash); } // DimConsole.WriteLine("Find file by FileName:"); // DimConsole.WriteLine("Please enter a file name:"); // var fileName = Console.ReadLine(); // var testFile = DatabaseCommander.GetRecordByFileName(fileName); // if(testFile != null) // DimConsole.WriteLine("File found!", testFile.FileName, testFile.Executed.ToString("dd-MMM-yyy hh:mm:ss")); // else // DimConsole.WriteLine("File not found :("); DimConsole.WriteLine("Completed test"); return(0); }
public override int Run(string[] remainingArguments) { if (!Program.IsCorrectlySetup(checkConnection: false)) { return(0); } if (this.IsSettingValues) { this.SettingValues(); } else { DimConsole.WriteIntro("Showing config"); foreach (var line in File.ReadAllLines(Local.LocalDimConfig)) { DimConsole.WriteLine(line); } } return(0); }