shuttle-hq / shuttle

Build & ship backends without writing any infrastructure files.
https://shuttle.rs
Apache License 2.0
6.07k stars 251 forks source link

[Bug]: Can't use sqlx compile time macros #1509

Open dev-ardi opened 9 months ago

dev-ardi commented 9 months ago

What happened?

Sqlx refuses to build because it can't connect to a database and shuttle refuses to provision a database because the code doesn't build!

For people experiencing this issue My workaround is to delete all code except

async fn axum(#[shuttle_shared_db::Postgres] pool: PgPool) -> shuttle_axum::ShuttleAxum {
    sqlx::migrate!().run(&pool).await.expect("Migration failed");

and then git reset --hard

Version

cargo-shuttle 0.35.2

Which operating system(s) are you seeing the problem on?

Linux

Which CPU architectures are you seeing the problem on?

x86_64

Relevant log output

No response

Duplicate declaration

oddgrd commented 9 months ago

Hey @dev-ardi! This is due to using the sqlx query macros that run compile-time checks against a database. I believe you can resolve this by using sqlx offline mode. Let me know how it goes, and if it works out we'll update our docs.

SymenTimmermans commented 9 months ago

I experienced the same thing, although while using Actix-web. I resolved it by using the hello world example from the repo, with the shuttle-annotations in the main function kept in place. After it built, I could revert back, and it worked fine from there.

I don't run the docker systemd service by default, so it might not have been running when I first tried to run the project. I started the service soon afterwards, but I had to resort to rewriting main.rs to get the project to build again.