static void Main(string[] args) { const string usage = @"Fluent Migrator Schema Dumper Usage: SchemaDumper.exe --connection CONNECTION [--file FILE] [--verbose] [--show] [--open] SchemaDumper.exe --version SchemaDumper.exe --help Options: --connection CONNECTION -c CONNECTION The connection string. Required. --file FILE -f FILE File to output. Optional. [default: schemaDump.cs] --show -s Show output. Optional. --open -o Open file. Optional. --verbose Verbose. Optional. --help -h Show this screen. --version -v Show version. "; var arguments = new Docopt().Apply(usage, args, version: Assembly.GetExecutingAssembly().GetName().Version, exit: true); var file = arguments["--file"].ToString(); var verbose = arguments["--verbose"].IsTrue; var open = arguments["--open"].IsTrue; var show = arguments["--show"].IsTrue; if (!Path.IsPathRooted(file)) file = Path.Combine(Environment.CurrentDirectory, file); var connectionString = arguments["--connection"].ToString(); if (verbose) WriteLine($"Saving to {file}."); try { var builder = new SqlConnectionStringBuilder(connectionString); } catch (ArgumentException) { WriteLine("Connection string is in incorrect format."); return; } using (var connection = new SqlConnection(connectionString)) { try { connection.Open(); } catch (SqlException ex) { WriteLine($"Connection couldn't be established:\n{ex.Message}"); return; } var consoleAnnouncer = new ConsoleAnnouncer(); var dumper = new SqlServerSchemaDumper(new SqlServerProcessor(connection, new SqlServer2000Generator(), consoleAnnouncer, new ProcessorOptions(), new SqlServerDbFactory()), consoleAnnouncer); var tables = dumper.ReadDbSchema(); var writer = new RCDumpWriter(); writer.WriteToFile(tables, file); } if (show) WriteLine(File.ReadAllText(file)); if (open) try { Process.Start(file); } catch { } if (verbose) WriteLine("Done."); }
public override bool Execute() { if (string.IsNullOrEmpty(databaseType)) { Log.LogError("You must specify a database type. i.e. mysql or sqlserver"); return false; } if (Targets == null || Targets.Length == 0) { Log.LogError("You must specify a migration assemblies "); return false; } IAnnouncer announcer = new ConsoleAnnouncer { ShowElapsedTime = Verbose, ShowSql = Verbose }; StreamWriter outputWriter = null; if (Output) { if (string.IsNullOrEmpty(OutputFilename)) OutputFilename = Path.GetFileName(Target) + ".sql"; outputWriter = new StreamWriter(OutputFilename); var fileAnnouncer = new TextWriterAnnouncer(outputWriter) { ShowElapsedTime = false, ShowSql = true }; announcer = new CompositeAnnouncer(announcer, fileAnnouncer); } Log.LogMessage(MessageImportance.Low, "Creating Context"); var runnerContext = new RunnerContext(announcer) { ApplicationContext = ApplicationContext, Database = databaseType, Connection = Connection, ConnectionStringConfigPath = ConnectionStringConfigPath, Targets = Targets, PreviewOnly = PreviewOnly, Namespace = Namespace, NestedNamespaces = Nested, Task = Task, Version = Version, Steps = Steps, WorkingDirectory = WorkingDirectory, Profile = Profile, Tags = Tags.ToTags(), Timeout = Timeout, TransactionPerSession = TransactionPerSession }; Log.LogMessage(MessageImportance.Low, "Executing Migration Runner"); try { new TaskExecutor(runnerContext).Execute(); } catch (ProcessorFactoryNotFoundException ex) { Log.LogError("While executing migrations the following error was encountered: {0}", ex.Message); return false; } catch (Exception ex) { Log.LogError("While executing migrations the following error was encountered: {0}, {1}", ex.Message, ex.StackTrace); return false; } finally { if (outputWriter != null) { outputWriter.Dispose(); } } return true; }
protected override void ExecuteTask() { IAnnouncer announcer = new ConsoleAnnouncer { ShowElapsedTime = Verbose, ShowSql = Verbose }; StreamWriter outputWriter = null; if (Output) { if (string.IsNullOrEmpty(OutputFilename)) OutputFilename = Path.GetFileName(Target) + ".sql"; outputWriter = new StreamWriter(OutputFilename); var fileAnnouncer = new TextWriterAnnouncer(outputWriter) { ShowElapsedTime = false, ShowSql = true }; announcer = new CompositeAnnouncer(announcer, fileAnnouncer); } var runnerContext = new RunnerContext(announcer) { ApplicationContext = ApplicationContext, Database = Database, Connection = Connection, Target = Target, PreviewOnly = Preview, Namespace = Namespace, Task = Task, Version = Version, Steps = Steps, WorkingDirectory = WorkingDirectory, Profile = Profile, Tags = Tags.ToTags(), Timeout = Timeout }; try { new TaskExecutor(runnerContext).Execute(); } catch (ProcessorFactoryNotFoundException ex) { announcer.Error("While executing migrations the following error was encountered: {0}", ex.Message); } catch (Exception e) { announcer.Error("While executing migrations the following error was encountered: {0}, {1}", e.Message, e.StackTrace); } finally { if (outputWriter != null) outputWriter.Dispose(); } }
protected override void ExecuteTask() { var announcer = new ConsoleAnnouncer { ShowElapsedTime = Verbose, ShowSql = Verbose }; var runnerContext = new RunnerContext(announcer) { Database = Database, Connection = Connection, Target = Target, PreviewOnly = false, Namespace = Namespace, Task = Task, Version = Version, Steps = Steps, WorkingDirectory = WorkingDirectory, Profile = Profile, Timeout = Timeout }; try { new TaskExecutor(runnerContext).Execute(); } catch (ProcessorFactoryNotFoundException ex) { announcer.Error("While executing migrations the following error was encountered: {0}", ex.Message); } catch (Exception e) { announcer.Error("While executing migrations the following error was encountered: {0}, {1}", e.Message, e.StackTrace); } }
public MigratorContext() { // Default values Announcer = new ConsoleAnnouncer(); Timeout = 30; }
protected virtual IAnnouncer GetAnnouncer() { var announcer = new ConsoleAnnouncer() { ShowElapsedTime = true, ShowSql = true }; return announcer; }