Compare commits
1 Commits
2a1047d970
...
0792935b76
Author | SHA1 | Date | |
---|---|---|---|
0792935b76 |
@ -1 +1 @@
|
|||||||
|
DATABASE_URL="postgres://root@localhost:26257/defaultdb?sslmode=disable"
|
||||||
|
@ -13,5 +13,6 @@ 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"] }
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
-- Add migration script here
|
@ -6,6 +6,7 @@ use axum::http::Request;
|
|||||||
use axum::Router;
|
use axum::Router;
|
||||||
use axum::routing::get;
|
use axum::routing::get;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
use sqlx::{Pool, Postgres};
|
||||||
use tower_http::trace::TraceLayer;
|
use tower_http::trace::TraceLayer;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
@ -81,11 +82,25 @@ 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> {
|
||||||
Ok(Self {})
|
let db = sqlx::PgPool::connect(
|
||||||
|
&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 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
cuddle-rust-service/templates/docker-compose.yaml
Normal file
15
cuddle-rust-service/templates/docker-compose.yaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
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'
|
Loading…
Reference in New Issue
Block a user