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

RFC: how should sqlx-cli handle migrations in dependencies? #3761

Open
abonander opened this issue Feb 27, 2025 · 0 comments
Open

RFC: how should sqlx-cli handle migrations in dependencies? #3761

abonander opened this issue Feb 27, 2025 · 0 comments
Labels
cli Concerns `sqlx-cli` enhancement New feature or request migrations Proposals or bugs involving migrations proposal

Comments

@abonander
Copy link
Collaborator

A question that I ran into while implementing the multi-tenant example in #3383 is how to make it more convenient to run migrations from multiple crates at once.

sqlx-cli could gain a --recursive flag that checks
subdirectories for sqlx.toml files, but that would only work for crates within the directory tree.

For dependencies from crates.io that need to run migrations (e.g. tower-sessions-sqlx-store), we would probably need to check dependencies through Cargo.

I'm imagining something like cargo sqlx db setup --deps which scans dependencies for migrations folders, but we don't want to just assume that a migrations/ folder existing means SQLx should run the scripts within; they could be using a different tool. Scanning dependencies' sources for sqlx.toml files would also likely be pretty inefficient.

For best results this should probably be explicitly opt-in per crate. The dependent crate could have something like this in its sqlx.toml:

[migrate]
# A list of package names of dependencies to additionally run migrations for.
# These migrations will be run first in the order specified, then the current crate's.
include-dependencies = ["foo", "bar"]

This would require running as cargo sqlx so we can use cargo metadata to look up the dependencies.

@abonander abonander added enhancement New feature or request proposal cli Concerns `sqlx-cli` migrations Proposals or bugs involving migrations labels Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Concerns `sqlx-cli` enhancement New feature or request migrations Proposals or bugs involving migrations proposal
Projects
None yet
Development

No branches or pull requests

1 participant