use declarative_base for all ORM models

This rewrites the entire model base as declarative models.
This allows us to more easily customize overlay fields
in tables and is more common.

This effort also brought some DB violations to light which
this commit addresses.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-06-06 22:45:40 -07:00
parent 7f7a975614
commit 888cf5118a
29 changed files with 398 additions and 292 deletions

View file

@ -1,10 +1,16 @@
from fastapi import Request
from sqlalchemy.orm import mapper
from sqlalchemy import Column, String
from aurweb.schema import Bans
from aurweb.models.declarative import Base
class Ban:
class Ban(Base):
__tablename__ = "Bans"
IPAddress = Column(String(45), primary_key=True)
__mapper_args__ = {"primary_key": [IPAddress]}
def __init__(self, **kwargs):
self.IPAddress = kwargs.get("IPAddress")
self.BanTS = kwargs.get("BanTS")
@ -14,6 +20,3 @@ def is_banned(request: Request):
from aurweb.db import session
ip = request.client.host
return session.query(Ban).filter(Ban.IPAddress == ip).first() is not None
mapper(Ban, Bans)