Skip to content

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

Open
@abonander

Description

@abonander

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliConcerns `sqlx-cli`enhancementNew feature or requestmigrationsProposals or bugs involving migrationsproposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions