public QueueFixture() { try { var configuration = new DbMigrationsConfiguration { ContextType = typeof(QueueDataContext), MigrationsAssembly = typeof(QueueDataContext).Assembly, TargetDatabase = new DbConnectionInfo("QueueDataContext"), MigrationsNamespace = typeof(InitialCreate).Namespace, AutomaticMigrationDataLossAllowed = true }; var migrator = new DbMigrator(configuration); //Update / rollback to "MigrationName" migrator.Update("0"); migrator.Update(); _sut = new SqlQueueImpl(new Infrastructure.DatabaseContextFactory()); } catch (Exception ex) { if (Debugger.IsAttached) Debugger.Break(); Console.WriteLine(ex); throw; } }
public void FullUp_FullDown() { var configuration = new Veil.DataAccess.Migrations.Configuration(); var migrator = new DbMigrator(configuration); List<string> migrations = new List<string> { "0" }; migrations.AddRange(migrator.GetLocalMigrations()); migrator.Update(migrations.Last()); migrator.Update(migrations.First()); }
static void Main(string[] args) { var configuration = new DbMigrationsConfiguration { AutomaticMigrationsEnabled = true, AutomaticMigrationDataLossAllowed = true, ContextType = typeof(ToDoAppContext), MigrationsAssembly = Assembly.GetExecutingAssembly(), MigrationsNamespace = "ToDoApp.Entity.Context", TargetDatabase = new DbConnectionInfo("ToDoAppContext") }; try { var migrator = new System.Data.Entity.Migrations.DbMigrator(configuration); migrator.Update(); Console.WriteLine("All databases have been migrated."); } catch (Exception ex) { Console.WriteLine("An error occured during migration of host database."); Console.WriteLine("Exception Message: " + ex.Message); } Console.ReadKey(); }
public static void RegisterAuth() { var migrator = new DbMigrator(new Configuration()); migrator.Update(); if (!WebSecurity.Initialized) { WebSecurity.InitializeDatabaseConnection("AnunciosDbContext", "UserProfile", "UserId", "UserName", autoCreateTables: true); } // To let users of this site log in using their accounts from other sites such as Microsoft, Facebook, and Twitter, // you must update this site. For more information visit http://go.microsoft.com/fwlink/?LinkID=252166 //OAuthWebSecurity.RegisterMicrosoftClient( // clientId: "", // clientSecret: ""); //OAuthWebSecurity.RegisterTwitterClient( // consumerKey: "", // consumerSecret: ""); //OAuthWebSecurity.RegisterFacebookClient( // appId: "", // appSecret: ""); //OAuthWebSecurity.RegisterGoogleClient(); }
private static void UpdateDb() { var settings = new Configuration(); var migrator = new DbMigrator(settings); migrator.Update(); }
private static void RunUpdate(string connectionName) { Console.WriteLine("RUNNING MIGRATIONS FOR CONNECTION NAME: " + connectionName); var configuration = new Configuration(); configuration.TargetDatabase = new DbConnectionInfo(connectionName); try { Console.WriteLine("TRYING..."); var migrator = new DbMigrator(configuration); migrator.Update(); Console.WriteLine("SUCCESS!"); ExitCode = 1; } catch (Exception ex) { Console.WriteLine("EXCEPTION:"); Console.WriteLine(ex.Message); Console.WriteLine("FAILURE!"); } Console.WriteLine("DONE!"); Environment.Exit(ExitCode); }
public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); //For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686 config.EnableSystemDiagnosticsTracing(); new MobileAppConfiguration().UseDefaultConfiguration().ApplyTo(config); // Use Entity Framework Code First to create database tables based on your DbContext // Database.SetInitializer(new mouselightInitializer()); var migrator = new DbMigrator(new Janelia.Mouse.Mobile.Server.Migrations.Configuration()); migrator.Update(); // To prevent Entity Framework from modifying your database schema, use a null database initializer // Database.SetInitializer<MouseLightContext>(null); MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings(); if (string.IsNullOrEmpty(settings.HostName)) { // This middleware is intended to be used locally for debugging. By default, HostName will // only have a value when running in an App Service application. app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions { SigningKey = ConfigurationManager.AppSettings["SigningKey"], ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] }, ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] }, TokenHandler = config.GetAppServiceTokenHandler() }); } app.UseWebApi(config); }
public static void Run() { ConsoleLogger.Information("Installing Database"); using (var context = new DataContext()) { try { ConsoleLogger.Information(" Dropping database..."); context.Database.Delete(); } catch (Exception ex) { ConsoleLogger.Error(" Error: Could not drop database! " + ex); } try { ConsoleLogger.Information(" Creating database..."); var migrator = new DbMigrator(new ClaimDbConfiguration()); migrator.Update(); } catch (Exception ex) { ConsoleLogger.Error(" Error: Could not create database! " + ex); } } ConsoleLogger.Information("Database Installed!"); }
protected void Application_Start() { var connString = ConfigurationManager.ConnectionStrings["BlogContext"]; string commandText = @" CREATE TABLE [__MigrationHistory] ( [Id] [uniqueidentifier] DEFAULT newid(), [Migration] [nvarchar](255) NOT NULL, [CreatedOn] [datetime] NOT NULL, [Hash] [binary](32) NOT NULL, [Model] [varbinary](max) NOT NULL, PRIMARY KEY ([Id]) ); "; using (var connection = new SqlConnection(connString.ConnectionString)) { using (var command = new SqlCommand(commandText, connection)) { connection.Open(); try { command.ExecuteNonQuery(); } catch { } } } var dbMigrator = new DbMigrator(new MvcApplicationCodeFirst.Migrations.Settings()); dbMigrator.Update(); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); }
/// <summary> /// Creates a new database file at the specified path with the specified file name. /// The ".sdf" extension will be added to the file. Do not pass it in the file name. /// </summary> /// <param name="databaseFilePath">The path to the file, excluding the file's name</param> /// <param name="databaseFileName">The name of the new database file. Exclude the .sdf extension - it will be added automatically.</param> /// <param name="changeApplicationConnection">If true, the application's connection will be changed to this new database.</param> /// <returns>Returns the full path to the database file.</returns> public string CreateNewDatabase(string databaseFilePath, string databaseFileName, bool changeApplicationConnection) { string fullPath = databaseFilePath + "\\" + databaseFileName + ".sdf"; string connectionString; // Update connection settings and the active module directory path if (changeApplicationConnection) { ChangeDatabaseConnection(fullPath); WinterConnectionInformation.ActiveModuleDirectoryPath = fullPath; connectionString = WinterConnectionInformation.ActiveConnectionString; } // Otherwise we're simply creating a new database file. Build a connection string. else { connectionString = BuildConnectionString(fullPath); } // Initialize the database - will create the database file at the specified location. // Also creates tables based on the code-first model. using (ModuleDataContext context = new ModuleDataContext(connectionString)) { DbMigrator migrator = new DbMigrator(new ModuleDataContextMigrationConfiguration()); migrator.Update(); } return fullPath; }
/// <summary> /// Initializes the database. /// </summary> /// <param name="context">The context.</param> /// <inheritdoc /> public virtual void InitializeDatabase(TContext context) { if (_config == null) { _config = new TMigrationsConfiguration { TargetDatabase = new DbConnectionInfo(context.Database.Connection.ConnectionString, "System.Data.SqlClient") }; } var migrator = new System.Data.Entity.Migrations.DbMigrator(_config); var pending = migrator.GetPendingMigrations().Count(); var local = migrator.GetLocalMigrations().Count(); var exists = context.Database.Exists(); if (!exists || pending > 0) { try { migrator.Update(); } catch (SqlException ex) { throw new ApplicationException($"Migrations failed with error \"{ex.ExpandExceptionMessage()}\"", ex); } InitializeDbSettings(context); if (pending == local) { Seed(context); } } }
private static void RunMigrations() { var efMigrationSettings = new HomeManager.Domain.Migrations.Configuration(); var efMigrator = new DbMigrator(efMigrationSettings); efMigrator.Update(); }
public static void Main(string[] args) { Console.WriteLine(@"Migrating database..."); var migrator = new DbMigrator(new Configuration()); Console.WriteLine(@"Connection: " + GetConnectionString(migrator)); var migrations = migrator.GetPendingMigrations().ToList(); if (!migrations.Any()) { Console.WriteLine(@"No pending migrations."); } else { foreach (var migration in migrations) { Console.WriteLine(migration); migrator.Update(migration); } } if (args.Contains("--seed")) { Console.WriteLine(@"Seeding the database..."); var context = new EntityContext(); DatabaseSeeder.Seed(context); context.SaveChanges(); } else { Console.WriteLine(@"No seeding required."); } Console.WriteLine(@"Migration done."); }
private static void RunMigrations() { var efMigrationSettings = new PingYourPackage.Domain.Migrations.Configuration(); var efMigrator = new DbMigrator(efMigrationSettings); efMigrator.Update(); }
private static void RunMigrations() { var efMigrationSettings = new ShippingExpress.Domain.Migrations.Configuration(); var efMigrator = new DbMigrator(efMigrationSettings); efMigrator.Update(); }
public void InitializeDatabase() { var configuration = new Configuration(); var migrator = new DbMigrator(configuration); migrator.Update(); }
protected void Application_Start() { var migrator = new DbMigrator(new Configuration()); migrator.Configuration.AutomaticMigrationDataLossAllowed = true; migrator.Update(); //Database.SetInitializer<ApplicationDbContext>(new AppDbInitializer()); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); BundleMobileConfig.RegisterBundles(BundleTable.Bundles); ModelBinders.Binders.Add(typeof(Cart), new CartModelBinder()); ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory()); DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iphone") { ContextCondition = Context => Context.Request.Browser["HardwareModel"] == "iPhone" }); DisplayModeProvider.Instance.Modes.Insert(1, new DefaultDisplayMode("android") { ContextCondition = Context => Context.Request.Browser["PlatformName"] == "Android" }); DisplayModeProvider.Instance.Modes.Insert(2, new DefaultDisplayMode("mobile") { ContextCondition = Context => Context.Request.Browser["IsMobile"] == "True" }); }
public string Run(string from, string to) { var configuration = new Configuration(); //Can set the Target Database to be in another Server or Environment //configuration.TargetDatabase = // new DbConnectionInfo("Server=.;Database=Investment;Trusted_Connection=True;", // "System.Data.SqlClient"); //var context = (InvestmentContext)Activator.CreateInstance(configuration.ContextType); var runUpdate = false; var migrator = new DbMigrator(configuration); var scriptor = new MigratorScriptingDecorator(migrator); var sql = scriptor.ScriptUpdate("", ""); //var sql = scriptor.ScriptUpdate("Name-Of-Source-Migration", "Name-Of-Target-Migration"); //configuration.RunSeedProcess(context); if (runUpdate) { //Can run the update from here migrator.Update(); //Could add a "TargetMigration" } return sql; }
public void TestInitialize() { _accountController = new AccountController(ContextEnum.BeatBuddyTest); var migratorConfig = new Migrations.Configuration(); migratorConfig.TargetDatabase = new DbConnectionInfo(ContextEnum.BeatBuddyTest.ToString()); var dbMigrator = new DbMigrator(migratorConfig); dbMigrator.Update(); }
private void InitialiseDataBase() { var migrator = new DbMigrator(new DataLayer.Migrations.Configuration()); migrator.Update(); if (!WebSecurity.Initialized) WebSecurity.InitializeDatabaseConnection("NavasthalaContext", "UserProfile", "UserId", "UserName", autoCreateTables: true); }
public static int Main(string[] args) { DbMigrator databaseMigrator = new DbMigrator(DatabaseStartup.GetConfiguration()); // interpret arguments if (args.Length == 0) { System.Console.WriteLine("Please enter some parameters to control migrations."); System.Console.WriteLine("Usage: -<parameter> [<parameter_value>]"); return 1; } try { if (args[0].ToLowerInvariant().Equals("update-database")) { DatabaseStartup.InitConfiguration(); Console.WriteLine("Starting database update..."); databaseMigrator.Update(); Console.WriteLine("Update completed."); } else if (args[0].ToLowerInvariant().Equals("migrate-to")) { if (args.Length == 1) { System.Console.WriteLine("Please enter some parameters to control migrations."); System.Console.WriteLine("Usage: -<parameter> [<parameter_value>]"); return 1; } Console.WriteLine("Starting migration..."); string desiredMigrationName = args[1]; databaseMigrator.Update(desiredMigrationName); Console.WriteLine("Migration completed."); } return 0; } catch (Exception ex) { Console.WriteLine("Exception occured: " + ex.Message + Environment.NewLine + ex.StackTrace); Console.ReadLine(); return 1; } }
public void FixtureSetup() { // Migrate the database to the most current migration var configuration = new Veil.DataAccess.Migrations.Configuration(); var migrator = new DbMigrator(configuration); migrator.Update(); }
protected void Application_Start() { WebApiConfig.Register(); var configuration = new Migrations.Configuration(); var migrator = new DbMigrator(configuration); migrator.Update(); }
public void FixtureTeardown() { // Return the database back to pre-first migration state var configuration = new Veil.DataAccess.Migrations.Configuration(); var migrator = new DbMigrator(configuration); migrator.Update("0"); // 0 is equivalent to undoing all migrations }
private static void DbMigratorPostStart() { var dbMigrator = new DbMigrator(new MigrationsConfiguration()); // After upgrading to EF 4.3 and MiniProfile 1.9, there is a bug that causes several // 'Invalid object name 'dbo.__MigrationHistory' to be thrown when the database is first created; // it seems these can safely be ignored, and the database will still be created. dbMigrator.Update(); }
public void TestInitialize() { userManager = new UserManager(new UserRepository(new EFDbContext(ContextEnum.BeatBuddyTest)) ); var migratorConfig = new UI.Web.MVC.Migrations.Configuration(); migratorConfig.TargetDatabase = new DbConnectionInfo(ContextEnum.BeatBuddyTest.ToString()); var dbMigrator = new DbMigrator(migratorConfig); dbMigrator.Update(); }
private static void UpdateDatabase() { var dbMigrator = new DbMigrator(new Settings()); dbMigrator.Update(); // The Seed method of Settings is never called, so // we call it here again as a workaround. Settings.SeedDatabase(new EntitiesContext()); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); var migrator = new DbMigrator(new Configuration()); migrator.Update(); }
/// <summary> /// Uninstall plugin /// </summary> public override void Uninstall() { _services.Localization.DeleteLocaleStringResources(PluginDescriptor.ResourceRootKey); var migrator = new DbMigrator(new Configuration()); migrator.Update(DbMigrator.InitialDatabase); base.Uninstall(); }
public void ReSeed() { var configuration = new Research.UI.Web.Migrations.Configuration(); configuration.ContextType = typeof(ResearchDbContext); var migrator = new DbMigrator(configuration); // This will run the migration update script and will run Seed() method. migrator.Update(); }
public static void RunMigration() { var migrationConfig = new Configuration(); var migrator = new DbMigrator(migrationConfig); // JBOY: migrator.Update will look at the startup projects cofig file for the connection string // but you can provide a connection string to migrationConfig using "migrationConfig.TargetDatabase = connString" migrator.Update(); }
public static void EnableCodeFirstMigrations() { if (bool.Parse(ConfigurationManager.AppSettings["MigrateDatabaseToLatestVersion"])) { var configuration = new Migrations.Configuration(); var migrator = new DbMigrator(configuration); migrator.Update(); } }
public void Can_seed_database_when_database_up_to_date() { ResetDatabase(); var migrationsConfiguration = new SeedingMigrationsConfiguration(); ConfigureMigrationsConfiguration(migrationsConfiguration); var migrator = new DbMigrator(migrationsConfiguration); migrator.Update(); using (var context = CreateContext <ShopContext_v1>()) { Assert.Equal(1, context.Products.Count()); } }
[Fact] // CodePlex 529, 1192 public void Creating_database_using_throws_if_Migrations_configuration_is_found_but_not_ready_to_update() { using (var context = new NotReadyContext()) { context.Database.Delete(); Assert.Throws <InvalidOperationException>(() => context.Database.Initialize(force: true)) .ValidateMessage("DatabaseInitializationStrategy_MigrationsEnabled", "NotReadyContext"); Assert.False(context.Database.Exists()); } var migrator = new DbMigrator(new NotreadyMigrationsConfig()); Assert.Throws <AutomaticMigrationsDisabledException>( () => migrator.Update()).ValidateMessage("AutomaticDisabledException"); }
[Fact] // CodePlex #2579 public void Repro() { var connection1 = SimpleConnectionString("Db2579Aa"); var connection2 = SimpleConnectionString("Db2579Bb"); using (var context = new Context2579I(connection1)) { context.Database.Delete(); context.Database.Create(); context.Entities.Add(new Entity2579()); context.SaveChanges(); } using (var context = new Context2579I(connection2)) { context.Database.Delete(); } var tests = new Action[100]; for (var i = 0; i < 100; i++) { tests[i] = () => { using (var context = new Context2579(connection1)) { Assert.Equal(1, context.Entities.Count()); } }; } tests[25] = () => { using (new Context2579(connection2)) { var migrationConfiguration = new Configuration2579(connection2); var migrator = new DbMigrator(migrationConfiguration); migrator.Update(); } }; Parallel.Invoke(tests); }
/// <summary> /// 更新数据库 /// </summary> public static bool UpdateDBToLast() { bool result = false; try { var m = new System.Data.Entity.Migrations.DbMigrator(new Configuration() { TargetDatabase = new System.Data.Entity.Infrastructure.DbConnectionInfo(ConnectionString.connectionString, "System.Data.SqlClient") }); m.Update(); result = true; } catch (Exception ex) { result = false; throw ex; } return(result); }
public void Application_Start() { //Database.SetInitializer(new MigrateDatabaseToLatestVersion<VeriTabanı, MvcProjem.Models.VeriTabanı.Configuration>("MvcProjemConnectionString")); using (var vt = new VeriTabanı()) { if (vt.Database.Exists()) { DbMigrator migrator = new System.Data.Entity.Migrations.DbMigrator(new Configuration()); migrator.Update(); } else { vt.Database.Create(); } } AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); }