From 635a57645e6bc86a307f307fdb9007fbc053b9bb Mon Sep 17 00:00:00 2001 From: continuist Date: Sun, 21 Sep 2025 14:53:29 -0400 Subject: [PATCH] Run database migration directly in backend main() --- .forgejo/workflows/ci.yml | 14 +++++++------- backend/crates/sharenet-api-postgres/src/main.rs | 5 +++++ deploy/prod-pod.yml | 3 --- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index f085df8..779d4c7 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -4,7 +4,7 @@ on: [push, pull_request] jobs: test-backend: runs-on: [ci] - if: false + # if: false # Point all steps at the host's rootless Podman socket env: @@ -128,7 +128,7 @@ jobs: test-frontend: runs-on: [ci] - # if: false + if: false # needs: test-backend steps: @@ -140,7 +140,7 @@ jobs: build-backend: runs-on: [ci] - if: false + # if: false needs: [test-backend, test-frontend] # needs: [test-frontend] @@ -177,8 +177,8 @@ jobs: build-frontend: runs-on: [ci] # if: false - # needs: [test-backend, test-frontend] - needs: [test-frontend] + needs: [test-backend, test-frontend] + # needs: [test-frontend] env: CONTAINER_HOST: unix:///run/user/1001/podman/podman.sock @@ -236,8 +236,8 @@ jobs: deploy-prod: runs-on: [prod] - needs: [build-frontend] - # needs: [build-backend, build-frontend] + # needs: [build-frontend] + needs: [build-backend, build-frontend] env: CONTAINER_HOST: unix:///run/user/1001/podman/podman.sock diff --git a/backend/crates/sharenet-api-postgres/src/main.rs b/backend/crates/sharenet-api-postgres/src/main.rs index 80a8e11..f6adb92 100644 --- a/backend/crates/sharenet-api-postgres/src/main.rs +++ b/backend/crates/sharenet-api-postgres/src/main.rs @@ -25,6 +25,11 @@ async fn main() -> anyhow::Result<()> { .connect(&database_url) .await?; + // Run database migrations + sqlx::migrate!("../../migrations") + .run(&pool) + .await?; + // Create repositories let user_repo = PostgresUserRepository::new(pool.clone()); let product_repo = PostgresProductRepository::new(pool); diff --git a/deploy/prod-pod.yml b/deploy/prod-pod.yml index 1937576..3bc5207 100644 --- a/deploy/prod-pod.yml +++ b/deploy/prod-pod.yml @@ -78,9 +78,6 @@ spec: value: "postgres://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@127.0.0.1:${POSTGRES_PORT}/${POSTGRES_DATABASE_NAME}?sslmode=disable" - name: PORT value: "${PROD_BACKEND_PORT}" - command: ["sh", "-c"] - args: - - "cd /app && sqlx migrate run --database-url $DATABASE_URL && ./sharenet-api-postgres" ports: - containerPort: ${PROD_BACKEND_PORT} protocol: TCP