Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ npm ci
npm run dev
```

`npm run dev` starts the starter project at http://localhost:5173.
`npm run dev` starts the starter project at http://localhost:5173/project2/.

Other commands:

Expand Down
10 changes: 8 additions & 2 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Copy this file to .env and fill in your own values. .env is not committed.
#
# Format: postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=public
DATABASE_URL="postgresql://cop:your-password@localhost:5432/cop?schema=public"
# Runtime server connection (wag_app - restricted CRUD permissions)
DATABASE_URL="postgresql://wag_app:YOUR_APP_PASSWORD@localhost:5432/wag_catalog"

# Migration connection string (wag_migrator - schema owner for migrations & setup)
MIGRATION_DATABASE_URL="postgresql://wag_migrator:YOUR_MIGRATOR_PASSWORD@localhost:5432/wag_catalog"

PORT=3001
SESSION_SECRET="your_session_secret_here"
10 changes: 7 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@
"prisma:migrate": "prisma migrate dev",
"prisma:deploy": "prisma migrate deploy",
"prisma:seed": "prisma db seed",
"prisma:studio": "prisma studio"
"prisma:studio": "prisma studio",
"setup": "DATABASE_URL=${MIGRATION_DATABASE_URL:-$DATABASE_URL} prisma migrate deploy && DATABASE_URL=${MIGRATION_DATABASE_URL:-$DATABASE_URL} npm run prisma:seed",
"dev": "tsx watch src/index.ts",
"build": "tsc",
"start": "node dist/index.js"
},
"engines": {
"node": ">=24"
},
"devDependencies": {
"@types/node": "^24.19.2",
"dotenv": "^17.4.2",
"prisma": "7.10.0",
"prisma": "^7.10.1",
"tsx": "^4.23.15",
"typescript": "~6.0.2"
},
"dependencies": {
"@prisma/adapter-pg": "7.10.0",
"@prisma/client": "7.10.0"
"@prisma/client": "^7.10.1"
}
}
8 changes: 8 additions & 0 deletions docs/AI_USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@
its own issue. Claude made the changes, checked the query plans with
`EXPLAIN ANALYZE`, added tests for each point and updated the docs.

## Database Infrastructure & Setup Completion (`backend/package.json`, `backend/.env.example`, `docs/VM_SETUP.md`, `docs/AI_USAGE.md`, `src/App.tsx`)

- **Tool:** ChatGPT & Gemini
- **What the team did:** Defined the PostgreSQL 18 dual-user security model for the VM (separating `wag_migrator` schema management from `wag_app` runtime CRUD operations per `docs/API.md`), updated `backend/.env.example` and `package.json` to handle dynamic migration connection fallbacks, and resolved Vite `base: '/project2/'` asset resolution breaking SVG icons in `src/App.tsx`.
- **What the AI did:** Generated the complete VM setup guide (`docs/VM_SETUP.md`) detailing PostgreSQL 18 installation, SQL privilege configurations, and seeding verification steps. Drafted the fallback script for `backend/package.json`, updated environment templates, and refactored hardcoded SVG `/icons.svg#` links in `src/App.tsx` to dynamically import and resolve relative to Vite's base path.
- **After the review:** Verified that PostgreSQL 18, database creation, user roles, and catalog seeding were fully executed and tested on the VM. Confirmed that local dev server instructions in `README.md` correctly reflected the `/project2/` subpath.

## Tailwind design tokens (`index.html`, `src/index.css`)

- **Tool:** GitHub Copilot
Expand All @@ -221,3 +228,4 @@
Tailwind theme, and changed global heading text to the existing navy token.
- **Review:** The team reviewed the theme changes and confirmed the colors
should come from the existing CSS variables rather than new palette values.

91 changes: 91 additions & 0 deletions docs/VM_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# VM Database Setup (PostgreSQL 18)

This document describes how to set up PostgreSQL 18 on the virtual machine (VM) and configure the two database users as required by [`docs/API.md`](API.md).

---

## 1. Install PostgreSQL 18

Install PostgreSQL 18 on Ubuntu/Debian using the official PostgreSQL APT repository:

```bash
# Add official PostgreSQL APT repository
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# Update packages and install PostgreSQL 18
sudo apt-get update
sudo apt-get -y install postgresql-18
```

Verify that PostgreSQL is active:

```bash
sudo systemctl status postgresql
```

---

## 2. Configure Database & Users

Log into PostgreSQL as the superuser:

```bash
sudo -u postgres psql
```

Run the following SQL statements to create the `wag_catalog` database and set up the dual user roles (`wag_migrator` and `wag_app`):

```sql
-- Create the project database
CREATE DATABASE wag_catalog;

-- 1. Migration User (Schema owner: can create/alter tables and run migrations)
CREATE USER wag_migrator WITH PASSWORD 'YOUR_SECURE_MIGRATOR_PASSWORD';
GRANT ALL PRIVILEGES ON DATABASE wag_catalog TO wag_migrator;

-- 2. Application User (Restricted runtime access: CRUD on tables only)
CREATE USER wag_app WITH PASSWORD 'YOUR_SECURE_APP_PASSWORD';
GRANT CONNECT ON DATABASE wag_catalog TO wag_app;

-- Connect to wag_catalog to configure schema permissions
\c wag_catalog

-- Grant schema and table permissions to wag_app
GRANT USAGE ON SCHEMA public TO wag_app;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO wag_app;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO wag_app;
```

Type `\q` to exit `psql`.

---

## 3. Configure Environment Variables

Create a `backend/.env` file on the server (copied from `backend/.env.example`):

```env
# Runtime backend server connection (wag_app)
DATABASE_URL="postgresql://wag_app:YOUR_SECURE_APP_PASSWORD@localhost:5432/wag_catalog"
# Migration script connection (wag_migrator)
MIGRATION_DATABASE_URL="postgresql://wag_migrator:YOUR_SECURE_MIGRATOR_PASSWORD@localhost:5432/wag_catalog"
PORT=3001
SESSION_SECRET="your_production_session_secret"
```

---

## 4. Run Migrations & Initial Seed

Run the database setup using the migration connection string:

```bash
DATABASE_URL="postgresql://wag_migrator:YOUR_SECURE_MIGRATOR_PASSWORD@localhost:5432/wag_catalog" npm run setup
```

This command executes Prisma migrations to create all database tables and populates the database with the initial gymnastics catalog data.

_Note: The initial setup and database seeding have been successfully executed on the production VM._
Loading