public InvocationResponse CreateDatabase(string targetModel, DatabaseConfigModel config)
        {
            var targetConfigurator = GetTargetConfigurator(targetModel);

            if (targetConfigurator == null)
            {
                return(new InvocationResponse("No configurator found"));
            }

            // Update config copy from model
            var updatedConfig = UpdateConfigFromModel(targetConfigurator.Config, config);

            try
            {
                var creationResult = targetConfigurator.CreateDatabase(updatedConfig);
                return(creationResult
                    ? new InvocationResponse()
                    : new InvocationResponse("Cannot create database. May be the database already exists or was misconfigured."));
            }
            catch (Exception ex)
            {
                Logger.LogException(LogLevel.Warning, ex, "Database creation failed!");
                return(new InvocationResponse(ex));
            }
        }
 public void SetAllConfigs(DatabaseConfigModel config)
 {
     // Overwrite all configs
     BulkOperation(mc =>
     {
         // Save and reload config
         UpdateConfigFromModel(mc.Config, config);
         mc.UpdateConfig();
     }, "Save config");
 }
        public void SetDatabaseConfig(string targetModel, DatabaseConfigModel config)
        {
            var match = GetTargetConfigurator(targetModel);

            if (match == null)
            {
                return;
            }

            // Save config and reload all DataModels
            UpdateConfigFromModel(match.Config, config);
            match.UpdateConfig();
        }
        public InvocationResponse RollbackDatabase(string targetModel, DatabaseConfigModel config)
        {
            var targetConfigurator = GetTargetConfigurator(targetModel);

            if (targetConfigurator == null)
            {
                return(new InvocationResponse("No configurator found"));
            }

            var updatedConfig  = UpdateConfigFromModel(targetConfigurator.Config, config);
            var rollbackResult = targetConfigurator.RollbackDatabase(updatedConfig);

            return(rollbackResult ? new InvocationResponse() : new InvocationResponse("Error while rollback!"));
        }
        public InvocationResponse DumpDatabase(string targetModel, DatabaseConfigModel config)
        {
            var targetConfigurator = GetTargetConfigurator(targetModel);

            if (targetConfigurator == null)
            {
                return(new InvocationResponse("No configurator found"));
            }

            var updatedConfig = UpdateConfigFromModel(targetConfigurator.Config, config);

            targetConfigurator.DumpDatabase(updatedConfig, Config.SetupDataDir);

            return(new InvocationResponse());
        }
        public TestConnectionResponse TestDatabaseConfig(string targetModel, DatabaseConfigModel config)
        {
            var targetConfigurator = GetTargetConfigurator(targetModel);

            if (targetConfigurator == null)
            {
                return new TestConnectionResponse {
                           Result = TestConnectionResult.ConfigurationError
                }
            }
            ;

            // Update config copy from model
            var updatedConfig = UpdateConfigFromModel(targetConfigurator.Config, config);
            var result        = targetConfigurator.TestConnection(updatedConfig);

            return(new TestConnectionResponse {
                Result = result
            });
        }
        public InvocationResponse DumpDatabase(string targetModel, DatabaseConfigModel config)
        {
            var targetConfigurator = GetTargetConfigurator(targetModel);

            if (targetConfigurator == null)
            {
                return(new InvocationResponse("No configurator found"));
            }

            var updatedConfig = UpdateConfigFromModel(targetConfigurator.Config, config);

            var targetPath = Path.Combine(Config.SetupDataDir, targetModel);

            if (!Directory.Exists(targetPath))
            {
                Directory.CreateDirectory(targetPath);
            }

            targetConfigurator.DumpDatabase(updatedConfig, targetPath);

            return(new InvocationResponse());
        }
        public InvocationResponse EraseDatabase(string targetModel, DatabaseConfigModel config)
        {
            var targetConfigurator = GetTargetConfigurator(targetModel);

            if (targetConfigurator == null)
            {
                return(new InvocationResponse("No configurator found"));
            }

            // Update config copy from model
            var updatedConfig = UpdateConfigFromModel(targetConfigurator.Config, config);

            try
            {
                targetConfigurator.DeleteDatabase(updatedConfig);
                return(new InvocationResponse());
            }
            catch (Exception ex)
            {
                Logger.LogException(LogLevel.Warning, ex, "Database deletion failed!");
                return(new InvocationResponse(ex));
            }
        }
 private static IDatabaseConfig UpdateConfigFromModel(IDatabaseConfig dbConfig, DatabaseConfigModel model)
 {
     dbConfig.Host     = model.Server;
     dbConfig.Port     = model.Port;
     dbConfig.Database = model.Database;
     dbConfig.Username = model.User;
     dbConfig.Password = model.Password;
     return(dbConfig);
 }
Ejemplo n.º 10
0
        public DatabaseUpdateSummary MigrateDatabaseModel(string targetModel, string migrationName, DatabaseConfigModel configModel)
        {
            var targetConfigurator = GetTargetConfigurator(targetModel);

            if (targetConfigurator == null)
            {
                return new DatabaseUpdateSummary {
                           WasUpdated = false
                }
            }
            ;

            var config = UpdateConfigFromModel(targetConfigurator.Config, configModel);

            return(targetConfigurator.MigrateDatabase(config, migrationName));
        }