-
Notifications
You must be signed in to change notification settings - Fork 403
Repurpose db-migrate to run all pending migrations #2936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright 2018-2022 contributors to the Marquez project | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package marquez.cli; | ||
|
|
||
| import io.dropwizard.cli.ConfiguredCommand; | ||
| import io.dropwizard.db.DataSourceFactory; | ||
| import io.dropwizard.db.ManagedDataSource; | ||
| import io.dropwizard.setup.Bootstrap; | ||
| import lombok.NonNull; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import marquez.MarquezConfig; | ||
| import marquez.db.DbMigration; | ||
| import net.sourceforge.argparse4j.inf.Namespace; | ||
|
|
||
| /** | ||
| * A command to manually run database migrations. This command to be used to run migrations | ||
| * decoupled from application deployment. | ||
| */ | ||
| @Slf4j | ||
| public class DbMigrateCommand extends ConfiguredCommand<MarquezConfig> { | ||
|
|
||
| public DbMigrateCommand() { | ||
| super("db-migrate", "A command to manually run database migrations."); | ||
| } | ||
|
|
||
| @Override | ||
| protected void run( | ||
| @NonNull Bootstrap<MarquezConfig> bootstrap, | ||
| @NonNull Namespace namespace, | ||
| @NonNull MarquezConfig configuration) | ||
| throws Exception { | ||
|
|
||
| final DataSourceFactory sourceFactory = configuration.getDataSourceFactory(); | ||
| final ManagedDataSource source = | ||
| sourceFactory.build(bootstrap.getMetricRegistry(), "MarquezApp-source"); | ||
|
|
||
| DbMigration.migrateDbOrError(configuration.getFlywayFactory(), source, true); | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,15 +25,15 @@ public static void migrateDbOrError(@NonNull final DataSource source) { | |
| public static void migrateDbOrError( | ||
| @NonNull final FlywayFactory flywayFactory, | ||
| @NonNull final DataSource source, | ||
| final boolean migrateDbOnStartup) { | ||
| final boolean migrateNow) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed to make more sense in the context of |
||
| final Flyway flyway = flywayFactory.build(source); | ||
| // Only attempt a database migration if there are pending changes to be applied, | ||
| // or on the initialization of a new database. Otherwise, error on pending changes | ||
| // when the flag 'migrateOnStartup' is set to 'false'. | ||
| if (!hasPendingDbMigrations(flyway)) { | ||
| log.info("No pending migrations found, skipping..."); | ||
| return; | ||
| } else if (!migrateDbOnStartup && hasDbMigrationsApplied(flyway)) { | ||
| } else if (!migrateNow && hasDbMigrationsApplied(flyway)) { | ||
| errorOnPendingDbMigrations(flyway); | ||
| } | ||
| // Attempt to perform a database migration. An exception is thrown on failed migration attempts | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.