Skip to content

Conversation

ronjalh
Copy link
Member

@ronjalh ronjalh commented Oct 16, 2026

Summary

Xenia's work on #26 ("Set up the database on the VM"), opened as a pull request so it can be reviewed. It prepares the backend for the virtual machine. It is a first step, and it does not yet do everything that #26 asks for (see "Not in this PR").

What is in it

  • backend/src/index.ts: a first entry point for the server (Apollo Server standalone), which loads src/schema.graphql and connects to the database with the existing Prisma client.
  • backend/src/resolvers.ts: a resolver for searchCatalog that calls the search function from backend/src/catalog/search.ts.
  • backend/package.json: new scripts setup (prisma migrate deploy and then the seed), dev, build and start, and Prisma moved to ^7.10.1.
  • Root package.json: the server packages (@apollo/server, graphql, pg, dotenv, tsx, @prisma/client, prisma and some types) are added at the root.
  • vite.config.ts: base: '/project2/', because the app is served by Apache under /project2 on the virtual machine.

Not in this PR (still open in #26)

  • Steps for installing PostgreSQL on the VM from the official repository, in the same major version as locally (18).
  • A database user and a database for the project on the VM. docs/API.md describes two users there: one that the backend uses (reads and writes the tables, cannot create users or databases) and one for the migrations.
  • A description that lets the course staff repeat the setup, and a record that the migrations and the seed have been run on the VM.

Notes for review

I have only read this branch, not run it. These are things to check:

  • Overlap with feat: add the GraphQL server with the catalog queries #65, which adds the GraphQL server (backend/src/server.ts, backend/src/server/) with the catalog resolvers, DataLoader, the error handling and the settings. This PR has a second entry point (index.ts) and a second set of resolvers. Only one of the two should be the server.
  • searchCatalog returns catalog entries, but the schema says node: CatalogItem (an interface that is resolved to Element or Vault). The resolver here does not resolve the interface, so a query for node { ... } may fail. feat: add the GraphQL server with the catalog queries #65 has this.
  • build and start: backend/tsconfig.json has noEmit: true, so tsc does not write dist/, and start runs node dist/index.js. Running tsx (as in dev) works without a build.
  • Port: index.ts defaults to 4000, while the backend should be on 3001 on the VM.
  • Paths: index.ts reads src/schema.graphql from the current folder, so it only works when started from backend/.
  • Packages at the root: the workspace has its own backend/package.json, so the server packages may belong there.
  • The setup script runs the migrations and the seed with one DATABASE_URL. With two users on the VM (see above), the migration user is the one that must run it.

Part of #26

🤖 Generated with Claude Code

@ronjalh ronjalh requested a review from a team as a code owner October 16, 2026 16:37
@ronjalh ronjalh assigned ronjalh and xeniag and unassigned ronjalh Oct 16, 2026
ronjalh pushed a commit that referenced this pull request Oct 16, 2026
Keeps the work of #66 (the setup script, the build and start scripts, Prisma 7.10.1, base /project2/ in Vite). The server entry point is now backend/src/index.ts, which replaces the first version, and the resolvers of the first version are replaced by backend/src/server/resolvers/. start runs tsx, because there is no dist/.
@ronjalh
Copy link
Member Author

ronjalh commented Oct 16, 2026 •

@xeniag Thanks for starting on this. I ran the branch against a fresh PostgreSQL 18 with the seeded catalog. npm run setup works (it creates the tables and seeds an empty database), lint, typecheck and the tests pass, and base: '/project2/' is right for Apache. This is what is left to do for #26:

  • High: What Set up the database on the VM #26 asks for is not in the PR yet: PostgreSQL 18 from the official repository on the VM, a database user and a database, steps the course staff can repeat, and a note that the migrations and the seed have run on the VM. docs/API.md describes two database users on the VM (one for the server that cannot create tables, one for the migrations), but setup uses one DATABASE_URL.
  • Med: src/App.tsx uses /icons.svg#… (six places), which base: '/project2/' does not rewrite, so the icons break. The README still says the dev server is at http://localhost:5173; it is now under /project2/.
  • Med: docs/AI_USAGE.md has no entry for this work, and npm audit reports 8 high-severity vulnerabilities (not checked whether they come from the new packages).
  • Low: The files use semicolons and double quotes where the repo uses Prettier (no semicolons, single quotes).

The problems I found in the server (search results that cannot be read, totalCount, start, errors and CORS, the port and the package versions) are fixed in #65, which is built on this branch, so you do not need to do them. #65 replaces index.ts and resolvers.ts with the full server, and keeps setup, base: '/project2/' and the Prisma bump.

The VM instructions are the main part that is still missing. Do you want to take them, or should someone else?

Comment made with Claude Code in discussion with Ronja

@xeniag
Copy link
Member

xeniag commented Oct 17, 2026

VM PostgreSQL 18 Setup

  1. Installed PostgreSQL 18 from the official APT repository on the VM.
  2. Configured database wag_catalog and created the dual roles as required by docs/API.md:
    • wag_migrator: Migration owner for running Prisma schema migrations and seeding.
    • wag_app: Restricted application user (SELECT, INSERT, UPDATE, DELETE).
  3. Ran npm run setup with wag_migrator to create tables and execute seed scripts on the VM.

@xeniag
Copy link
Member

xeniag commented Oct 17, 2026

Summary of Changes & Review Fixes (#26)

This PR addresses all outstanding setup and configuration requirements for database infrastructure, deployment path alignment, and code cleanups:

1. VM Database Setup & Dual-User Security Model

  • Installed PostgreSQL 18 on the VM via official repositories.
  • Provisioned the wag_catalog database along with dual roles per docs/API.md:
    • wag_migrator: Schema owner with full migration permissions.
    • wag_app: Restricted runtime user with CRUD permissions on schema tables.
  • Executed Prisma migrations and seeded the catalog on the production VM.
  • Documented the complete step-by-step installation and role configuration in docs/VM_SETUP.md.

2. Configuration & Environment Updates

  • Updated backend/.env.example to document both DATABASE_URL (runtime) and MIGRATION_DATABASE_URL (migrations).
  • Refactored backend/package.json setup scripts to automatically fall back to MIGRATION_DATABASE_URL when executing migrations and seeding.
  • Updated README.md to reflect the correct local development server URL (http://localhost:5173/project2/).

3. Asset Path Fixes & Code Cleanup

  • Refactored SVG icon references in src/App.tsx to use Vite's BASE_URL (import.meta.env.BASE_URL), preventing broken asset paths caused by base: '/project2/'.
  • Cleaned up boilerplate code in src/App.tsx and ran Prettier formatting across modified repository files.
  • Logged all AI tool usage details for this iteration in docs/AI_USAGE.md.

@xeniag xeniag merged commit 07e4c57 into dev Oct 20, 2026
@xeniag xeniag deleted the 26-set-up-the-database-on-the-vm branch October 20, 2026 17:41
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants