Skip to content
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

cmd: migrate command #18

Merged
merged 7 commits into from
Jun 10, 2024
Merged

cmd: migrate command #18

merged 7 commits into from
Jun 10, 2024

Conversation

daniel-burghardt
Copy link
Member

What

Adds the migrate up/down command.

Why

For applying the database migration. This is a required component for the CI/CD setup.

Known limitations

N/A

Issue that this PR addresses

[Wallet Backend] Implement migrate command

Checklist

PR Structure

  • It is not possible to break this PR down into smaller PRs.
  • This PR does not mix refactoring changes with feature changes.
  • This PR's title starts with name of package that is most changed in the PR, or all if the changes are broad or impact many packages.

Thoroughness

  • This PR adds tests for the new functionality or fixes.
  • All updated queries have been tested (refer to this check if the data set returned by the updated query is expected to be same as the original one).

Release

  • This is not a breaking change.
  • This is ready to be tested in development.
  • The new functionality is gated with a feature flag if this is not ready for production.

@daniel-burghardt daniel-burghardt self-assigned this Jun 5, 2024
@daniel-burghardt daniel-burghardt changed the title migrate: command added cmd: migrate command Jun 5, 2024
cmd/migrate.go Outdated
Comment on lines 34 to 39
PersistentPreRun: func(_ *cobra.Command, _ []string) {
cfgOpts.Require()
if err := cfgOpts.SetValues(); err != nil {
log.Fatalf("Error setting values of config options: %s", err.Error())
}
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before you write too many CLI commands, there's a good practice you should adopt here.

These commands have counterparts that return errors:

  • PersistentPreRun -> PersistentPreRunE
  • Run -> RunE
  • ...

Instead of logging with Fatal, it's better to return an error and log + Panic in the root caller. It's easier to debug and to write tests for it.

log.Fatalf calls os.Exit(0), which terminates the program without very good feedback.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for raising this @marcelosalloum! Great suggestion.
I'll add to this one and refactor the other two commands we already have in place. 👍

Copy link
Member Author

@daniel-burghardt daniel-burghardt Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@CaioTeixeira95 CaioTeixeira95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this command! 🚀

internal/db/migrate.go Outdated Show resolved Hide resolved
cmd/migrate.go Outdated Show resolved Hide resolved
cmd/migrate.go Outdated Show resolved Hide resolved
@@ -24,3 +24,8 @@ func Open(t *testing.T) *dbtest.DB {

return db
}

func OpenWithoutMigrations(t *testing.T) *dbtest.DB {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

cmd/migrate.go Show resolved Hide resolved
What
Adds the Dockerfile for building the API's Docker image. A Makefile is also added to make the CI/CD later easier.
The docker-compose is also changed to use the new Dockerfile and run the API more easily.

Why
Building the system's Docker image.
@daniel-burghardt daniel-burghardt merged commit ef6aeda into main Jun 10, 2024
5 checks passed
@daniel-burghardt daniel-burghardt deleted the migrate-command branch June 10, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants