Skip to content

Feature: Fixtures outside of sqlx::test, like sqlx::fixtures!() or other function that exposes code to load fixtures #3868

Open
@tgrushka

Description

@tgrushka

I have found these related issues/pull requests

I've found a list of open and closed issues related to fixtures in #[sqlx::test] but I don't see anything about a feature request for a way to access this fixture loading functionality outside of #[sqlx::test], either in code or in the CLI.

Description

Hi, I'm using sqlx and of course #[sqlx::test] for unit/integration tests, but I also have a "test client" for my app, and in development, I'd like to just be able to load fixtures manually.

(Another thought is "factories, not fixtures" which would be very useful in tests so we wouldn't have to maintain .sql files just for test fixtures, but that's out of scope here. I see a few limited crates like cder that proport to do this, but I don't see much elegance on this front and integration with tests.)

Since we have to create .sql files for fixtures for use with the #[sqlx::test(fixtures(...)] feature anyway, it would be nice if we could:

  1. re-use these outside of #[sqlx::test]; and
  2. have access to it in the CLI, perhaps under sqlx database fixtures or similar.

Is there any way to expose the code that loads fixtures to a sqlx::fixtures!(...) macro, just like sqlx::migrate!(...)? Or even a non-macro function that just takes a list of fixtures to load? This would be really helpful in development to reduce boilerplate of either:

  1. Loading up the .sql files and executing them one by one; or
  2. Running an external command,

... when this capability is already built into sqlx.

Thanks!

Prefered solution

  1. Access to a function/method to load fixtures using the feature already built into sqlx, outside of #[sqlx::test], similar to sqlx::migrate!(...) e.g. sqlx::fixtures!(...) or similar.
  2. Access to this functionality via the CLI, perhaps under sqlx database fixtures or similar.

Is this a breaking change? Why or why not?

I don't think it would be a breaking change because I don't see any feature that exposes this functionality currently. Maybe I need a feature flag or something, but I don't see anything on it.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions