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

feat: add hsdev binary to run migrations #4877

Merged
merged 15 commits into from
Jul 8, 2024
Merged

Conversation

davidkurilla
Copy link
Contributor

@davidkurilla davidkurilla commented Jun 4, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

This PR closes #4589
Created a new Rust binary in the crates directory which automates the Diesel migrations with Postgres. The new tool is a CLI tool that takes a path to a TOML file as an argument along with the name of a TOML table to extract Postgres database credentials from. The tool then automatically performs the migrations by utilizing diesel_migrations library. From our testing, we were able to set up Hyperswitch locally without using diesel_cli and Bash variables on WSL2 Ubuntu.

I worked on this Issue with @JamesM25 @ind1goDusk

The example below shows the application running using cargo run in the hsdev crate.

cargo run -- --toml-file ~/hyperswitch/config/development.toml --toml-table master_database

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

Before our tool, Hyperswitch needed to be set up on local machines using a long diesel_cli command with Bash variables for the Postgres migration. Now we have provided a simpler and easily repeatable solution to Postgres and Diesel migrations that allows for greater modularity as you can select specific TOML files and tables to select database credentials from.

How did you test it?

We wrote two units test on the core functionality. We tested it both on a dummy TOML file as well as in Hyperswitch repository. We were able to set up Hyperswitch locally using hsdev instead of diesel_cli.

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@davidkurilla davidkurilla requested a review from a team as a code owner June 4, 2024 20:18
@davidkurilla davidkurilla changed the title [feat]: add 'hsdev' binary to 'crates' directory feat(enhancement): add 'hsdev' binary to 'crates' directory Jun 4, 2024
@SanchithHegde SanchithHegde added A-framework Area: Framework C-feature Category: Feature request or enhancement labels Jun 5, 2024
crates/hsdev/Cargo.toml Outdated Show resolved Hide resolved
crates/hsdev/docs/README.md Outdated Show resolved Hide resolved
crates/hsdev/src/input_file.rs Outdated Show resolved Hide resolved
Comment on lines 11 to 15
let toml_str = "username = \"db_user\"\n\
password = \"db_pass\"\n\
dbname = \"db_name\"\n\
host = \"localhost\"\n\
port = 5432";
Copy link
Member

Choose a reason for hiding this comment

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

Optional change: you can take advantage of Rust's raw string literals instead of having to escape quotes:

let toml_str = r#"username = "db_user"
password = "db_pass"
dbname = "db_name"
host = "localhost"
port = 5432"#;

@SanchithHegde SanchithHegde added the S-waiting-on-author Status: This PR is incomplete or needs to address review comments label Jun 5, 2024
@SanchithHegde
Copy link
Member

@davidkurilla @JamesM25 Could you also address the failing CI checks?

@SanchithHegde
Copy link
Member

@JamesM25 Please address the clippy lints as well. Feel free to reach out if you have any queries about them. As for the failing MSRV check, we can run cargo update -p migrations_macros@2.2.0 --precise 2.1.0, and then commit the Cargo.lock file and push it.

@SanchithHegde SanchithHegde changed the title feat(enhancement): add 'hsdev' binary to 'crates' directory feat(enhancement): add hsdev binary to run migrations Jul 8, 2024
@SanchithHegde SanchithHegde changed the title feat(enhancement): add hsdev binary to run migrations feat: add hsdev binary to run migrations Jul 8, 2024
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jul 8, 2024
Merged via the queue into juspay:main with commit f64b522 Jul 8, 2024
21 checks passed
@SanchithHegde SanchithHegde removed the S-waiting-on-author Status: This PR is incomplete or needs to address review comments label Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-framework Area: Framework C-feature Category: Feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Add a cargo binary for running diesel migrations locally
5 participants