public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <SqlMigrationEntity>() .WithQuery(() => e => new { Entity = e, e.Id, e.VersionNumber, }); sb.Include <CSharpMigrationEntity>() .WithQuery(() => e => new { Entity = e, e.Id, e.UniqueName, e.ExecutionDate, }); sb.Include <LoadMethodLogEntity>() .WithQuery(() => e => new { Entity = e, e.Id, e.Start, e.Duration, e.ClassName, e.MethodName, e.Description, }); ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs; Administrator.AvoidSimpleSynchronize = () => { if (Administrator.ExistsTable <SqlMigrationEntity>()) { var count = Database.Query <SqlMigrationEntity>().Count(); if (count > 0) { Console.Write("The database "); SafeConsole.WriteColor(ConsoleColor.Yellow, Connector.Current.DatabaseName()); Console.Write(" contains "); SafeConsole.WriteColor(ConsoleColor.Yellow, count.ToString()); Console.WriteLine(" Sql Migrations!"); if (SafeConsole.Ask("Do you want to create a new SQL Migration instead?")) { SqlMigrationRunner.SqlMigrations(); return(true); } } } return(false); }; } }
private static void RunMigration(DbConnection dbConnection) { if ((dbConnection != null) && (String.IsNullOrEmpty(dbConnection.ConnectionString) == false)) { using (MigrationRunner migrationRunner = new SqlMigrationRunner(dbConnection)) { migrationRunner.ExecuteMigrations(); } } }
static int Main(string[] args) { try { using (AuthLogic.Disable()) using (CultureInfoUtils.ChangeCulture("en")) using (CultureInfoUtils.ChangeCultureUI("en")) { DynamicLogicStarter.AssertRoslynIsPresent(); Starter.Start(UserConnections.Replace(Settings.Default.ConnectionString)); Console.WriteLine("..:: Welcome to Southwind Loading Application ::.."); Console.WriteLine("Database: {0}", Regex.Match(((SqlConnector)Connector.Current).ConnectionString, @"Initial Catalog\=(?<db>.*)\;").Groups["db"].Value); Console.WriteLine(); if (args.Any()) { switch (args.First().ToLower().Trim('-', '/')) { case "sql": SqlMigrationRunner.SqlMigrations(true); return(0); case "csharp": SouthwindMigrations.CSharpMigrations(true); return(0); case "load": Load(args.Skip(1).ToArray()); return(0); default: { SafeConsole.WriteLineColor(ConsoleColor.Red, "Unkwnown command " + args.First()); Console.WriteLine("Examples:"); Console.WriteLine(" sql: SQL Migrations"); Console.WriteLine(" csharp: C# Migrations"); Console.WriteLine(" load 1-4,7: Load processes 1 to 4 and 7"); return(-1); } } } //if(args.Any()) while (true) { Action action = new ConsoleSwitch <string, Action> { { "N", NewDatabase }, { "G", CodeGenerator.GenerateCodeConsole }, { "SQL", SqlMigrationRunner.SqlMigrations }, { "CS", () => SouthwindMigrations.CSharpMigrations(false), "C# Migrations" }, { "S", Synchronize }, { "L", () => Load(null), "Load" }, }.Choose(); if (action == null) { return(0); } action(); } } } catch (Exception e) { SafeConsole.WriteColor(ConsoleColor.DarkRed, e.GetType().Name + ": "); SafeConsole.WriteLineColor(ConsoleColor.Red, e.Message); SafeConsole.WriteLineColor(ConsoleColor.DarkRed, e.StackTrace.Indent(4)); return(-1); } }
static int Main(string[] args) { try { using (AuthLogic.Disable()) using (CultureInfoUtils.ChangeCulture("en")) using (CultureInfoUtils.ChangeCultureUI("en")) { var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); Configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{env}.json", true) .AddUserSecrets <Program>(optional: true) .Build(); Starter.Start( Configuration.GetConnectionString("ConnectionString"), Configuration.GetValue <bool>("IsPostgres"), Configuration.GetConnectionString("AzureStorageConnectionString"), Configuration.GetValue <string>("BroadcastSecret"), Configuration.GetValue <string>("BroadcastUrls")); Console.WriteLine("..:: Welcome to Southwind Loading Application ::.."); SafeConsole.WriteLineColor(env == "live" ? ConsoleColor.Red : env == "test" ? ConsoleColor.Yellow : ConsoleColor.Gray, Connector.Current.ToString()); Console.WriteLine(); if (args.Any()) { switch (args.First().ToLower().Trim('-', '/')) { case "sql": SqlMigrationRunner.SqlMigrations(true); return(0); case "csharp": SouthwindMigrations.CSharpMigrations(true); return(0); case "load": Load(args.Skip(1).ToArray()); return(0); default: { SafeConsole.WriteLineColor(ConsoleColor.Red, "Unkwnown command " + args.First()); Console.WriteLine("Examples:"); Console.WriteLine(" sql: SQL Migrations"); Console.WriteLine(" csharp: C# Migrations"); Console.WriteLine(" load 1-4,7: Load processes 1 to 4 and 7"); return(-1); } } } //if(args.Any()) while (true) { Action?action = new ConsoleSwitch <string, Action> { { "N", Administrator.NewDatabase }, { "G", CodeGenerator.GenerateCodeConsole }, { "SQL", SqlMigrationRunner.SqlMigrations }, { "CS", () => SouthwindMigrations.CSharpMigrations(false), "C# Migrations" }, { "S", Administrator.Synchronize }, { "L", () => Load(null), "Load" }, }.Choose(); if (action == null) { return(0); } action(); } } } catch (Exception e) { SafeConsole.WriteColor(ConsoleColor.DarkRed, e.GetType().Name + ": "); SafeConsole.WriteLineColor(ConsoleColor.Red, e.Message); SafeConsole.WriteLineColor(ConsoleColor.DarkRed, e.StackTrace !.Indent(4)); return(-1); } }
static int Main(string[] args) { try { using (AuthLogic.Disable()) using (CultureInfoUtils.ChangeCulture("en")) using (CultureInfoUtils.ChangeCultureUI("en")) { ConfigRoot = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", true) .AddUserSecrets <Program>().Build(); var connectionString = ConfigRoot.GetConnectionString("ConnectionString"); Starter.Start(connectionString); Console.WriteLine("..:: Welcome to Southwind Loading Application ::.."); Console.WriteLine("Database: {0}", Regex.Match(((SqlConnector)Connector.Current).ConnectionString, @"Initial Catalog\=(?<db>.*)\;").Groups["db"].Value); Console.WriteLine(); if (args.Any()) { switch (args.First().ToLower().Trim('-', '/')) { case "sql": SqlMigrationRunner.SqlMigrations(true); return(0); case "csharp": SouthwindMigrations.CSharpMigrations(true); return(0); case "load": Load(args.Skip(1).ToArray()); return(0); default: { SafeConsole.WriteLineColor(ConsoleColor.Red, "Unkwnown command " + args.First()); Console.WriteLine("Examples:"); Console.WriteLine(" sql: SQL Migrations"); Console.WriteLine(" csharp: C# Migrations"); Console.WriteLine(" load 1-4,7: Load processes 1 to 4 and 7"); return(-1); } } } //if(args.Any()) while (true) { Action action = new ConsoleSwitch <string, Action> { { "N", NewDatabase }, { "G", CodeGenerator.GenerateCodeConsole }, { "SQL", SqlMigrationRunner.SqlMigrations }, { "CS", () => SouthwindMigrations.CSharpMigrations(false), "C# Migrations" }, { "S", Synchronize }, { "L", () => Load(null), "Load" }, }.Choose(); if (action == null) { return(0); } action(); } } } catch (Exception e) { SafeConsole.WriteColor(ConsoleColor.DarkRed, e.GetType().Name + ": "); SafeConsole.WriteLineColor(ConsoleColor.Red, e.Message); SafeConsole.WriteLineColor(ConsoleColor.DarkRed, e.StackTrace.Indent(4)); return(-1); } }