Skip to content

Commit 361d122

Browse files
committed
[PEER-118][PEER-256] Add Matching Svc, Dockerize Collab Svc
Signed-off-by: SeeuSim <[email protected]>
1 parent 4824c96 commit 361d122

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+328
-529
lines changed

.env.local

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
1-
USER_PGDATA="/data/user-db"
2-
USER_EXPRESS_DB_PORT=5431
3-
4-
QUESTION_PGDATA="/data/qn-db"
5-
QUESTION_EXPRESS_DB_PORT=5433
6-
7-
COLLAB_PGDATA="/data/collab-db"
8-
COLLAB_EXPRESS_DB_PORT=5434
9-
10-
MATCHING_PGDATA="/data/collab-db"
11-
MATCHING_EXPRESS_DB_PORT=5434
12-
131
USER_SERVICE_NAME=user-express
2+
USER_EXPRESS_DB_PORT=5431
143
USER_EXPRESS_ENV=compose
154
USER_EXPRESS_PORT=9001
5+
USER_PGDATA="/data/user-db"
166

177
QUESTION_SERVICE_NAME=question-express
18-
QUESTION_EXPRESS_ENV=compose
198
QUESTION_EXPRESS_PORT=9002
9+
QUESTION_EXPRESS_ENV=compose
10+
QUESTION_EXPRESS_DB_PORT=5433
11+
QUESTION_PGDATA="/data/qn-db"
2012

21-
COLLAB_CONTAINER_NAME=collab-express
13+
COLLAB_SERVICE_NAME=collab-express
2214
COLLAB_EXPRESS_ENV=compose
2315
COLLAB_EXPRESS_PORT=9003
2416

17+
MATCHING_SERVICE_NAME=match-express
2518
MATCHING_EXPRESS_ENV=compose
2619
MATCHING_EXPRESS_PORT=9004
2720

21+
FRONTEND_SERVICE_NAME=frontend
2822
FRONTEND_ENV=compose
2923
FRONTEND_PORT=3000

backend/collaboration/.env.compose

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# To be injected by Docker Compose
2+
# PEERPREP_UI_HOST="http://frontend:3000"
3+
4+
EXPRESS_PORT=9003

backend/collaboration/.env.docker

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PEERPREP_UI_HOST="http://host.docker.internal:5173"
2+
3+
EXPRESS_PORT=9003

backend/collaboration/.env.local

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
EXPRESS_ENV="local"
2-
EXPRESS_DB_HOST="localhost"
3-
EXPRESS_DB_PORT=5434
4-
POSTGRES_DB="collab"
5-
POSTGRES_USER="peerprep-collab-express"
6-
POSTGRES_PASSWORD="/86awM+Izo6949YgEQIls8HU+j5RlFYEInRy8auiNa8="
7-
PGDATA="/data/collab-db"
1+
PEERPREP_UI_HOST="http://localhost:5173"
2+
3+
EXPRESS_PORT=9003

backend/collaboration/README.md

Lines changed: 1 addition & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1 @@
1-
# Template Service
2-
3-
This directory contains the code for the Template
4-
Service.
5-
6-
## Database
7-
8-
We use:
9-
10-
- PostgreSQL 16 for the database. To run it, we use:
11-
- Docker to run the database, as well as inject any user-defined
12-
configurations or SQL files into the Docker image.
13-
- Docker-Compose to run the database, as well as any other
14-
services this API microservice may depend on.
15-
- [**Drizzle**](https://orm.drizzle.team/) for the ORM.
16-
17-
Follow the instructions below for the setup, as well as to learn how to work with the database.
18-
19-
### Setup
20-
21-
1. Install Docker Desktop on your device. Launch it.
22-
23-
2. To verify that it is launched and installed correctly, run the
24-
following in your terminal:
25-
26-
```bash
27-
docker --version
28-
```
29-
30-
If the command does not error, and outputs a version, proceed to
31-
the next step.
32-
33-
3. Inspect the `docker-compose.yml` file. It
34-
should look like this:
35-
36-
```yml
37-
services:
38-
# ...
39-
postgres:
40-
# ...
41-
volumes:
42-
- "template-db-docker:/data/template-db"
43-
# - ./init.sql:/docker-entrypoint-initdb.d/init.sql
44-
ports:
45-
- "5431:5432"
46-
restart: unless-stopped
47-
48-
volumes:
49-
template-db-docker:
50-
external: true
51-
```
52-
53-
We observe that this Database relies on a
54-
Docker Volume. Replace all instances of
55-
`template-db-docker` with your desired
56-
volume name.
57-
58-
4. Then, create the Docker Volume with
59-
the following command:
60-
61-
```bash
62-
# in this case, the command is
63-
# docker volume create template-db-docker
64-
docker volume create <volume-name>
65-
```
66-
5. Finally, create the Database Container:
67-
68-
```bash
69-
docker-compose up -d
70-
```
71-
72-
6. To bring it down, run this command:
73-
74-
```bash
75-
docker-compose down
76-
```
77-
78-
### Schema
79-
80-
We maintain the schema in the `src/lib/db/schema.ts` file.
81-
82-
Refer to the Drizzle documentation to learn how
83-
to properly define schemas. Then, insert your
84-
schemas into the file.
85-
86-
### Migration
87-
88-
After you have created/updated your schemas in
89-
the file, persist them to the Database with
90-
Migrations.
91-
92-
1. Configure your credentials (port,
93-
password, ...) in:
94-
95-
- `drizzle.config.ts`
96-
- `drizzle.migrate.mts`.
97-
- `src/lib/db/index.ts`.
98-
99-
In the future, we may wish to migrate these
100-
credentials to environment variables.
101-
102-
2. Run the `npm run db:generate` command to
103-
generate your `.sql` Migration Files under the
104-
`drizzle` folder.
105-
106-
3. Rename your
107-
`<migration_num>_<random_name>.sql` file
108-
to `<migration_num>_<meaningful_name>.sql`.
109-
110-
For example:
111-
- Generated: `0000_dazzling_squirrel.sql`
112-
- Renamed: `0000_initial_schema.sql`.
113-
114-
Then, rename the
115-
`meta/_journal.json` tag from
116-
`0000_dazzling_squirrel` to
117-
`0000_initial_schema` as well. Replace the
118-
migration number and name with the one you
119-
used.
120-
121-
4. Finally, run the migration with this:
122-
123-
```bash
124-
npm run db:migrate
125-
```
126-
127-
### Connecting with the DB
128-
129-
1. Import the `db` instance from `lib/db`.
130-
2. Use the Drizzle APIs and the tables defined in
131-
`src/lib/schema.ts` to interact with the
132-
tables.
133-
134-
```ts
135-
import { db, tableName } from '../lib/db';
136-
137-
const route = async (req, res) => {
138-
await db.select().from(tableName); //...
139-
}
140-
```
1+
# Collaboration Service

backend/collaboration/docker-compose.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

backend/collaboration/drizzle.config.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

backend/collaboration/drizzle/0000_initial_schema.sql

Lines changed: 0 additions & 4 deletions
This file was deleted.

backend/collaboration/drizzle/meta/0000_snapshot.json

Lines changed: 0 additions & 41 deletions
This file was deleted.

backend/collaboration/drizzle/meta/_journal.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)