public void VerifyThatMigrationVersionsWork() { MigrationEngine.Reset(); MigrationEngine.Migrate(excludes: new List <string>() { "BadMigration", "BadSeed", "BadSave", "BadReverse" }); Assert.IsTrue(DatabaseSession.Instance.Connector.CheckTableExists(new MigrationRecord())); Assert.AreEqual(4, MigrationRecord.All().Count); MigrationEngine.ResetTo(new Version(1, 0, 0)); Assert.AreEqual(3, MigrationRecord.All().Count); MigrationEngine.Reset(); MigrationEngine.Migrate(excludes: new List <string>() { "BadMigration", "BadSeed", "BadSave" }); Assert.IsTrue(DatabaseSession.Instance.Connector.CheckTableExists(new MigrationRecord())); Assert.AreEqual(5, MigrationRecord.All().Count); var migrationDeleteBase = new BadMigration(); Assert.Throws <InvalidDataException>(() => migrationDeleteBase.Delete()); Assert.Throws <Exception>(() => MigrationEngine.ResetTo(new Version(0, 0, 0))); MigrationEngine.Reset(hard: true); Assert.IsFalse(DatabaseSession.Instance.Connector.CheckTableExists(new MigrationRecord())); }
/// <summary> /// reinitialize the bootstrapper - can be used for adding pre-/post- hooks and /// any other initialization tasks that aren't specifically container setup /// related /// </summary> /// <param name="container">Container instance for resolving types if required.</param> /// <param name="pipelines">The pipelines used in this application.</param> protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { Logger.Info("Bootstrapping Application"); Logger.Info("Setting up Pipelines"); base.ApplicationStartup(container, pipelines); Logger.Info("Setting up Serialization Resolver"); // register model resolvers SeedResolverRegistry.Register(); // register serializer container.Register <ISerializer, JsonApiSerializer>().AsSingleton(); var serializer = container.Resolve <ISerializer>() as JsonApiSerializer; if (serializer != null) { serializer.DeserializationMap = EntityResolverMap.DeserializationMap; } try { Logger.Info("Initializing database connection..."); DatabaseSession.Instance.CreateConnector("localhost", 5432, "redshiftseed", "redshiftseed", "redshift", ConnectorType.Postgresql); Logger.Info("Database connected..."); } catch (Exception ex) { Logger.Info("Failed to establish database connected..."); throw new HttpRequestException(string.Format("The connection to database could not be made: {0}", ex.Message)); } #if DEBUG Logger.Info("DEBUG Detected. Reseting database."); // dev mode only! wipe the db to remigrate and reseed, should always delete this once the first few migrations are finalized. MigrationEngine.DropAllTables("public"); Logger.Info("Reseting database complete..."); #endif Logger.Info("Initializing migration engine..."); MigrationEngine.Migrate(); Logger.Info("Migrations done..."); Logger.Info("Application Finished Bootstrapping"); }
/// <summary> /// Sets up the database connection and migration engine /// </summary> private void SetupDatabaseConnection() { // read all settings from the db var settings = AppSettingsManager.ReadAllSettings(); try { // Create the connection. DatabaseSession.Instance.CreateConnector(settings["dbhost"], settings["dbport"], settings["dbname"], settings["dbuser"], settings["dbpassword"]); } catch (Exception ex) { throw new HttpRequestException(string.Format("The connection to database could not be made: {0}", ex.Message)); } #if DEBUG // when debugging reset the full database MigrationEngine.Reset(); #endif // perform the migration MigrationEngine.Migrate(); }
public void VerifyThatMigrationEngineWorks() { // Reset all migrations MigrationEngine.Reset(); Assert.IsFalse(DatabaseSession.Instance.Connector.CheckTableExists(new MigrationRecord())); Assert.Throws <Exception>(() => MigrationEngine.Migrate()); Assert.IsTrue(DatabaseSession.Instance.Connector.CheckTableExists(new MigrationRecord())); Assert.Throws <Exception>(() => MigrationEngine.Migrate(new List <string>() { "BadMigration" })); Assert.Throws <Exception>(() => MigrationEngine.Migrate(excludes: new List <string>() { "BadMigration", "BadSeed" })); MigrationEngine.Migrate(excludes: new List <string>() { "BadMigration", "BadSeed", "BadSave", "CreateMigrationTable" }); Assert.Throws <Exception>(() => MigrationEngine.Reset("BadReverse")); MigrationEngine.Reset(hard: true); Assert.IsFalse(DatabaseSession.Instance.Connector.CheckTableExists(new MigrationRecord())); }