File tree Expand file tree Collapse file tree
api/src/main/java/marquez Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828import marquez .api .filter .JobRedirectFilter ;
2929import marquez .api .filter .exclusions .Exclusions ;
3030import marquez .api .filter .exclusions .ExclusionsConfig ;
31- import marquez .cli .DbMigrationCommand ;
31+ import marquez .cli .DbMigrateCommand ;
3232import marquez .cli .DbRetentionCommand ;
3333import marquez .cli .MetadataCommand ;
3434import marquez .cli .SeedCommand ;
@@ -90,6 +90,7 @@ public void initialize(@NonNull Bootstrap<MarquezConfig> bootstrap) {
9090 new EnvironmentVariableSubstitutor (ERROR_ON_UNDEFINED )));
9191
9292 // Add CLI commands
93+ bootstrap .addCommand (new DbMigrateCommand ());
9394 bootstrap .addCommand (new DbRetentionCommand ());
9495 bootstrap .addCommand (new MetadataCommand ());
9596 bootstrap .addCommand (new SeedCommand ());
@@ -202,12 +203,6 @@ public void registerResources(
202203 }
203204 }
204205
205- @ Override
206- protected void addDefaultCommands (Bootstrap <MarquezConfig > bootstrap ) {
207- bootstrap .addCommand (new DbMigrationCommand <>(this ));
208- super .addDefaultCommands (bootstrap );
209- }
210-
211206 private void registerServlets (@ NonNull Environment env ) {
212207 log .debug ("Registering servlets..." );
213208
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2018-2022 contributors to the Marquez project
3+ * SPDX-License-Identifier: Apache-2.0
4+ */
5+
6+ package marquez .cli ;
7+
8+ import io .dropwizard .cli .ConfiguredCommand ;
9+ import io .dropwizard .db .DataSourceFactory ;
10+ import io .dropwizard .db .ManagedDataSource ;
11+ import io .dropwizard .setup .Bootstrap ;
12+ import lombok .NonNull ;
13+ import lombok .extern .slf4j .Slf4j ;
14+ import marquez .MarquezConfig ;
15+ import marquez .db .DbMigration ;
16+ import net .sourceforge .argparse4j .inf .Namespace ;
17+
18+ /**
19+ * A command to manually run database migrations. This command to be used to run migrations
20+ * decoupled from application deployment.
21+ */
22+ @ Slf4j
23+ public class DbMigrateCommand extends ConfiguredCommand <MarquezConfig > {
24+
25+ public DbMigrateCommand () {
26+ super ("db-migrate" , "A command to manually run database migrations." );
27+ }
28+
29+ @ Override
30+ protected void run (
31+ @ NonNull Bootstrap <MarquezConfig > bootstrap ,
32+ @ NonNull Namespace namespace ,
33+ @ NonNull MarquezConfig configuration )
34+ throws Exception {
35+
36+ final DataSourceFactory sourceFactory = configuration .getDataSourceFactory ();
37+ final ManagedDataSource source =
38+ sourceFactory .build (bootstrap .getMetricRegistry (), "MarquezApp-source" );
39+
40+ DbMigration .migrateDbOrError (configuration .getFlywayFactory (), source , true );
41+ }
42+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -25,15 +25,15 @@ public static void migrateDbOrError(@NonNull final DataSource source) {
2525 public static void migrateDbOrError (
2626 @ NonNull final FlywayFactory flywayFactory ,
2727 @ NonNull final DataSource source ,
28- final boolean migrateDbOnStartup ) {
28+ final boolean migrateNow ) {
2929 final Flyway flyway = flywayFactory .build (source );
3030 // Only attempt a database migration if there are pending changes to be applied,
3131 // or on the initialization of a new database. Otherwise, error on pending changes
3232 // when the flag 'migrateOnStartup' is set to 'false'.
3333 if (!hasPendingDbMigrations (flyway )) {
3434 log .info ("No pending migrations found, skipping..." );
3535 return ;
36- } else if (!migrateDbOnStartup && hasDbMigrationsApplied (flyway )) {
36+ } else if (!migrateNow && hasDbMigrationsApplied (flyway )) {
3737 errorOnPendingDbMigrations (flyway );
3838 }
3939 // Attempt to perform a database migration. An exception is thrown on failed migration attempts
Original file line number Diff line number Diff line change 99 - " api/src/main/java/marquez/db/migrations/V44_1__UpdateRunsWithJobUUID.java"
1010 - " api/src/main/java/marquez/db/migrations/V44_2__BackfillAirflowParentRuns.java"
1111 - " api/src/main/java/marquez/db/migrations/V44_3_BackfillJobsWithParents.java"
12- - " api/src/main/java/marquez/cli/DbMigrationCommand .java"
12+ - " api/src/main/java/marquez/cli/DbMigrateCommand .java"
You can’t perform that action at this time.
0 commit comments