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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DATABASE_URL=postgresql://t31_dev:change-me@127.0.0.1:5432/t31_project2
API_HOST=127.0.0.1
API_PORT=3001
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI
on:
pull_request:
push:
branches: [main]
jobs:
quality:
runs-on: [self-hosted, linux, x64, t31-project2-ci]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version-file: .node-version, cache: npm }
- run: npm ci
- name: Verify generated GraphQL types
run: npm run types:check
- name: Verify database migrations
run: npm run db:check
- name: Lint, typecheck, test and build
run: npm run check
- run: npx playwright install chromium
- run: npm run test:e2e
- name: Save tested release
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v3.2.1-node20
with:
name: project2-${{ github.sha }}-${{ github.run_attempt }}
path: |
apps/api/dist
apps/api/migrations
apps/api/package.json
apps/web/dist
apps/web/package.json
package.json
package-lock.json
deploy:
needs: quality
if: github.ref == 'refs/heads/main'
runs-on: [self-hosted, linux, x64, t31-project2-deploy]
environment:
name: production
url: http://it2810-31.idi.ntnu.no/project2/
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3-node20
with:
name: project2-${{ github.sha }}-${{ github.run_attempt }}
path: release
- name: Install production dependencies
run: cd release && npm ci --omit=dev
- name: Apply database migrations
run: cd release && node --env-file=/etc/t31-project2.env apps/api/dist/db/migrate.js
- name: Publish and restart the API service
run: bash scripts/deploy.sh release "$GITHUB_SHA-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT"
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
dist/
.env
coverage/
playwright-report/
test-results/
*.tsbuildinfo
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24.21.0
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
engine-strict=true
save-exact=true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24.21.0
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "singleQuote": true }
28 changes: 9 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
# T31-Project-2
# T31 Project 2

Repository for team IT2810-H26-T31 in IT2810-H26.

## Working in this repository

`main` is protected — you cannot push to it directly. Work on a branch and
open a pull request:
## Dev tips

```bash
git checkout -b my-feature
git push -u origin my-feature
nvm use
npm ci
cp .env.example .env
npm run dev
```

Before a pull request can be merged:

1. **A member of IT2810-H26-T31 must approve it.** You cannot approve your own pull
request, and approvals from staff do not count — you review each other's
code.
2. **Every review comment must be marked resolved.** Reply to each one, fix it
or explain why not, then click *Resolve conversation*.
3. **Pushing new commits dismisses the approval**, so if you change something
after being approved, ask for another review. This is deliberate: what was
approved is what gets merged.
- Web: `http://localhost:5173/project2/`
- GraphQL: `http://localhost:3001/graphql`
- Before pushing: `npm run check`
7 changes: 7 additions & 0 deletions apps/api/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
dialect: 'postgresql',
schema: 'apps/api/src/db/schema.ts',
out: 'apps/api/migrations',
});
1 change: 1 addition & 0 deletions apps/api/migrations/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 4 additions & 0 deletions apps/api/migrations/0000_glorious_squadron_sinister.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE "project2"."recipes" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"title" text NOT NULL
);
45 changes: 45 additions & 0 deletions apps/api/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"id": "fa9889d1-8b19-437d-8360-333cd24d5aea",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
"project2.recipes": {
"name": "recipes",
"schema": "project2",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
13 changes: 13 additions & 0 deletions apps/api/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1790582041612,
"tag": "0000_glorious_squadron_sinister",
"breakpoints": true
}
]
}
20 changes: 20 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@t31/api",
"private": true,
"type": "module",
"scripts": {
"dev": "tsx --env-file-if-exists=../../.env watch src/server.ts",
"build": "tsc && cp src/schema.graphql dist/schema.graphql",
"start": "node --env-file-if-exists=../../.env dist/server.js"
},
"dependencies": {
"drizzle-orm": "0.45.2",
"graphql": "16.12.0",
"graphql-yoga": "5.16.2",
"pg": "8.16.3"
},
"devDependencies": {
"@types/pg": "8.15.6",
"tsx": "4.20.6"
}
}
14 changes: 14 additions & 0 deletions apps/api/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { readFileSync } from 'node:fs';
import { createSchema, createYoga } from 'graphql-yoga';
import type { Resolvers } from './generated.js';

export const app = createYoga({
schema: createSchema({
typeDefs: readFileSync(
new URL('./schema.graphql', import.meta.url),
'utf8',
),
resolvers: { Query: { health: () => 'ok' } } satisfies Resolvers,
}),
graphqlEndpoint: '/graphql',
});
3 changes: 3 additions & 0 deletions apps/api/src/db/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Pool } from 'pg';

export const db = new Pool({ connectionString: process.env.DATABASE_URL });
6 changes: 6 additions & 0 deletions apps/api/src/db/migrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { drizzle } from 'drizzle-orm/node-postgres';
import { migrate } from 'drizzle-orm/node-postgres/migrator';
import { db } from './client.js';

await migrate(drizzle(db), { migrationsFolder: 'apps/api/migrations' });
await db.end();
8 changes: 8 additions & 0 deletions apps/api/src/db/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { pgSchema, text, uuid } from 'drizzle-orm/pg-core';

const project2 = pgSchema('project2');

export const recipes = project2.table('recipes', {
id: uuid().primaryKey().defaultRandom(),
title: text().notNull(),
});
Loading