Skip to content

Commit ac97c4f

Browse files
committed
a bit of doc
1 parent 6ec5083 commit ac97c4f

File tree

1 file changed

+56
-37
lines changed

1 file changed

+56
-37
lines changed

README.md

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,48 @@
22

33
Simple backend expense tracker (personal experiment)
44

5+
- [ExpenseTracker](#expensetracker)
6+
- [Contributing](#contributing)
7+
- [Configuring environment variables](#configuring-environment-variables)
8+
- [Starting services](#starting-services)
9+
- [Migrating changes made to the database](#migrating-changes-made-to-the-database)
10+
- [Important notes about containers](#important-notes-about-containers)
11+
- [Generate a migration script](#generate-a-migration-script)
12+
- [Apply the migration script to the database](#apply-the-migration-script-to-the-database)
13+
- [Rollback if needed](#rollback-if-needed)
14+
- [Check the current version of the database schema](#check-the-current-version-of-the-database-schema)
15+
- [Common Debug](#common-debug)
16+
- [Check that your host machine has access to the api hosted in a container](#check-that-your-host-machine-has-access-to-the-api-hosted-in-a-container)
17+
- [Check that your container has access to the the api hosted locally](#check-that-your-container-has-access-to-the-the-api-hosted-locally)
18+
- [Check that alembic is up](#check-that-alembic-is-up)
19+
520
## Contributing
621

7-
### Configure environment variables
22+
### Configuring environment variables
823

924
In order to run properly and run safe, the code needs multiple environment variables.
1025

1126
A `.env` file must be created at the root of the project to load secrets to memory.
1227

1328
Here is an exhaustive list of variables that must be defined:
1429

15-
- DB_HOST (db, docker-compose container name)
16-
- DB_PORT (often 5432 for postgres)
17-
- DB_USER
18-
- DB_PASSWORD
30+
- DB_HOST: db (docker-compose container name)
31+
- DB_PORT: 5432
32+
- DB_USER (ex. postgres)
33+
- DB_PASSWORD (ex. postgres)
1934
- DB_NAME: expense_db
2035

2136
These environment variables are used:
2237

2338
- to define alembic `sqlalchemy.url` privately
2439
- to define sql engine in `app.core.database`: `engine = create_engine(DATABASE_URL)`
2540

26-
> [!CAUTION]
27-
> Do not version your `.env` file.
41+
### Starting services
2842

29-
## Common Debug
30-
31-
### Check that your host machine has access to the api hosted in a container
32-
33-
Outside Docker (on your host machine): The correct way to access the service is:
34-
35-
- `http://localhost:8000`
36-
- `http://127.0.0.1:8000`
43+
To start database and api services, use:
3744

3845
```shell
39-
curl -v http://localhost:8000/docs
40-
```
41-
42-
### Check that your container has access to the the api hosted locally
43-
44-
Inside Docker: FastAPI binds to `0.0.0.0`, allowing access from anywhere inside the container.
45-
46-
```shell
47-
docker exec -it fastapi_expense_backend sh
48-
```
49-
50-
then in the opened container shell:
51-
52-
```shell
53-
curl -v http://0.0.0.0:8000/docs
54-
```
55-
56-
### Check that alembic is up
57-
58-
```shell
59-
docker exec -it fastapi_expense_backend alembic current
46+
docker compose up -d
6047
```
6148

6249
### Migrating changes made to the database
@@ -76,7 +63,6 @@ docker exec -it fastapi_expense_backend sh
7663
> This error is due to the fact that db is the name of the docker-compose service and also the host name.
7764
> What would work is: "localhost" instead of "db", however the backend container would not be able to connect to the database url.
7865
79-
8066
#### Generate a migration script
8167

8268
After making changes to your database models (schemas), you need to generate a migration script.
@@ -144,3 +130,36 @@ INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
144130
INFO [alembic.runtime.migration] Will assume transactional DDL.
145131
08290ef9350a (head)
146132
```
133+
134+
## Common Debug
135+
136+
### Check that your host machine has access to the api hosted in a container
137+
138+
Outside Docker (on your host machine): The correct way to access the service is:
139+
140+
- `http://localhost:8000`
141+
- `http://127.0.0.1:8000`
142+
143+
```shell
144+
curl -v http://localhost:8000/docs
145+
```
146+
147+
### Check that your container has access to the the api hosted locally
148+
149+
Inside Docker: FastAPI binds to `0.0.0.0`, allowing access from anywhere inside the container.
150+
151+
```shell
152+
docker exec -it fastapi_expense_backend sh
153+
```
154+
155+
then in the opened container shell:
156+
157+
```shell
158+
curl -v http://0.0.0.0:8000/docs
159+
```
160+
161+
### Check that alembic is up
162+
163+
```shell
164+
docker exec -it fastapi_expense_backend alembic current
165+
```

0 commit comments

Comments
 (0)