Skip to content

Commit

Permalink
Backend content to README
Browse files Browse the repository at this point in the history
  • Loading branch information
mslwang committed Oct 8, 2024
1 parent 7085f05 commit 865f46c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,17 @@ git push -f
- PRs can contain multiple commits, they do not need to be squashed together before merging as long as each commit is atomic. Our repo is configured to only allow squash commits to `main` so the entire PR will appear as 1 commit on `main`, but the individual commits are preserved when viewing the PR.

## Secrets
Secrets are stored in the Environment Variable [file](https://www.notion.so/uwblueprintexecs/Environment-Variables-11910f3fb1dc80e4bc67d35c3d65d073?pvs=4) within the LLSC notion.
Secrets are stored in the Environment Variable [file](https://www.notion.so/uwblueprintexecs/Environment-Variables-11910f3fb1dc80e4bc67d35c3d65d073?pvs=4) within the LLSC notion.

## Migrations (mirrors [backend README](./backend/README.md))

We use Alembic for database schema migrations. We mainly use migration scripts to keep track of the incremental and in theory revertible changes that have occurred on the database. But, we don't need to rely on this to build the datebase itself, as `Base.metadata.create_all(bind=engine)` achieves that based on the current models. To create a new migration, run the following command after adding or editing models in `backend/app/models.py`:
```bash
cd backend
pdm run alembic revision --autogenerate -m "<migration message>"
```

To apply the migration, run the following command:
```bash
pdm run alembic upgrade head
```
59 changes: 59 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,60 @@
# llsc-backend

## Setup (mirrors [base README](../README.md#setup))
- Install pdm (this is a global installation, so location doesn't matter)
On macOS:
```bash
brew install pdm
```
Otherwise, feel free to follow install instructions [here](https://pdm-project.org/latest/#installation)

You will then need to go into each directory individually to install dependencies.

FastAPI backend
```bash
cd backend
pdm install
```

To run the backend server locally (recommended for development), run the following command:
```bash
cd backend
pdm run dev
```

To check if the database has been started up, type the following:
```bash
docker ps | grep llsc_db
```
This checks the list of docker containers and searchs for the container name `llsc_db`


## Formatting and Linting (mirrors [formatting in base README](../README.md#formatting-and-linting))

### Ruff

We use Ruff for code linting and formatting in the backend. To check for and automatically fix linting issues:

```bash
cd backend
pdm run ruff check --fix .
```

To format the code:
```bash
cd backend
pdm run ruff format .
```

## Migrations

We use Alembic for database schema migrations. We mainly use migration scripts to keep track of the incremental and in theory revertible changes that have occurred on the database. But, we don't need to rely on this to build the datebase itself, as `Base.metadata.create_all(bind=engine)` achieves that based on the current models. To create a new migration, run the following command after adding or editing models in `backend/app/models.py`:
```bash
cd backend
pdm run alembic revision --autogenerate -m "<migration message>"
```

To apply the migration, run the following command:
```bash
pdm run alembic upgrade head
```

0 comments on commit 865f46c

Please sign in to comment.