Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

refactor: ♻️ developer experience #145

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
15 changes: 15 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#-----------------------------------------------------------------------------------------
# Node.js
#-----------------------------------------------------------------------------------------
NODE_ENV=development

#-----------------------------------------------------------------------------------------
# PostgresSQL database.
#-----------------------------------------------------------------------------------------
DATABASE_DIALECT=postgres
DATABASE_HOST=localhost
DATABASE_USER=postgres
DATABASE_PASSWORD=postgres
DATABASE_DATABASE=anteaterapi
DATABASE_PORT=5432
DATABASE_URL=${DATABASE_DIALECT}://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_DATABASE}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the program that's used to parse the .env file, it may or may not support variable substitution. TIL, prisma does in fact support it, which is convenient for integrating this with docker-compose. The logic being that docker-compose.yml will automatically parse the nearest .env file (also with variable substitution enabled), and thus share the identical database configuration.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ yarn-error.log*

# env
.env*
!.env.example
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Special case.


# turbo
.turbo
Expand Down
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,74 @@ Our documentation can be found [here](https://docs.icssc.club/anteaterapi).

We welcome all open-source contributions! Please start by reading the [contributing guide](CONTRIBUTING.md).

## ✅ Getting Started

### Prerequisites

Node.js environment (server-side JavaScript runtime).

- [nvm (node-version-manager)](https://github.com/nvm-sh/nvm)
- [fnm (fast-node-manager)](https://github.com/Schniz/fnm)

[pnpm - performance node package manager](https://pnpm.io/installation#using-corepack)

This can be easily enabled via corepack once a Node.js environment has been installed.

```sh
corepack enable pnpm
```

[Docker](https://docs.docker.com/compose/install/)

Docker is used to run a PostgresSQL database instance locally for development.

Other JavaScript runtimes.

- [deno](https://docs.deno.com/runtime/manual/getting_started/installation)
- [bun](https://bun.sh/docs/installation)

### Developing

1. Clone the repository and change directory.

```sh
git clone https://github.com/icssc/peterportal-api-next
cd peterportal-api-next
```

2. Create a `.env` file. To get started, cloning the `.env.example` should work for now.

```sh
cp .env.example .env
```

3. Install dependencies.

```sh
pnpm install
```

4. Start local PostgresSQL database.

```sh
docker compose up -d
```

5. Push database schema.

```sh
pnpm db:push
```

6. Start development server.

```sh
pnpm dev
```

Quick overview of getting started with development. Please view the official documentation for
additional details.

## ⚠️ Caveats

Please note that while our data is obtained directly from official UCI sources, such as the Catalogue, the Public Records Office, and the Registrar, this is not an official UCI tool. While we strive to keep our data as accurate as possible with the limited support we have from the University, errors can and do happen; please take this into consideration when using this API.
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3.9"

services:
db:
build:
context: libs/db
dockerfile: Dockerfile
ports:
- ${DATABASE_PORT}:${DATABASE_PORT}
environment:
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_DB: ${DATABASE_DATABASE}
2 changes: 2 additions & 0 deletions libs/db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM postgres:latest
COPY db.sql.gz /docker-entrypoint-initdb.d/db.sql.gz
Binary file added libs/db/db.sql.gz
Binary file not shown.
3 changes: 2 additions & 1 deletion libs/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"main": "index.ts",
"types": "index.ts",
"scripts": {
"db:push": "prisma db push",
"db:push": "dotenv -e ../../.env prisma db push",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open issue with prisma and monorepo tech: prisma/prisma#12535

TLDR: they still haven't really optimized the combination.

"generate": "prisma generate",
"postinstall": "prisma generate",
"migrate:dev": "dotenv -e ../../.env.development -- prisma migrate dev",
Expand All @@ -20,6 +20,7 @@
"@prisma/client": "5.10.2"
},
"devDependencies": {
"dotenv-cli": "7.3.0",
"prisma": "5.10.2"
}
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build": "turbo run build",
"ci:tsc": "npx tsc -p . --noEmit",
"commit": "cz",
"db:push": "turbo run db:push",
"deploy": "turbo run deploy",
"destroy": "turbo run destroy",
"dev": "dotenv -c development -- turbo run dev",
Expand Down Expand Up @@ -45,6 +46,9 @@
"typescript": "5.3.3",
"unconfig": "0.3.11"
},
"devDependencies": {
"dotenv-cli": "7.3.0"
},
"packageManager": "[email protected]",
"engines": {
"pnpm": "8"
Expand Down
Loading
Loading