Skip to content

Commit 296db8b

Browse files
committed
Merge branch 'release/3.2.0'
2 parents 4cfc4dc + f44021d commit 296db8b

35 files changed

+536
-121
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,22 @@ on:
88
- "*"
99

1010
jobs:
11+
pre_job:
12+
# continue-on-error: true # Uncomment once integration is finished
13+
runs-on: ubuntu-latest
14+
# Map a step output to a job output
15+
outputs:
16+
should_skip: ${{ steps.skip_check.outputs.should_skip }}
17+
steps:
18+
- id: skip_check
19+
uses: fkirc/skip-duplicate-actions@master
20+
with:
21+
# All of these options are optional, so you can remove them if you are happy with the defaults
22+
concurrent_skipping: 'same_content'
23+
skip_after_successful_duplicate: 'true'
1124
pytest:
25+
needs: pre_job
26+
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
1227
runs-on: ubuntu-latest
1328
steps:
1429
- uses: actions/checkout@v2

fastapi_template/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ def read_user_input(current_context: BuilderContext) -> BuilderContext:
187187
if current_context.db == DatabaseType.none:
188188
current_context.enable_migrations = False
189189
current_context.add_dummy = False
190+
current_context.orm == ORM.none
190191
elif current_context.orm is None:
191192
current_context.orm = radiolist_dialog(
192193
"ORM",

fastapi_template/input_model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class CIType(enum.Enum):
2020

2121
@enum.unique
2222
class ORM(enum.Enum):
23+
none = "none"
24+
ormar = "ormar"
2325
sqlalchemy = "sqlalchemy"
2426
tortoise = "tortoise"
2527

@@ -29,6 +31,7 @@ class Database(BaseModel):
2931
image: Optional[str]
3032
driver: Optional[str]
3133
async_driver: Optional[str]
34+
driver_short: Optional[str]
3235
port: Optional[int]
3336

3437

@@ -44,20 +47,23 @@ class Database(BaseModel):
4447
name=DatabaseType.postgresql.value,
4548
image="postgres:13.4-buster",
4649
async_driver="postgresql+asyncpg",
47-
driver="postgres",
50+
driver_short="postgres",
51+
driver="postgresql",
4852
port=5432,
4953
),
5054
DatabaseType.mysql: Database(
5155
name=DatabaseType.mysql.value,
5256
image="bitnami/mysql:8.0.26",
5357
async_driver="mysql+aiomysql",
58+
driver_short="mysql",
5459
driver="mysql",
5560
port=3306,
5661
),
5762
DatabaseType.sqlite: Database(
5863
name=DatabaseType.sqlite.value,
5964
image=None,
6065
async_driver="sqlite+aiosqlite",
66+
driver_short="sqlite",
6167
driver="sqlite",
6268
port=None,
6369
),

fastapi_template/template/{{cookiecutter.project_name}}/.pre-commit-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ repos:
5858
entry: poetry run mypy
5959
language: system
6060
types: [python]
61+
pass_filenames: false
62+
args:
63+
- "{{cookiecutter.project_name}}"
6164

6265
- id: yesqa
6366
name: Remove usless noqa

fastapi_template/template/{{cookiecutter.project_name}}/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ docker save --output {{cookiecutter.project_name}}.tar {{cookiecutter.project_na
3737

3838
If you want to migrate your database, you should run following commands:
3939
```bash
40-
{%- if cookiecutter.orm == 'sqlalchemy' %}
40+
{%- if cookiecutter.orm in ['sqlalchemy', 'ormar'] %}
4141
# To run all migrations untill the migration with revision_id.
4242
alembic upgrade "<revision_id>"
4343

@@ -53,7 +53,7 @@ aerich upgrade
5353
5454
If you want to revert migrations, you should run:
5555
```bash
56-
{%- if cookiecutter.orm == 'sqlalchemy' %}
56+
{%- if cookiecutter.orm in ['sqlalchemy', 'ormar'] %}
5757
# revert all migrations up to: revision_id.
5858
alembic downgrade <revision_id>
5959

@@ -68,7 +68,7 @@ aerich downgrade
6868
6969
To generate migrations you should run:
7070
```bash
71-
{%- if cookiecutter.orm == 'sqlalchemy' %}
71+
{%- if cookiecutter.orm in ['sqlalchemy', 'ormar'] %}
7272
# For automatic change detection.
7373
alembic revision --autogenerate
7474

fastapi_template/template/{{cookiecutter.project_name}}/conditional_files.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@
3737
"aerich.ini",
3838
"alembic.ini",
3939
"{{cookiecutter.project_name}}/db_sa/migrations",
40+
"{{cookiecutter.project_name}}/db_ormar/migrations",
4041
"{{cookiecutter.project_name}}/db_tortoise/migrations"
4142
]
4243
},
44+
"Alembic migrations": {
45+
"enabled": "{{cookiecutter.orm in ['ormar', 'sqlalchemy']}}",
46+
"resources": [
47+
"alembic.ini"
48+
]
49+
},
4350
"Gitlab CI": {
4451
"enabled": "{{cookiecutter.ci_type == 'gitlab_ci'}}",
4552
"resources": [
@@ -69,10 +76,13 @@
6976
"{{cookiecutter.project_name}}/web/api/dummy",
7077
"{{cookiecutter.project_name}}/db_sa/dao",
7178
"{{cookiecutter.project_name}}/db_sa/models/dummy_model.py",
79+
"{{cookiecutter.project_name}}/db_ormar/dao",
80+
"{{cookiecutter.project_name}}/db_ormar/models/dummy_model.py",
7281
"{{cookiecutter.project_name}}/db_tortoise/dao",
7382
"{{cookiecutter.project_name}}/db_tortoise/models/dummy_model.py",
7483
"{{cookiecutter.project_name}}/tests/test_dummy.py",
7584
"{{cookiecutter.project_name}}/db_sa/migrations/versions/2021-08-16-16-55_2b7380507a71.py",
85+
"{{cookiecutter.project_name}}/db_ormar/migrations/versions/2021-08-16-16-55_2b7380507a71.py",
7686
"{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_pg.sql",
7787
"{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_mysql.sql",
7888
"{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_sqlite.sql"
@@ -88,7 +98,6 @@
8898
"SQLAlchemy ORM": {
8999
"enabled": "{{cookiecutter.orm == 'sqlalchemy'}}",
90100
"resources": [
91-
"alembic.ini",
92101
"{{cookiecutter.project_name}}/db_sa"
93102
]
94103
},
@@ -99,6 +108,12 @@
99108
"{{cookiecutter.project_name}}/db_tortoise"
100109
]
101110
},
111+
"Ormar ORM": {
112+
"enabled": "{{cookiecutter.orm == 'ormar'}}",
113+
"resources": [
114+
"{{cookiecutter.project_name}}/db_ormar"
115+
]
116+
},
102117
"Postgresql DB": {
103118
"enabled": "{{cookiecutter.db_info.name == 'postgresql'}}",
104119
"resources": [

fastapi_template/template/{{cookiecutter.project_name}}/deploy/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
FROM python:3.9.6-slim-buster
22

3+
{% if cookiecutter.db_info.name == "mysql" -%}
4+
RUN apt-get update && apt-get install -y \
5+
default-libmysqlclient-dev \
6+
gcc \
7+
&& rm -rf /var/lib/apt/lists/*
8+
{%- endif %}
39

410
RUN pip install poetry==1.1.8
511

@@ -13,6 +19,13 @@ WORKDIR /app/src
1319
# Installing requirements
1420
RUN poetry install
1521

22+
{%- if cookiecutter.db_info.name == "mysql" %}
23+
# Removing gcc
24+
RUN apt-get purge -y \
25+
gcc \
26+
&& rm -rf /var/lib/apt/lists/*
27+
{%- endif %}
28+
1629
# Copying actuall application
1730
COPY . /app/src/
1831
RUN poetry install

fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ services:
9393
migrator:
9494
image: {{cookiecutter.project_name}}:{{"${" }}{{cookiecutter.project_name | upper }}_VERSION:-latest{{"}"}}
9595
restart: "no"
96-
{%- if cookiecutter.orm == 'sqlalchemy' %}
96+
{%- if cookiecutter.orm in ['sqlalchemy', 'ormar'] %}
9797
command: alembic upgrade head
9898
{%- elif cookiecutter.orm == 'tortoise' %}
9999
command: aerich upgrade

fastapi_template/template/{{cookiecutter.project_name}}/deploy/kube/app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ spec:
2828
args:
2929
- -c
3030
- >-
31-
{%- if cookiecutter.orm == 'sqlalchemy' %}
31+
{%- if cookiecutter.orm in ['sqlalchemy', 'ormar'] %}
3232
alembic upgrade head &&
3333
{%- elif cookiecutter.orm == 'tortoise' %}
3434
aerich upgrade &&

fastapi_template/template/{{cookiecutter.project_name}}/deploy/kube/db.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ spec:
6666
- name: migrator
6767
image: {{cookiecutter.project_name}}:latest
6868
command:
69-
{%- if cookiecutter.orm == 'sqlalchemy' %}
69+
{%- if cookiecutter.orm in ['sqlalchemy', 'ormar'] %}
7070
- "alembic"
7171
- "upgrade"
7272
- "head"

0 commit comments

Comments
 (0)