From 690a7111aa4fcef8d2287f357c8dfb89907f2164 Mon Sep 17 00:00:00 2001 From: stefiosif Date: Wed, 24 Jun 2026 20:10:34 +0300 Subject: [PATCH] chore: update justfile commands and parameterize healthcheck info Co-Authored-By: Claude Opus 4.8 --- Justfile | 7 ---- compose.yml | 4 +- justfile | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 9 deletions(-) delete mode 100644 Justfile create mode 100644 justfile diff --git a/Justfile b/Justfile deleted file mode 100644 index 21b40a4..0000000 --- a/Justfile +++ /dev/null @@ -1,7 +0,0 @@ -backend_path := "backend" - -watch: - cd {{backend_path}} && cargo watch -q -c -w src/ -x run - -watch-test: - cd {{backend_path}} && cargo watch -q -c -w src/ -x test \ No newline at end of file diff --git a/compose.yml b/compose.yml index 5ce0df0..269a970 100644 --- a/compose.yml +++ b/compose.yml @@ -11,7 +11,7 @@ services: volumes: - loft_db_data:/var/lib/postgresql/data healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres -d loft"] + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] interval: 5s timeout: 5s retries: 5 @@ -21,7 +21,7 @@ services: restart: unless-stopped build: . ports: - - "3000:3000" + - "3000:3000" depends_on: db: condition: service_healthy diff --git a/justfile b/justfile new file mode 100644 index 0000000..efd35c9 --- /dev/null +++ b/justfile @@ -0,0 +1,106 @@ +backend_path := "backend" +frontend_path := "frontend" + +# Run backend + frontend watchers in split tmux panes (run from inside tmux) +[group('dev')] +watch: + #!/usr/bin/env bash + tmux split-window -h 'just watch-frontend' + just watch-backend + +# Run the backend with hot reload +[group('dev')] +watch-backend: + cd {{backend_path}} && cargo watch -q -c -w src/ -x run + +# Run the frontend dev server +[group('dev')] +watch-frontend: + cd {{frontend_path}} && pnpm dev + +# Run the backend tests in watch mode (sets up the test DB first) +[group('test')] +watch-test: test-db-setup + cd {{backend_path}} && cargo watch -q -c -w src/ -x test + +# Run the Playwright e2e suite (sets up the test DB + servers) +[group('test')] +e2e: + mkdir -p /tmp/loft-files-test + cd {{backend_path}} && set -a && . ./.env.test && set +a && (sqlx database create 2>/dev/null || true) && sqlx migrate run + docker compose exec -T db psql -U postgres -d loft_test -c "TRUNCATE users, sessions, file_records CASCADE" + cd {{frontend_path}} && pnpm exec playwright test + +# Format backend + frontend +[group('quality')] +fmt: fmt-backend fmt-frontend + +# Format the backend (cargo fmt) +[group('quality')] +fmt-backend: + cd {{backend_path}} && cargo fmt + +# Format the frontend (prettier) +[group('quality')] +fmt-frontend: + cd {{frontend_path}} && pnpm exec prettier --write . + +# Lint the backend (cargo clippy) +[group('quality')] +lint-backend: + cd {{backend_path}} && cargo clippy + +# Stage the given files (git add) +[group('git')] +stage +files: + git add {{files}} + +# Commit staged changes with a message +[group('git')] +commit message: + git commit -m "{{message}}" + +# Commit staged changes with a Claude co-author trailer +[group('git')] +co-commit message: + git commit -m "{{message}}" -m "Co-Authored-By: Claude Opus 4.8 " + +# Push main to both the github and gitea remotes +[group('git')] +push: + git push -u github main && git push -u gitea main + +# Create (if missing) + migrate the test database +[group('db')] +test-db-setup: db-up + cd {{backend_path}} && set -a && . ./.env.test && set +a && (sqlx database create 2>/dev/null || true) && sqlx migrate run + +# Bring up the dev database container +[group('db')] +db-up: + docker compose up -d db + +# Create (if missing) + migrate the dev database +[group('db')] +db-setup: db-up + cd {{backend_path}} && set -a && . ./.env && set +a && (sqlx database create 2>/dev/null || true) && sqlx migrate run + +# Apply pending migrations to the dev database +[group('db')] +migrate: + cd {{backend_path}} && set -a && . ./.env && set +a && sqlx migrate run + +# Open a psql shell on the dev database +[group('db')] +db-shell: + docker compose exec db psql -U postgres -d loft + +# Run a SQL query against the dev database +[group('db')] +db-query query: + docker compose exec db psql -U postgres -d loft -c "{{query}}" + +# Open a shell inside the app container +[group('db')] +app-shell: + docker compose exec app sh