-
Remco Tukker authoredRemco Tukker authored
survey_model.py 1.24 KiB
import logging
from typing import Dict, Any
from typing_extensions import Annotated
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.schema import ForeignKey
from sqlalchemy.types import JSON
from compendium_v2.db import db
from compendium_v2.db.model import NREN
logger = logging.getLogger(__name__)
int_pk = Annotated[int, mapped_column(primary_key=True)]
int_pk_fkNREN = Annotated[int, mapped_column(ForeignKey("nren.id"), primary_key=True)]
int_pk_fkSurvey = Annotated[int, mapped_column(ForeignKey("survey.year"), primary_key=True)]
json = Annotated[Dict[str, Any], mapped_column(JSON)]
# Unfortunately flask-sqlalchemy doesnt fully support DeclarativeBase yet.
# See https://github.com/pallets-eco/flask-sqlalchemy/issues/1140
# mypy: disable-error-code="name-defined"
class Survey(db.Model):
__tablename__ = 'survey'
year: Mapped[int_pk]
survey: Mapped[json]
# status column?
class SurveyResponse(db.Model):
__tablename__ = 'survey_response'
nren_id: Mapped[int_pk_fkNREN]
nren: Mapped[NREN] = relationship(lazy='joined')
survey_year: Mapped[int_pk_fkSurvey]
survey: Mapped[Survey] = relationship(lazy='joined')
answers: Mapped[json]
# completed column?? I think we need that..