Infrastructure/Resources
Postgres
How to migrate a web service that uses Postgres to Shuttle
Shuttle has a native resource integration for Postgres by default with the shuttle-shared-db
crate.
Reference
Quickstart
See the following code comparison below (using Axum and SQLx):
Shared database
You can find out more about shared databases here.
By default, the resource annotation will output the connection string for your database. You can augment this by adding relevant feature flags:
diesel-async
(enables outputtingdiesel_async::AsyncPgConnection
from the resource)diesel-async-bb8
(enables outputtingdiesel_bb8::Pool<diesel_async::AsyncPgConnection>
from the resource)diesel-async-deadpool
(enables outputtingdiesel_deadpool::Pool<diesel_async::AsyncPgConnection>
from the resource)sqlx
(enables outputtingsqlx::PgPool
from the resource)
Note that the relevant crates will need to be added manually (the relevant Diesel crate as noted in the type signatures, or SQLx if using it).
How does it work?
The Shuttle runtime analyzes the given macro annotations and does one of two things:
- If your service is run locally, attempt to spin up a local Postgres container via Docker (unless
local_addr
is provided then it will use ) - If your service is deployed, the Shuttle runtime will provision a Postgres database to you.
If you need to view your Postgres connection string, you can do so with shuttle resource list
.