Example #1
0
        internal static void ListMigrations()
        {
            Options = new AppOptions();
            var serviceProvider = AppServiceProvider;

            // Put the database update into a scope to ensure
            // that all resources will be disposed.
            using (Scope = serviceProvider.CreateScope())
            {
                // Instantiate the runner
                MigrationRunner = serviceProvider.GetRequiredService <IMigrationRunner>();

                // Execute the migrations
                MigrationRunner.ListMigrations();
            }
        }
        private static void UpdateDatabase(IConfiguration configuration, IHostEnvironment environment)
        {
            IServiceProvider serviceProvider = CreateFluentMigrationServiceProvider(configuration, environment.EnvironmentName);

            using IServiceScope serviceScope = serviceProvider.CreateScope();
            IMigrationRunner            migrationRunner            = serviceScope.ServiceProvider.GetService <IMigrationRunner>();
            IMigrationInformationLoader migrationInformationLoader = migrationRunner.MigrationLoader;
            IMigrationContext           migrationContext           = serviceProvider.GetRequiredService <IMigrationContext>();
            IMigrationGenerator         migrationGenerator         = serviceProvider.GetRequiredService <IMigrationGenerator>();
            string sqlScriptsDirectory = Path.Combine(environment.ContentRootPath, "./Scripts/");

            RefreshDirectory(sqlScriptsDirectory);

            migrationInformationLoader.CreateMigrationsSqlEquivalent(migrationContext, migrationGenerator, sqlScriptsDirectory);

            migrationRunner.ListMigrations();

            if (environment.EnvironmentName.Equals("Testing"))
            {
                migrationRunner.MigrateDown(0);
            }

            migrationRunner.MigrateUp();
        }