feat: remove crdb from rust-service

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-10-16 14:16:47 +02:00
parent 5aeb2b8bff
commit 74b81c9762
Signed by: kjuulh
GPG Key ID: D85D7535F18F35FA
5 changed files with 3 additions and 34 deletions

View File

@ -1 +1 @@
DATABASE_URL="postgres://root@localhost:26257/defaultdb?sslmode=disable"

View File

@ -13,6 +13,5 @@ dotenv.workspace = true
axum.workspace = true axum.workspace = true
serde = { version = "1.0.197", features = ["derive"] } serde = { version = "1.0.197", features = ["derive"] }
sqlx = { version = "0.7.3", features = ["runtime-tokio", "tls-rustls", "postgres", "uuid", "time"] }
uuid = { version = "1.7.0", features = ["v4"] } uuid = { version = "1.7.0", features = ["v4"] }
tower-http = { version = "0.5.2", features = ["cors", "trace"] } tower-http = { version = "0.5.2", features = ["cors", "trace"] }

View File

@ -1 +0,0 @@
-- Add migration script here

View File

@ -82,25 +82,11 @@ impl Deref for SharedState {
} }
} }
pub struct State { pub struct State {}
pub db: Pool<Postgres>,
}
impl State { impl State {
pub async fn new() -> anyhow::Result<Self> { pub async fn new() -> anyhow::Result<Self> {
let db = sqlx::PgPool::connect( Ok(Self {})
&std::env::var("DATABASE_URL").context("DATABASE_URL is not set")?,
)
.await?;
sqlx::migrate!("migrations/crdb")
.set_locking(false)
.run(&db)
.await?;
let _ = sqlx::query("SELECT 1;").fetch_one(&db).await?;
Ok(Self { db })
} }
} }

View File

@ -1,15 +0,0 @@
version: "3"
services:
crdb:
restart: 'always'
image: 'cockroachdb/cockroach:v23.1.14'
command: 'start-single-node --advertise-addr 0.0.0.0 --insecure'
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health?ready=1"]
interval: '10s'
timeout: '30s'
retries: 5
start_period: '20s'
ports:
- 8080:8080
- '26257:26257'