Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/webmasterdevlin/fastapi-backend

FastAPI backend for my react-vite-frontend repo
https://github.com/webmasterdevlin/fastapi-backend

azure-ad dockerfile entra-id fastapi

Last synced: 1 day ago
JSON representation

FastAPI backend for my react-vite-frontend repo

Awesome Lists containing this project

README

        

## Docker

- local containerization
```zsh
docker build -t webmasterdevlin/fastapi: .
```

- local deployment
```zsh
docker run -p 8000:80 webmasterdevlin/fastapi:
```

- push the container to your Docker Hub account repository
```zsh
docker push webmasterdevlin/react-vite:
```

#### Test Coverage

When the tests are run, a file `htmlcov/index.html` is generated, you can open it in your browser to see the coverage of the tests.

### Migrations

As during local development your app directory is mounted as a volume inside the container, you can also run the migrations with `alembic` commands inside the container and the migration code will be in your app directory (instead of being only inside the container). So you can add it to your git repository.

Make sure you create a "revision" of your models and that you "upgrade" your database with that revision every time you change them. As this is what will update the tables in your database. Otherwise, your application will have errors.

* Start an interactive session in the backend container:

```console
$ docker compose exec backend bash
```

* Alembic is already configured to import your SQLModel models from `./backend/app/models.py`.

* After changing a model (for example, adding a column), inside the container, create a revision, e.g.:

```console
$ alembic upgrade head
$ alembic revision --autogenerate -m "Add column last_name to User model"
```

* Commit to the git repository the files generated in the alembic directory.

* After creating the revision, run the migration in the database (this is what will actually change the database):

```console
$ alembic upgrade head
```

If you don't want to use migrations at all, uncomment the lines in the file at `./src/app/helpers/db.py` that end in:

```python
SQLModel.metadata.create_all(engine)
```

and comment the line in the file `prestart.sh` that contains:

```console
$ alembic upgrade head
```

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 `./src/app/alembic/versions/`. And then create a first migration as described above.