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

Build a CLI for running schema changes, migration etc #14

Open
mjovanc opened this issue Sep 20, 2023 · 15 comments
Open

Build a CLI for running schema changes, migration etc #14

mjovanc opened this issue Sep 20, 2023 · 15 comments
Labels
feature New feature or request

Comments

@mjovanc
Copy link
Owner

mjovanc commented Sep 20, 2023

Commands that should exist:

njord migration generate <name>
njord migration run
njord migration rollback

Flags that should exist on njord:

  • -v and --version
  • -h and --help

Flags that should exist on njord migration:

  • --dry-run (simulate the migration)
  • --env (specify development/test/staging/production etc)
  • --dir (specify target directory for generated migration changes)
  • --to (rollback to specific version, for example 20191225120000)
  • --log-level (standard, debug etc)

Examples:

njord setup
njord migration generate <name> --env=development --dry-run
njord migration run --env=production --log-level=debug
njord migration rollback --env=development --to=20191225120000
@mjovanc mjovanc added the feature New feature or request label Dec 11, 2023
@mjovanc mjovanc self-assigned this Dec 12, 2023
@mjovanc
Copy link
Owner Author

mjovanc commented Dec 12, 2023

Command/args logic now in place and skeleton functions added that will be updated later.

@mjovanc
Copy link
Owner Author

mjovanc commented Dec 13, 2023

Basic command line functionality in place, now its just time to actually implement generate, run and rollback functions.

@mjovanc
Copy link
Owner Author

mjovanc commented Dec 13, 2023

How should we specify which connector we should use, for example:

njord migration generate <name> --env=development --dry-run --connector=sqlite

or during installation of the CLI with:

cargo install njord --no-default-features --features sqlite

@mjovanc
Copy link
Owner Author

mjovanc commented Dec 13, 2023

By using:

njord setup

We should look for a file usually located in src/schema.rs if not specified elsewhere in njord.toml file to extract values from there and create SQL queries based on that. Not like Diesel does that you have to manually create the SQL queries to setup tables...

@mjovanc
Copy link
Owner Author

mjovanc commented Dec 15, 2023

Passing in --env=development doesn't get the actual value as well as other arguments:

Migration files generated successfully:
Version: 00000000000002
Name: --name=update_users
Environment: Some("--")
Dry-run: None

@newtoallofthis123
Copy link

This looks like something right up my alley 😁

@mjovanc
Copy link
Owner Author

mjovanc commented Dec 16, 2023

@newtoallofthis123 Super! Would you have time to look at my previous comment with that issue with passing arguments? That would be very helpful since I do not have time at the moment to look at it. If you do, just fork the repo, send a PR. Thanks!

@newtoallofthis123
Copy link

Sure will

@newtoallofthis123
Copy link

Hey! Your code seems quite good and it is working just fine for me...

image

My suspicion is that it might be a weird thing with your terminal....can you once try using '--env=development' or --env='development'

@mjovanc
Copy link
Owner Author

mjovanc commented Dec 17, 2023

Alright, I can not test right now, but could you look maybe into how we can strip the --env= from the arg strings here: https://github.com/njord-rs/njord/blob/master/njord_cli/src/command.rs#L139

So we can pass only the "pure" values into the next function to call, either generate(), run() and rollback()?

@newtoallofthis123
Copy link

So, strip the string and have an enum? or something like that?

@mjovanc
Copy link
Owner Author

mjovanc commented Dec 17, 2023

So, strip the string and have an enum? or something like that?

Sounds good to me!

@mjovanc
Copy link
Owner Author

mjovanc commented Mar 25, 2024

The CLI has been improved with functionality of generating new schema changes and running it. However a lot of work still persists and help here is needed! Will pause this CLI tool since it's not really necessary at the moment. More important work is needed on njord and njord_derive crate.

Let me know if someone is interested in helping out here.

@mjovanc
Copy link
Owner Author

mjovanc commented Mar 25, 2024

@shadrach-tayo
Copy link

I just forked the repo and will try to read through it to understand the code. Happy to continue work on this as soon I'm done

@mjovanc mjovanc removed their assignment Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants