You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: backend/README.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,13 +16,13 @@ By default, the dependencies are managed with [uv](https://docs.astral.sh/uv/),
16
16
From `./backend/` you can install all the dependencies with:
17
17
18
18
```console
19
-
$ uv sync
19
+
uv sync
20
20
```
21
21
22
22
Then you can activate the virtual environment with:
23
23
24
24
```console
25
-
$ source .venv/bin/activate
25
+
source .venv/bin/activate
26
26
```
27
27
28
28
Make sure your editor is using the correct Python virtual environment, with the interpreter at `backend/.venv/bin/python`.
@@ -46,21 +46,21 @@ For example, the directory with the backend code is synchronized in the Docker c
46
46
There is also a command override that runs `fastapi run --reload` instead of the default `fastapi run`. It starts a single server process (instead of multiple, as would be for production) and reloads the process whenever the code changes. Have in mind that if you have a syntax error and save the Python file, it will break and exit, and the container will stop. After that, you can restart the container by fixing the error and running again:
47
47
48
48
```console
49
-
$ docker compose watch
49
+
docker compose watch
50
50
```
51
51
52
52
There is also a commented out `command` override, you can uncomment it and comment the default one. It makes the backend container run a process that does "nothing", but keeps the container alive. That allows you to get inside your running container and execute commands inside, for example a Python interpreter to test installed dependencies, or start the development server that reloads when it detects changes.
53
53
54
54
To get inside the container with a `bash` session you can start the stack with:
55
55
56
56
```console
57
-
$ docker compose watch
57
+
docker compose watch
58
58
```
59
59
60
60
and then in another terminal, `exec` inside the running container:
61
61
62
62
```console
63
-
$ docker compose exec backend bash
63
+
docker compose exec backend bash
64
64
```
65
65
66
66
You should see an output like:
@@ -74,7 +74,7 @@ that means that you are in a `bash` session inside your container, as a `root` u
74
74
There you can use the `fastapi run --reload` command to run the debug live reloading server.
75
75
76
76
```console
77
-
$ fastapi run --reload app/main.py
77
+
fastapi run --reload app/main.py
78
78
```
79
79
80
80
...it will look like:
@@ -94,7 +94,7 @@ Nevertheless, if it doesn't detect a change but a syntax error, it will just sto
94
94
To test the backend run:
95
95
96
96
```console
97
-
$ bash ./scripts/test.sh
97
+
bash ./scripts/test.sh
98
98
```
99
99
100
100
The tests run with Pytest, modify and add tests to `./backend/tests/`.
@@ -134,55 +134,55 @@ From the `./backend/` directory, you can run Alembic commands using `uv run`:
134
134
* Apply all pending migrations:
135
135
136
136
```console
137
-
$ uv run alembic upgrade head
137
+
uv run alembic upgrade head
138
138
```
139
139
140
140
* Create a new migration after changing models:
141
141
142
142
```console
143
-
$ uv run alembic revision --autogenerate -m "Add column last_name to User model"
143
+
uv run alembic revision --autogenerate -m "Add column last_name to User model"
144
144
```
145
145
146
146
* View migration history:
147
147
148
148
```console
149
-
$ uv run alembic history
149
+
uv run alembic history
150
150
```
151
151
152
152
* Check current database revision:
153
153
154
154
```console
155
-
$ uv run alembic current
155
+
uv run alembic current
156
156
```
157
157
158
158
* Rollback the last migration:
159
159
160
160
```console
161
-
$ uv run alembic downgrade -1
161
+
uv run alembic downgrade -1
162
162
```
163
163
164
164
### Running Migrations with Docker
165
165
166
166
* Start an interactive session in the backend container:
167
167
168
168
```console
169
-
$ docker compose exec backend bash
169
+
docker compose exec backend bash
170
170
```
171
171
172
172
* Alembic is already configured to import your SQLModel models from `./backend/app/models.py`.
173
173
174
174
* After changing a model (for example, adding a column), inside the container, create a revision, e.g.:
175
175
176
176
```console
177
-
$ alembic revision --autogenerate -m "Add column last_name to User model"
177
+
alembic revision --autogenerate -m "Add column last_name to User model"
178
178
```
179
179
180
180
* Commit to the git repository the files generated in the alembic directory.
181
181
182
182
* After creating the revision, run the migration in the database (this is what will actually change the database):
183
183
184
184
```console
185
-
$ alembic upgrade head
185
+
alembic upgrade head
186
186
```
187
187
188
188
If you don't want to use migrations at all, uncomment the lines in the file at `./backend/app/core/db.py` that end in:
and comment the line in the file `scripts/prestart.sh` that contains:
195
195
196
196
```console
197
-
$ alembic upgrade head
197
+
alembic upgrade head
198
198
```
199
199
200
200
If you don't want to start with the default models and want to remove them / modify them, from the beginning, without having any previous revision, you can remove the revision files (`.py` Python files) under `./backend/app/alembic/versions/`. And then create a first migration as described above.
0 commit comments