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
During development, you can change Docker Compose settings that will only affect the local development environment in the file `docker-compose.override.yml`.
@@ -46,21 +52,21 @@ For example, the directory with the backend code is synchronized in the Docker c
46
52
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
53
48
54
```console
49
-
$ docker compose watch
55
+
docker compose watch
50
56
```
51
57
52
58
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
59
54
60
To get inside the container with a `bash` session you can start the stack with:
55
61
56
62
```console
57
-
$ docker compose watch
63
+
docker compose watch
58
64
```
59
65
60
66
and then in another terminal, `exec` inside the running container:
61
67
62
68
```console
63
-
$ docker compose exec backend bash
69
+
docker compose exec backend bash
64
70
```
65
71
66
72
You should see an output like:
@@ -74,7 +80,7 @@ that means that you are in a `bash` session inside your container, as a `root` u
74
80
There you can use the `fastapi run --reload` command to run the debug live reloading server.
75
81
76
82
```console
77
-
$ fastapi run --reload app/main.py
83
+
fastapi run --reload app/main.py
78
84
```
79
85
80
86
...it will look like:
@@ -94,7 +100,7 @@ Nevertheless, if it doesn't detect a change but a syntax error, it will just sto
94
100
To test the backend run:
95
101
96
102
```console
97
-
$ bash ./scripts/test.sh
103
+
bash ./scripts/test.sh
98
104
```
99
105
100
106
The tests run with Pytest, modify and add tests to `./backend/app/tests/`.
@@ -130,23 +136,23 @@ Make sure you create a "revision" of your models and that you "upgrade" your dat
130
136
* Start an interactive session in the backend container:
131
137
132
138
```console
133
-
$ docker compose exec backend bash
139
+
docker compose exec backend bash
134
140
```
135
141
136
142
* Alembic is already configured to import your SQLModel models from `./backend/app/models.py`.
137
143
138
144
* After changing a model (for example, adding a column), inside the container, create a revision, e.g.:
139
145
140
146
```console
141
-
$ alembic revision --autogenerate -m "Add column last_name to User model"
147
+
alembic revision --autogenerate -m "Add column last_name to User model"
142
148
```
143
149
144
150
* Commit to the git repository the files generated in the alembic directory.
145
151
146
152
* After creating the revision, run the migration in the database (this is what will actually change the database):
147
153
148
154
```console
149
-
$ alembic upgrade head
155
+
alembic upgrade head
150
156
```
151
157
152
158
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:
159
165
160
166
```console
161
-
$ alembic upgrade head
167
+
alembic upgrade head
162
168
```
163
169
164
170
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