Exemple #1
0
        public Task ExecuteAsync(CancellationToken cancellationToken)
        {
            var options = _options.Value;

            ValidateOptions(options);

            var migrationExecutor = _providerCollection.GetMigrationExecutor(options.ProviderType);

            var fileProviders = options.FileProviders;

            var migrations = _migrationFilesLoader.Load(fileProviders, options.Pattern);

            return(migrationExecutor.ExecuteAsync(options.ConnectionString, migrations, options.DryRun, cancellationToken));
        }
Exemple #2
0
        public async Task <int> ExecuteAsync(IMigrationRunnerArguments arguments, CancellationToken cancellationToken)
        {
            var provider = arguments.Provider;

            var configFilePath       = arguments.ConfigFilePath;
            var connectionString     = arguments.ConnectionString;
            var migrationsDirectory  = arguments.MigrationsDirectory;
            var connectionStringName = arguments.ConnectionStringName;
            var environmentName      = arguments.EnvironmentName;

            var environmentVariables = EnvironmentVariables.GetValues();

            try
            {
                if (_migrationOptionsLoader.TryGetOptions(configFilePath,
                                                          connectionString,
                                                          migrationsDirectory,
                                                          connectionStringName,
                                                          environmentName,
                                                          environmentVariables,
                                                          provider,
                                                          out var options))
                {
                    var files = new List <MigrationInfo>();

                    connectionString = options.ConnectionString;
                    var migrationsDirectories = options.MigrationsDirectories;

                    if (ValidateDirectories(migrationsDirectories, files))
                    {
                        var executor = _providerCollection.GetMigrationExecutor(options.ProviderType);

                        await executor.ExecuteAsync(connectionString, files, arguments.DryRun, cancellationToken);
                    }

                    return(0);
                }

                return(1);
            }
            catch (Exception e)
            {
                var exceptionType = e.GetType();
                _logger.LogError(e, "Error in migration process: {ExceptionType} - {Message}", exceptionType,
                                 e.Message);

                return(-1);
            }
        }