public override void FixtureSetup() { base.FixtureSetup(); var serviceContext = (ServiceContext)MerchelloContext.Current.Services; _databaseSchemaCreation = new DatabaseSchemaCreation(serviceContext.DatabaseUnitOfWorkProvider.GetUnitOfWork().Database); }
public void Init() { var syntax = (DbSyntax)Enum.Parse(typeof(DbSyntax), ConfigurationManager.AppSettings["syntax"]); var worker = new DbPreTestDataWorker {SqlSyntax = syntax }; _database = worker.Database; var deletions = new DatabaseSchemaCreation(_database); deletions.UninstallDatabaseSchema(); }
public void Init() { var syntax = (DbSyntax)Enum.Parse(typeof(DbSyntax), ConfigurationManager.AppSettings["syntax"]); _worker = new DbPreTestDataWorker {SqlSyntax = syntax }; var schemaHelper = new DatabaseSchemaHelper(_worker.Database, _worker.TestLogger, _worker.SqlSyntaxProvider); var deletions = new DatabaseSchemaCreation(_worker.Database, _worker.TestLogger, schemaHelper, _worker.SqlSyntaxProvider); deletions.UninstallDatabaseSchema(); }
/// <summary> /// Undoes the specified package name. /// </summary> /// <param name="packageName">Name of the package.</param> /// <param name="xmlData">The XML data.</param> /// <returns></returns> public bool Undo(string packageName, System.Xml.XmlNode xmlData) { try { var deletions = new DatabaseSchemaCreation(Umbraco.Core.ApplicationContext.Current.DatabaseContext.Database); deletions.UninstallDatabaseSchema(); return true; } catch (Exception ex) { var message = string.Concat("Error at undo ", this.Alias(), " package action: ", ex); LogHelper.Error(typeof(CreateDatabase), message, ex); } return false; }
/// <summary> /// Executes the specified package name. /// </summary> /// <param name="packageName">Name of the package.</param> /// <param name="xmlData">The XML data.</param> /// <returns></returns> public bool Execute(string packageName, System.Xml.XmlNode xmlData) { try { var creation = new DatabaseSchemaCreation(Umbraco.Core.ApplicationContext.Current.DatabaseContext.Database); creation.InitializeDatabaseSchema(); var creationData = new BaseDataCreation(Umbraco.Core.ApplicationContext.Current.DatabaseContext.Database); bool dataCreationResult = CreateInitialMerchelloData(creationData); return true; } catch (Exception ex) { var message = string.Concat("Error at install ", this.Alias(), " package action: ", ex); LogHelper.Error(typeof(CreateDatabase), message, ex); } return false; }
/// <summary> /// Executes the Migration runner. /// </summary> /// <param name="database"> /// The database. /// </param> /// <returns> /// A value indicating whether or not the migration was successful. /// </returns> private bool UpgradeMerchello(Database database) { var databaseSchemaCreation = new DatabaseSchemaCreation(_database, _logger, new DatabaseSchemaHelper(_database, _logger, _sqlSyntaxProvider), _sqlSyntaxProvider); var schemaResult = databaseSchemaCreation.ValidateSchema(); var dbVersion = schemaResult.DetermineInstalledVersion(); if (dbVersion != MerchelloVersion.Current) { try { _logger.Info<CoreMigrationManager>("Merchello database upgraded required. Initializing Upgrade."); var resolver = new MigrationResolver(_logger, PluginManager.Current.ResolveMerchelloMigrations()); var migrations = resolver.OrderedUpgradeMigrations( MerchelloConfiguration.ConfigurationStatusVersion, MerchelloVersion.Current); bool upgraded; try { foreach (var m in migrations) { m.Up(); } upgraded = true; } catch (Exception ex) { _logger.Error<CoreMigrationManager>("Merchello migration failed", ex); upgraded = false; } //var entryService = ApplicationContext.Current.Services.MigrationEntryService; //var runner = new MigrationRunner( // entryService, // _logger, // new SemVersion(MerchelloConfiguration.ConfigurationStatusVersion), // new SemVersion(MerchelloVersion.Current), // MerchelloConfiguration.MerchelloMigrationName); //var upgraded = runner.Execute(database); if (upgraded) { var migrationKey = this.EnsureMigrationKey(schemaResult); var record = new MigrationRecord() { MigrationKey = migrationKey, CurrentVersion = dbVersion.ToString(), TargetVersion = MerchelloVersion.Current.ToString(), DbProvider = database.GetDatabaseProvider().ToString(), InstallDate = DateTime.Now, IsUpgrade = true }; this.OnUpgraded(record); _logger.Info<CoreMigrationManager>("Merchello Schema Migration completed successfully"); } _logger.Debug<CoreMigrationManager>("Merchello migration runner returned false."); } catch (Exception ex) { _logger.Error<CoreMigrationManager>("Merchello Database Schema Upgrade Failed", ex); throw; } } else { // this is a new install var migrationKey = this.EnsureMigrationKey(schemaResult); var record = new MigrationRecord() { MigrationKey = migrationKey, CurrentVersion = MerchelloConfiguration.ConfigurationStatus, TargetVersion = MerchelloVersion.Current.ToString(), DbProvider = database.GetDatabaseProvider().ToString(), InstallDate = DateTime.Now, IsUpgrade = !MerchelloConfiguration.ConfigurationStatus.Equals("0.0.0") }; this.OnUpgraded(record); } MerchelloConfiguration.ConfigurationStatus = MerchelloVersion.Current.ToString(); return true; }
private void RebuildDatabase() { // migration var schema = new DatabaseSchemaCreation(Database); // drop all the tables schema.UninstallDatabaseSchema(); // install the schema schema.InitializeDatabaseSchema(); // add the default data var baseDataCreation = new BaseDataCreation(Database); baseDataCreation.InitializeBaseData("merchDBTypeField"); baseDataCreation.InitializeBaseData("merchInvoiceStatus"); baseDataCreation.InitializeBaseData("merchOrderStatus"); baseDataCreation.InitializeBaseData("merchWarehouse"); baseDataCreation.InitializeBaseData("merchGatewayProviderSettings"); baseDataCreation.InitializeBaseData("merchStoreSetting"); }
/// <summary> /// Executes the Migration runner. /// </summary> /// <param name="database"> /// The database. /// </param> /// <returns> /// A value indicating whether or not the migration was successful. /// </returns> private bool UpgradeMerchello(Database database) { var databaseSchemaCreation = new DatabaseSchemaCreation(_database, _logger, new DatabaseSchemaHelper(_database, _logger, _sqlSyntaxProvider), _sqlSyntaxProvider); var schemaResult = databaseSchemaCreation.ValidateSchema(); var dbVersion = schemaResult.DetermineInstalledVersion(); var upgraded = false; if (dbVersion != MerchelloVersion.Current) { try { _logger.Info<CoreMigrationManager>("Merchello database upgraded required. Initializing Upgrade."); var resolver = new MigrationResolver(_logger, PluginManager.Current.ResolveMerchelloMigrations()); var migrations = resolver.OrderedUpgradeMigrations( MerchelloConfiguration.ConfigurationStatusVersion, MerchelloVersion.Current).ToList(); var context = InitializeMigrations(migrations, _database, _database.GetDatabaseProvider()); try { ExecuteMigrations(context, _database); upgraded = true; } catch (Exception ex) { _logger.Error<CoreMigrationManager>("Merchello migration failed", ex); upgraded = false; } _logger.Debug<CoreMigrationManager>("Merchello migration runner returned false."); } catch (Exception ex) { _logger.Error<CoreMigrationManager>("Merchello Database Schema Upgrade Failed", ex); throw; } } var currentVersion = dbVersion.ToString(); if (!upgraded) { currentVersion = MerchelloConfiguration.ConfigurationStatusVersion.ToString(); } var migrationKey = this.EnsureMigrationKey(schemaResult); var record = new MigrationRecord() { MigrationKey = migrationKey, CurrentVersion = currentVersion, TargetVersion = MerchelloVersion.Current.ToString(), DbProvider = database.GetDatabaseProvider().ToString(), InstallDate = DateTime.Now, IsUpgrade = currentVersion != "0.0.0" }; this.OnUpgraded(record); _logger.Info<CoreMigrationManager>("Merchello Schema Migration completed successfully"); MerchelloConfiguration.ConfigurationStatus = MerchelloVersion.Current.ToString(); return true; }
/// <summary> /// Ensures the Merchello database has been installed. /// </summary> /// <returns> /// The <see cref="bool"/>. /// </returns> internal bool EnsureDatabase() { var databaseSchemaCreation = new DatabaseSchemaCreation(_database, _logger, new DatabaseSchemaHelper(_database, _logger, _sqlSyntaxProvider), _sqlSyntaxProvider); var schemaResult = databaseSchemaCreation.ValidateSchema(); var databaseVersion = schemaResult.DetermineInstalledVersion(); if (databaseVersion != new Version("0.0.0")) return true; // install the database var schemaHelper = new MerchelloDatabaseSchemaHelper(this._database, this._logger, this._sqlSyntaxProvider); schemaHelper.CreateDatabaseSchema(); var baseDataCreation = new BaseDataCreation(this._database, this._logger); baseDataCreation.InitializeBaseData("merchTypeField"); baseDataCreation.InitializeBaseData("merchInvoiceStatus"); baseDataCreation.InitializeBaseData("merchOrderStatus"); baseDataCreation.InitializeBaseData("merchWarehouse"); baseDataCreation.InitializeBaseData("merchGatewayProviderSettings"); baseDataCreation.InitializeBaseData("merchStoreSetting"); baseDataCreation.InitializeBaseData("merchShipmentStatus"); return false; }
public void Successfully_Create_Default_Database_Schema() { var creation = new DatabaseSchemaCreation(_database); creation.InitializeDatabaseSchema(); }
public void Can_Drop_All_Database_Tables() { var deletions = new DatabaseSchemaCreation(_database); deletions.UninstallDatabaseSchema(); }
/// <summary> /// The uninstall database schema. /// </summary> internal void UninstallDatabaseSchema() { _logger.Info<MerchelloDatabaseSchemaHelper>("Uninstalling Merchello database schema"); var creation = new DatabaseSchemaCreation(_db, _logger, _umbSchemaHelper, _syntaxProvider); creation.UninstallDatabaseSchema(); _logger.Info<MerchelloDatabaseSchemaHelper>("Merchello database schema removed"); }
/// <summary> /// The create database schema. /// </summary> public void CreateDatabaseSchema() { _logger.Info<MerchelloDatabaseSchemaHelper>("Initializing database schema creation"); var creation = new DatabaseSchemaCreation(_db, _logger, _umbSchemaHelper, _syntaxProvider); creation.InitializeDatabaseSchema(); _logger.Info<MerchelloDatabaseSchemaHelper>("Finalized database schema creation"); }
/// <summary> /// Completely uninstalls Merchello's database schema /// </summary> public void UninstallDatabaseSchema() { var uninstaller = new DatabaseSchemaCreation(_database); uninstaller.UninstallDatabaseSchema(); }
/// <summary> /// Creates a new version of Merchello's Database Schema /// </summary> public void InitializeDatabaseSchema() { var creation = new DatabaseSchemaCreation(_database); creation.InitializeDatabaseSchema(); }