Skip to content

Commit

Permalink
chore: tables for workshops and checkins
Browse files Browse the repository at this point in the history
  • Loading branch information
fivan999 committed Oct 29, 2024
1 parent 44d4d10 commit fcee98c
Show file tree
Hide file tree
Showing 16 changed files with 329 additions and 258 deletions.
3 changes: 2 additions & 1 deletion alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
fileConfig(config.config_file_name)

# Read settings YAML file
import os # noqa: E402
from pathlib import Path # noqa: E402

from yaml import safe_load # noqa: E402
import os # noqa: E402

app_settings_path = os.getenv("SETTINGS_PATH", "settings.yaml")
app_settings = safe_load(Path(app_settings_path).read_text())
Expand Down
Empty file removed alembic/versions/.gitkeep
Empty file.
39 changes: 0 additions & 39 deletions alembic/versions/_2024_09_21_23_01_add_user_table.py

This file was deleted.

61 changes: 61 additions & 0 deletions alembic/versions/_2024_10_30_01_20_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""empty message
Revision ID: 7fa9ff5cfa18
Revises:
Create Date: 2024-10-30 01:20:12.174006
"""

from typing import Sequence, Union

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "7fa9ff5cfa18"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"users",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("innohassle_id", sa.String(), nullable=False),
sa.Column("email", sa.String(), nullable=False),
sa.Column("name", sa.String(), nullable=True),
sa.Column("role", sa.Enum("DEFAULT", "ADMIN", name="userrole"), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"workshops",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(length=255), nullable=False),
sa.Column("alias", sa.String(length=255), nullable=False),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("dtstart", sa.DateTime(), nullable=False),
sa.Column("dtend", sa.DateTime(), nullable=False),
sa.Column("capacity", sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("alias"),
)
op.create_table(
"workshops_checkins",
sa.Column("user_id", sa.Integer(), nullable=False),
sa.Column("workshop_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["workshop_id"], ["users.id"], ondelete="CASCADE"),
sa.PrimaryKeyConstraint("user_id", "workshop_id"),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("workshops_checkins")
op.drop_table("workshops")
op.drop_table("users")
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
condition: service_healthy
restart: always
ports:
- "8000:8000"
- "8002:8000"
env_file: .env

db:
Expand Down
395 changes: 202 additions & 193 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
name = "fastapi-template"
name = "workshops"
version = "0.1.0"
description = ""
authors = ["one-zero-eight <https://t.me/one_zero_eight>"]
Expand Down Expand Up @@ -29,7 +29,9 @@ lint.ignore = [
# wildcard imports are fine
"F403",
"F405",
"PLR"
]
lint.extend-select = ["I", "UP", "PL"]

[build-system]
requires = ["poetry-core"]
Expand Down
2 changes: 1 addition & 1 deletion scripts/alembic_auto_migrations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
import pathlib
import sys

import alembic.config

Expand Down
9 changes: 2 additions & 7 deletions settings.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
$schema: http://json-schema.org/draft-07/schema#
$schema: https://json-schema.org/draft-07/schema
$defs:
Accounts:
additionalProperties: false
description: InNoHassle-Accounts integration settings
description: InNoHassle Accounts integration settings
properties:
api_url:
default: https://api.innohassle.ru/accounts/v0
description: URL of the Accounts API
title: Api Url
type: string
well_known_url:
default: https://api.innohassle.ru/accounts/v0/.well-known
description: URL of the well-known endpoint for the Accounts API
title: Well Known Url
type: string
api_jwt_token:
description: JWT token for accessing the Accounts API as a service
format: password
Expand Down
2 changes: 1 addition & 1 deletion src/api/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__all__ = ["IncorrectCredentialsException"]

from typing import ClassVar, Any
from typing import Any, ClassVar

from fastapi import HTTPException
from starlette import status
Expand Down
4 changes: 2 additions & 2 deletions src/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path

import yaml
from pydantic import BaseModel, Field, SecretStr, ConfigDict
from pydantic import BaseModel, ConfigDict, Field, SecretStr


class Environment(StrEnum):
Expand Down Expand Up @@ -40,7 +40,7 @@ class Settings(SettingBaseModel):

@classmethod
def from_yaml(cls, path: Path) -> "Settings":
with open(path, "r", encoding="utf-8") as f:
with open(path, encoding="utf-8") as f:
yaml_config = yaml.safe_load(f)

return cls.model_validate(yaml_config)
Expand Down
4 changes: 2 additions & 2 deletions src/logging_.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import inspect
import logging.config
import os
from typing import Dict, Any
from typing import Any, Dict

import fastapi
import yaml
Expand All @@ -18,7 +18,7 @@ def filter(self, record: logging.LogRecord) -> bool:
return True


with open("logging.yaml", "r") as f:
with open("logging.yaml") as f:
config = yaml.safe_load(f)
logging.config.dictConfig(config)

Expand Down
3 changes: 1 addition & 2 deletions src/modules/tokens/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import time

from authlib.jose import JWTClaims
from authlib.jose import jwt, JoseError
from authlib.jose import JoseError, JWTClaims, jwt
from pydantic import BaseModel

from src.modules.innohassle_accounts import innohassle_accounts
Expand Down
3 changes: 2 additions & 1 deletion src/storages/sql/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

# Add all models here
from src.storages.sql.models.users import User
from src.storages.sql.models.workshops import CheckIn, Workshop

__all__ = ["Base", "User"]
__all__ = ["Base", "User", "Workshop", "CheckIn"]
30 changes: 30 additions & 0 deletions src/storages/sql/models/workshops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
__all__ = ["Workshop", "CheckIn"]

import datetime

from sqlalchemy import ForeignKey, String, Text
from sqlalchemy.orm import Mapped, mapped_column

from src.storages.sql.models.base import Base


class Workshop(Base):
__tablename__ = "workshops"

id: Mapped[int] = mapped_column(primary_key=True)

name: Mapped[str] = mapped_column(String(255), nullable=False)
alias: Mapped[str] = mapped_column(String(255), unique=True)
description: Mapped[str] = mapped_column(Text, nullable=True)

dtstart: Mapped[datetime.datetime] = mapped_column()
dtend: Mapped[datetime.datetime] = mapped_column()

capacity: Mapped[int] = mapped_column()


class CheckIn(Base):
__tablename__ = "workshops_checkins"

user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), primary_key=True)
workshop_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), primary_key=True)
26 changes: 19 additions & 7 deletions src/storages/sql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,24 @@
"AssociationProxy",
]

from sqlalchemy import ForeignKey, UniqueConstraint
from sqlalchemy.ext.associationproxy import association_proxy, AssociationProxy
from sqlalchemy import (
DateTime,
ForeignKey,
String,
UniqueConstraint,
and_,
any_,
bindparam,
delete,
insert,
join,
not_,
or_,
select,
union,
update,
)
from sqlalchemy import Enum as SQLEnum
from sqlalchemy.ext.associationproxy import AssociationProxy, association_proxy
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy import select, update, insert, delete, join, union
from sqlalchemy import and_, or_, any_, not_
from sqlalchemy import bindparam
from sqlalchemy import DateTime
from sqlalchemy.sql import func
from sqlalchemy import Enum as SQLEnum, String

0 comments on commit fcee98c

Please sign in to comment.