示例#1
0
        public static int Run(ILogger logger, DatabaseConnectionSettings settings)
        {
            try
            {
                logger.LogInformation($"Try to migrate \"{settings.DatabaseName}\" database");

                var serviceProvider = MigrateUtilities.CreateServices(settings);
                using (var scope = serviceProvider.CreateScope())
                {
                    // Instantiate the runner
                    var runner = scope.ServiceProvider.GetRequiredService <IMigrationRunner>();

                    // Execute the migrations
                    runner.MigrateDown(0);
                }

                logger.LogInformation($"{settings.DatabaseName} database successfully migrated");
                return(0);
            }
            catch (Exception exception)
            {
                logger.LogError(exception.Message);
                return(1);
            }
        }
        public static int Run(ILogger logger, DatabaseConnectionSettings settings)
        {
            try
            {
                logger.LogInformation($"Try to drop \"{settings.DatabaseName}\" database");

                using (var connection = MigrateUtilities.CreateServerConnection(settings))
                {
                    var comma = MigrateUtilities.CreateCommand(settings, $"drop database if exists {settings.DatabaseName}", connection);

                    connection.Open();
                    comma.ExecuteNonQuery();
                    connection.Close();
                }

                logger.LogInformation($"{settings.DatabaseName} database successfully dropped");
                return(0);
            }
            catch (Exception exception)
            {
                logger.LogError(exception.Message);
                return(1);
            }
        }