Esempio n. 1
0
        private static async Task RunWithOptionsAsync(ConsoleArguments consoleArguments, ILogger logger)
        {
            try {
                consoleArguments.CalculateDefaults();
                await using var connectionPool = new PostgreSqlConnectionPool();

                var appConfig        = new AppConfiguration(consoleArguments);
                var scriptsAccessor  = new SqlScriptsFileAccessor(appConfig);
                var scriptRunner     = new PostgreSqlScriptRunner(appConfig.CurrentEnvironment, connectionPool);
                var executionManager = new ExecutionManager(scriptsAccessor, connectionPool, scriptRunner);

                var success = false;
                if (consoleArguments.Up)
                {
                    success = await executionManager.RunUpScriptsAsync(_stoppingCts.Token);
                }
                else
                {
                    success = await executionManager.RunDownScriptsAsync(_stoppingCts.Token);
                }
                if (!success)
                {
                    throw new ApplicationException("Script running failed");
                }
            }
            catch (Exception ex) {
                logger.Error(ex);
            }
        }
Esempio n. 2
0
        public AppConfiguration(ConsoleArguments consoleArgs)
        {
            ConsoleArgs = consoleArgs ?? throw new ArgumentNullException(nameof(consoleArgs));
            var settingsPath = string.IsNullOrWhiteSpace(ConsoleArgs.SettingsPath)
                ? "appsettings.json"
                : ConsoleArgs.SettingsPath;

            _appSettings = new ConfigurationBuilder()
                           .AddJsonFile(settingsPath)
                           .AddUserSecrets <Program>()
                           .Build();
        }