Skip to content

Implement fixtures support #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exclude_patterns:
- "spec/"
- "!spec/support/helpers"
- "config/"
- "src/alembic/"
- "src/migrations/"
- "db/"
- "dist/"
- "features/"
Expand Down
2 changes: 1 addition & 1 deletion .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ RUN --mount=type=cache,target=~/.cache/uv \
# Create the base app with the common python packages
FROM base AS base_app
USER nonroot
COPY --chown=nonroot:nonroot src/alembic ./alembic
COPY --chown=nonroot:nonroot src/migrations ./migrations
COPY --chown=nonroot:nonroot src/domains ./domains
COPY --chown=nonroot:nonroot src/gateways ./gateways
COPY --chown=nonroot:nonroot src/common ./common
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ This template provides out of the box some commonly used functionalities:
* Async tasks execution using [Dramatiq](https://dramatiq.io/index.html)
* Repository pattern for databases using [SQLAlchemy](https://www.sqlalchemy.org/) and [SQLAlchemy bind manager](https://febus982.github.io/sqlalchemy-bind-manager/stable/)
* Database migrations using [Alembic](https://alembic.sqlalchemy.org/en/latest/) (configured supporting both sync and async SQLAlchemy engines)
* Database fixtures support using customized [Alembic](https://alembic.sqlalchemy.org/en/latest/) configuration
* Authentication and Identity Provider using [ORY Zero Trust architecture](https://www.ory.sh/docs/kratos/guides/zero-trust-iap-proxy-identity-access-proxy)
* Example CI/CD deployment pipeline for GitLab (The focus for this repository is still GitHub but, in case you want to use GitLab 🤷)
* [TODO] Producer and consumer to emit and consume events using [CloudEvents](https://cloudevents.io/) format on [Confluent Kafka](https://docs.confluent.io/kafka-clients/python/current/overview.html)
* [TODO] Producer and consumer to emit and consume events using [CloudEvents](https://cloudevents.io/) format using HTTP, to be used with [Knative Eventing](https://knative.dev/docs/eventing/)

## Documentation

Expand Down
2 changes: 1 addition & 1 deletion alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[alembic]
# path to migration scripts
script_location = src/alembic
script_location = src/migrations

# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
Expand Down
6 changes: 3 additions & 3 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and the persistence layer.

This is a high level list of the packages in this application template:

* `alembic` (database migration manager)
* `migrations` (database migration manager)
* `dramatiq_worker` (async tasks runner)
* `common` (some common boilerplate initialisation shared by all applications )
* `http_app` (http presentation layer)
Expand All @@ -30,7 +30,7 @@ This is a high level representation of the nested layers in the application:
```mermaid
flowchart TD
subgraph "Framework & Drivers + Interface Adapters"
alembic
migrations
dramatiq_worker
http_app
gateways
Expand All @@ -51,7 +51,7 @@ flowchart TD
end
end

alembic ~~~ domains.books
migrations ~~~ domains.books
dramatiq_worker ~~~ domains.books
http_app ~~~ domains.books
gateways ~~~ domains.books
Expand Down
1 change: 1 addition & 0 deletions docs/packages/alembic.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
we implement some extra features on top of the default configuration:

* Support for both sync and async SQLAlchemy engines at the same time
* Support for fixtures management
* Grabs the database information from the `SQLAlchemyBindManager` configuration
in the application, so we won't have duplicate configuration.
* `alembic.ini` (not technically part of the python package) is setup to
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ includes = ["src/**/*.py"]
branch = true
source = ["src"]
omit = [
"src/alembic/*",
"src/migrations/*",
"src/common/config.py",
"src/common/logs/*",
"src/dramatiq_worker/__init__.py",
Expand All @@ -94,7 +94,7 @@ exclude_also = [

[tool.mypy]
files = ["src", "tests"]
exclude = ["alembic"]
exclude = ["migrations"]
# Pydantic plugin causes some issues: https://github.com/pydantic/pydantic-settings/issues/403
#plugins = "pydantic.mypy,strawberry.ext.mypy_plugin"
plugins = "strawberry.ext.mypy_plugin"
Expand Down Expand Up @@ -151,3 +151,4 @@ ignore = [
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"] # Ignore unused imports on init files
"tests/**/*.py" = ["S101"] # Allow assert usage on tests
"src/migrations/env.py" = ["E501"] # Allow long lines
2 changes: 1 addition & 1 deletion src/alembic.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copy of alembic.ini used to run migrations inside the container

[alembic]
script_location = alembic
script_location = migrations
prepend_sys_path = .
file_template = %%(year)d-%%(month).2d-%%(day).2d-%%(hour).2d%%(minute).2d%%(second).2d-%%(rev)s_%%(slug)s
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.
187 changes: 0 additions & 187 deletions src/alembic/env.py

This file was deleted.

File renamed without changes.
Loading
Loading