refactor(server): make redis required module (#9121)

This commit is contained in:
forehalo
2024-12-13 06:27:15 +00:00
parent 81c68032e1
commit 0e73737407
40 changed files with 292 additions and 728 deletions

View File

@@ -5,81 +5,13 @@ This document explains how to start server (@affine/server) locally with Docker
> This document is not guaranteed to be up-to-date.
> If you find any outdated information, please feel free to open an issue or submit a PR.
## Run postgresql in docker
## Run required dev services in docker compose
```
docker pull postgres
docker run --rm --name affine-postgres -e POSTGRES_PASSWORD=affine -p 5432:5432 -v ~/Documents/postgres:/var/lib/postgresql/data postgres
```
cp ./.docker/dev/compose.yml.example ./.docker/dev/compose.yml
cp ./.docker/dev/.env.example ./.docker/dev/.env
### Optionally, use a dedicated volume
```
docker volume create affine-postgres
docker run --rm --name affine-postgres -e POSTGRES_PASSWORD=affine -p 5432:5432 -v affine-postgres:/var/lib/postgresql/data postgres
```
### mailhog (for local testing)
```
docker run --rm --name mailhog -p 1025:1025 -p 8025:8025 mailhog/mailhog
```
## prepare db
```
docker ps
docker exec -it affine-postgres psql -U postgres ## `affine-postgres` is the container name from the previous step
```
### in the terminal, following the example to user & table
```
psql (15.3 (Debian 15.3-1.pgdg120+1))
Type "help" for help.
postgres=# CREATE USER affine WITH PASSWORD 'affine';
CREATE ROLE
postgres=# ALTER USER affine WITH SUPERUSER;
ALTER ROLE
postgres=# CREATE DATABASE affine;
CREATE DATABASE
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
affine | Superuser | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
```
### Set the following config to `packages/backend/server/.env`
In the following setup, we assume you have postgres server running at localhost:5432 and mailhog running at localhost:1025.
When logging in via email, you will see the mail arriving at localhost:8025 in a browser.
```
DATABASE_URL="postgresql://affine:affine@localhost:5432/affine"
MAILER_SENDER="noreply@toeverything.info"
MAILER_USER="auth"
MAILER_PASSWORD="auth"
MAILER_HOST="localhost"
MAILER_PORT="1025"
```
## Prepare prisma
```
yarn workspace @affine/server prisma db push
yarn workspace @affine/server data-migration run
```
Note, you may need to do it again if db schema changed.
### Enable prisma studio
```
yarn workspace @affine/server prisma studio
docker compose -f ./.docker/dev/compose.yml up -d
```
## Build native packages (you need to setup rust toolchain first)
@@ -87,27 +19,46 @@ yarn workspace @affine/server prisma studio
```
# build native
yarn workspace @affine/server-native build
yarn workspace @affine/native build
```
## start server
## Prepare dev environment
```
yarn workspace @affine/server dev
cd packages/backend/server
cp .env.example .env
yarn prisma db push
yarn data-migration run
```
when server started, it will created a default user:
email: dev@affine.pro
name: Dev User
password: dev
## start core (web)
## Start server
```
yarn dev
```
when server started, it will created a default user for testing:
- email: dev@affine.pro
- name: Dev User
- password: dev
## Start frontend
```
# at project root
yarn dev
```
## Done
Now you should be able to start developing affine with server enabled.
## Bonus
### Enable prisma studio (Database GUI)
```
# available at http://localhost:5555
yarn prisma studio
```