Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,6 @@ fabric.properties


# End of https://www.toptal.com/developers/gitignore/api/flask,python,jetbrains

# own ignorations
*.db
25 changes: 15 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: "https://github.com/pre-commit/pre-commit-hooks"
rev: "v3.4.0"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: "trailing-whitespace"
- id: "end-of-file-fixer"
- repo: "https://github.com/PyCQA/isort"
rev: "5.8.0"
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/PyCQA/isort
rev: 5.9.3
hooks:
- id: "isort"
- repo: "https://github.com/psf/black"
rev: "20.8b1"
- id: isort
- repo: https://github.com/psf/black
rev: 21.7b0
hooks:
- id: "black"
- id: black
- repo: https://github.com/hadialqattan/pycln
rev: 0.0.4
hooks:
- id: pycln
args: [--config=pyproject.toml]
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8

ENV MODULE_NAME="bvrnapi.main"

# Install Poetry
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, aber ich nutze bei so etwas gerne die Langform

cd /usr/local/bin && \
ln -s /opt/poetry/bin/poetry && \
poetry config virtualenvs.create false

# Copy using poetry.lock* in case it doesn't exist yet
COPY pyproject.toml poetry.lock* /app/

RUN poetry install --no-root --no-dev

COPY ./bvrnapi /app/bvrnapi
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# BVRN API

An API for various operation around music associations.
Used and developed for [Blasmusikverband Rhein-Neckar e.V.](https://www.bvrn.de/)
Used and developed for [Blasmusikverband Rhein-Neckar e.V.](https://www.bvrn.de/).

## Local development

Expand Down
Empty file added __init__.py
Empty file.
99 changes: 99 additions & 0 deletions alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# A generic, single database configuration.

[alembic]
# path to migration scripts
script_location = alembic

# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s

# 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 =

# 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

[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

# 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

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
1 change: 1 addition & 0 deletions alembic/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generic single-database configuration.
84 changes: 84 additions & 0 deletions alembic/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool

from alembic import context

from bvrnapi.db.base import Base
from bvrnapi.config import settings

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

config.set_main_option("sqlalchemy.url", settings.SQLALCHEMY_DATABASE_URI)

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
# target_metadata = None

target_metadata = Base.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
"""Run migrations in 'offline' mode.

This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.

Calls to context.execute() here emit the given string to the
script output.

"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)

with context.begin_transaction():
context.run_migrations()


def run_migrations_online():
"""Run migrations in 'online' mode.

In this scenario we need to create an Engine
and associate a connection with the context.

"""
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)

with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)

with context.begin_transaction():
context.run_migrations()


if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
24 changes: 24 additions & 0 deletions alembic/script.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""${message}

Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}

"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}

# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}


def upgrade():
${upgrades if upgrades else "pass"}


def downgrade():
${downgrades if downgrades else "pass"}
Empty file added alembic/versions/.keep
Empty file.
65 changes: 65 additions & 0 deletions alembic/versions/7325cd96f9b7_initial_revision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""initial revision

Revision ID: 7325cd96f9b7
Revises:
Create Date: 2022-03-15 11:17:23.266003

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '7325cd96f9b7'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('association',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('number', sa.String(), nullable=True),
sa.Column('shortname', sa.String(), nullable=True),
sa.Column('association_name', sa.String(), nullable=True),
sa.Column('city', sa.String(), nullable=True),
sa.Column('representative_address', sa.String(), nullable=True),
sa.Column('representative_plz', sa.Integer(), nullable=True),
sa.Column('representative_city', sa.String(), nullable=True),
sa.Column('representative_email', sa.String(), nullable=True),
sa.Column('it_representative', sa.String(), nullable=True),
sa.Column('mtime', sa.DateTime(), nullable=True),
sa.Column('homepage', sa.String(), nullable=True),
sa.Column('impressum', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_association_association_name'), 'association', ['association_name'], unique=True)
op.create_index(op.f('ix_association_homepage'), 'association', ['homepage'], unique=False)
op.create_index(op.f('ix_association_id'), 'association', ['id'], unique=False)
op.create_index(op.f('ix_association_number'), 'association', ['number'], unique=True)
op.create_table('problem',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('type', sa.String(), nullable=True),
sa.Column('data', sa.JSON(), nullable=True),
sa.Column('mtime', sa.DateTime(), nullable=True),
sa.Column('association_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['association_id'], ['association.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_problem_id'), 'problem', ['id'], unique=False)
op.create_index(op.f('ix_problem_type'), 'problem', ['type'], unique=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_problem_type'), table_name='problem')
op.drop_index(op.f('ix_problem_id'), table_name='problem')
op.drop_table('problem')
op.drop_index(op.f('ix_association_number'), table_name='association')
op.drop_index(op.f('ix_association_id'), table_name='association')
op.drop_index(op.f('ix_association_homepage'), table_name='association')
op.drop_index(op.f('ix_association_association_name'), table_name='association')
op.drop_table('association')
# ### end Alembic commands ###
Empty file added bvrnapi/__init__.py
Empty file.
Empty file added bvrnapi/api/__init__.py
Empty file.
Empty file added bvrnapi/api/api_v1/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions bvrnapi/api/api_v1/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from fastapi import APIRouter

from bvrnapi.api.api_v1.endpoints import associations

api_router = APIRouter()
# api_router.include_router(login.router, tags=["login"])
api_router.include_router(associations.router, prefix="/associations", tags=["associations"])
Empty file.
Loading