Skip to content

Replace databases with sqlalchemy #9

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 0 additions & 7 deletions .dockerignore

This file was deleted.

17 changes: 0 additions & 17 deletions .editorconfig

This file was deleted.

23 changes: 23 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Base
SECRET_KEY=some-secret-key
PROJECT_NAME='Some Project Name'
SERVER_HOST=http://0.0.0.0:8881
DEBUG=false

# Databases
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=postgres
POSTGRES_DB=postgres
POSTGRES_TEST_DB=test
PGDATA=/var/lib/postgresql/data/pgdata

# SMTP
SMTP_USER=some-email
SMTP_PASSWORD=some-password

# Auth
FIRST_SUPERUSER_USERNAME=user@user.com
FIRST_SUPERUSER_PASSWORD=password
FIRST_SUPERUSER_FIRST_NAME='first name'
FIRST_SUPERUSER_LAST_NAME='last name'
8 changes: 4 additions & 4 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
max-line-length = 120
exclude = .git,__pycache__,__init__.py,.mypy_cache,.pytest_cache,app/db/base.py
select = C,E,F,W,B,B950
extend-ignore = E203, E501
max-line-length = 88
select = C,E,F,W,B,B9
ignore = E203, E501, W503
exclude = __init__.py,app/db/base.py
36 changes: 0 additions & 36 deletions .mypy.ini

This file was deleted.

56 changes: 37 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
exclude: 'node_modules|alembic|migrations|.git|.tox'
default_stages: [commit]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-toml

- repo: https://github.com/psf/black
rev: 22.3.0
- id: check-yaml
args:
- --unsafe
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.1
hooks:
- id: black

- repo: https://github.com/timothycrosley/isort
rev: 5.9.3
- id: pyupgrade
args:
- --py39-plus
- --keep-runtime-typing
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args:
- --recursive
- --in-place
- --remove-all-unused-imports
- --remove-unused-variables
- --exclude
- __init__.py,base.py,app/db/base.py
- --remove-duplicate-keys
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
args:
- --line-length=88
- --profile
- black
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: flake8
additional_dependencies: [flake8-isort]
- id: black
args:
- --preview
- --line-length=88
24 changes: 14 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
FROM python:3.10
# Dockerfile

ENV PATH="${PATH}:/root/.poetry/bin"

RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python - && \
poetry config virtualenvs.create false
COPY ./pyproject.toml ./poetry.lock ./
RUN poetry install --no-interaction --no-dev --no-root --no-ansi -vvv
FROM python:3.10-bullseye

# copy source and install dependencies
ENV VIRTUAL_ENV=/venv
RUN python3.10 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

ENV PYTHONPATH=/app

WORKDIR /app

COPY . .
COPY docker-entrypoint.sh ./docker-entrypoint.sh
RUN chmod +x ./docker-entrypoint.sh && \
COPY requirements.txt ./requirements.txt
RUN apt-get update && \
apt-get install -y libpq-dev python3-dev && \
chmod +x ./docker-entrypoint.sh && \
ln -s ./docker-entrypoint.sh /

EXPOSE 8080
RUN pip install -r ./requirements.txt

ENTRYPOINT ["sh", "./docker-entrypoint.sh" ]
# start service
STOPSIGNAL SIGTERM
CMD ["sh", "docker-entrypoint.sh"]
73 changes: 64 additions & 9 deletions alembic.ini
Original file line number Diff line number Diff line change
@@ -1,18 +1,73 @@
[alembic]
databases = postgres
# A generic, single database configuration.

[DEFAULT]
prepend_sys_path = .
[alembic]
# path to migration scripts
script_location = alembic

# template used to generate migration files
file_template = %%(year)d-%%(month).2d-%%(day).2d_%%(hour).2d-%%(minute).2d_%%(slug)s

truncate_slug_length = 60
version_path_separator = space
# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory.
prepend_sys_path = .

# timezone to use when rendering the date within the migration file
# as well as the filename.
# If specified, requires the python-dateutil library that can be
# installed by adding `alembic[tz]` to the pip requirements
# string value is passed to dateutil.tz.gettz()
# leave blank for localtime
timezone = UTC

# max length of characters to apply to the
# "slug" field
# truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

# version location specification; This defaults
# to migrations/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "version_path_separator" below.
# version_locations = %(here)s/bar:%(here)s/bat:migrations/versions

# version path separator; As mentioned above, this is the character used to split
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
# Valid values for version_path_separator are:
#
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
version_path_separator = os
# Use os.pathsep. Default configuration used for new projects.

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

sqlalchemy.url = postgresql+asyncpg://postgres:postgres@localhost:5432/postgres


[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples

[postgres]
version_locations = alembic/pg_versions
sqlalchemy.engine = app.db.session.postgres_engine
# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks = black
# black.type = console_scripts
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

Expand Down
Loading