public void ParseMigrationParameters() { MigrationParametersParser parametersParser = new MigrationParametersParser(); MigrationParameters parameters = parametersParser.ParseMigrationParameters(new string[] { "downgrade", "/c:\"data source=GOGOLEV_A\\SQLEXPRESS;initial catalog=test;integrated security=SSPI;\"", "/p:sqlserver", "/o:downgrade.sql" }); Assert.AreEqual(MigrationCommand.Downgrade, parameters.Command); Assert.IsNull(parameters.VersionOrStep); Assert.AreEqual("data source=GOGOLEV_A\\SQLEXPRESS;initial catalog=test;integrated security=SSPI;", parameters.ConnectionString); Assert.AreEqual("sqlserver", parameters.PlatformAlias); Assert.AreEqual("downgrade.sql", parameters.OutputFileName); parameters = parametersParser.ParseMigrationParameters(new string[] { "migrate", "20090226100609", "/connection:\"data source=GOGOLEV_A\\SQLEXPRESS;initial catalog=test;integrated security=SSPI;\"", "/PLATFORM:sqlserver", "/e:dev" }); Assert.AreEqual(MigrationCommand.Migrate, parameters.Command); Assert.AreEqual(20090226100609, parameters.VersionOrStep.Value); Assert.AreEqual("data source=GOGOLEV_A\\SQLEXPRESS;initial catalog=test;integrated security=SSPI;", parameters.ConnectionString); Assert.AreEqual("sqlserver", parameters.PlatformAlias); Assert.AreEqual("dev", parameters.Environment); Assert.IsNull(parameters.OutputFileName); }
public void ParseMigrationParameters3() { MigrationParametersParser parametersParser = new MigrationParametersParser(); MigrationParameters parameters = parametersParser.ParseMigrationParameters(new string[] { "do" }); Assert.AreEqual(MigrationCommand.Downgrade, parameters.Command); }
public void ParseUnknownCommand() { MigrationParametersParser parametersParser = new MigrationParametersParser(); MigrationParameters parameters = parametersParser.ParseMigrationParameters(new string[] { "foo" }); }
public void ParseMigrationParameters4() { MigrationParametersParser parametersParser = new MigrationParametersParser(); MigrationParameters parameters = parametersParser.ParseMigrationParameters(new string[] { "red" }); Assert.AreEqual(MigrationCommand.Redo, parameters.Command); }
public void ParseAmbiguousCommand() { MigrationParametersParser parametersParser = new MigrationParametersParser(); MigrationParameters parameters = parametersParser.ParseMigrationParameters(new string[] { "r" }); }
static int Main(string[] args) { System.Console.WriteLine(Resources.CopyrightInformation, Assembly.GetExecutingAssembly().GetName().Version.ToString(4), ApplicationInfo.Milestone); if(args.Length == 0 || (args.Length == 1 && args[0] == "/?")) { System.Console.WriteLine(); System.Console.WriteLine(Resources.UsageInformation); return 1; } // if serviceProvider = new ServiceProvider(); serviceProvider.RegisterService(BuildDbPlatformRegistry()); serviceProvider.RegisterService<IMigrationService>(delegate(IServiceProvider sp) { MigrationService migrationService = new MigrationService( sp.GetService<IDbPlatform>(), sp.GetService<IMigrationVersionInfoManager>(), sp.GetService<IMigrationScriptExecutive>(), sp.GetService<INativeSqlResourceProvider>()); migrationService.Migrating += MigrationServiceMigrating; migrationService.Migrated += MigrationServiceMigrated; return migrationService; }); serviceProvider.RegisterService<IMigrationVersionInfoManager>(delegate(IServiceProvider sp) { return new DbMigrationVersionInfoManager( sp.GetService<IDbPlatform>(), sp.GetService<IDbCommandExecutionStrategy>(), "SchemaInfo"); }); serviceProvider.RegisterService<IMigrationScriptExecutive>(delegate(IServiceProvider sp) { return new DbMigrationScriptExecutive( sp.GetService<IDbCommandExecutionStrategy>()); }); serviceProvider.RegisterService(new DeploymentService()); serviceProvider.RegisterService(new ReverseEngineeringService()); serviceProvider.RegisterService(new UtcDateTimeTimestampProvider()); serviceProvider.RegisterService(new FileSystemNativeSqlResourceProvider(Directory.GetCurrentDirectory())); // // Prepare Migration Command Registry... MigrationCommandRegistry migrationCommandRegistry = new MigrationCommandRegistry(); migrationCommandRegistry.RegisterAssembly(typeof(Program).Assembly); try { // // Parse parameters MigrationParametersParser parametersParser = new MigrationParametersParser(); parameters = parametersParser.ParseMigrationParameters(args); // // If we have an output file name specified, use special IDbCommandExecutionStrategy if(!string.IsNullOrEmpty(parameters.OutputFileName)) serviceProvider.RegisterService(new FileDbCommandExecutionStrategy(parameters.OutputFileName)); else serviceProvider.RegisterService(new DbCommandExecutionStrategy()); // // ...and execute whatever command we need IMigrationCommand migrationCommand = migrationCommandRegistry.ResolveCommand(parameters.Command); migrationCommand.ServiceProvider = serviceProvider; migrationCommand.Execute(parameters); } // try catch(MdlParserException e) { using(new ConsoleStylingScope(ConsoleColor.Red)) System.Console.WriteLine(System.Environment.NewLine + "Compilation Exception: {0}", e.Message); return 2; } // catch catch(MdlCompilerException e) { using(new ConsoleStylingScope(ConsoleColor.Red)) System.Console.WriteLine(System.Environment.NewLine + "Compilation Exception: {0} ({1})", e.Message, e.Location); return 3; } // catch catch(MigrationException e) { using(new ConsoleStylingScope(ConsoleColor.Red)) System.Console.WriteLine(System.Environment.NewLine + "Migration Exception: {0} ({1})", e.Message, e.SqlStatement); return 4; } // catch catch(DbPlatformException e) { IDbPlatform dbPlatform = serviceProvider.GetService<DbPlatformRegistry>().ResolvePlatform(parameters.PlatformAlias); using(new ConsoleStylingScope(ConsoleColor.Red)) System.Console.WriteLine(System.Environment.NewLine + "{0} Exception: {1}", serviceProvider.GetService<DbPlatformRegistry>().GetPlatformName(dbPlatform), e.Message + e.StackTrace.ToString()); return 5; } // catch catch(DbException e) { IDbPlatform dbPlatform = serviceProvider.GetService<DbPlatformRegistry>().ResolvePlatform(parameters.PlatformAlias); using (new ConsoleStylingScope(ConsoleColor.Red)) System.Console.WriteLine(System.Environment.NewLine + "{0} Exception: {1}", serviceProvider.GetService<DbPlatformRegistry>().GetPlatformName(dbPlatform), e.Message + e.StackTrace.ToString()); return 6; } // catch catch(Exception e) { using(new ConsoleStylingScope(ConsoleColor.Red)) System.Console.WriteLine(System.Environment.NewLine + "Unknown Exception: {0}", e.ToString()); return 100; } // catch return 0; }