mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
change(fastapi): refactor database ORM model definitions
We don't want to depend on the database to load up data about the models we define. We now leverage the existing `aurweb.schema` module for table definitions and set __table_args__["autoload"] to False. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
e4a5b7fae9
commit
446a082352
31 changed files with 212 additions and 356 deletions
|
@ -1,31 +1,27 @@
|
|||
from sqlalchemy import Column, ForeignKey, Integer
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm import backref, relationship
|
||||
|
||||
from aurweb import schema
|
||||
from aurweb.models.declarative import Base
|
||||
from aurweb.models.package_base import PackageBase as _PackageBase
|
||||
from aurweb.models.user import User as _User
|
||||
|
||||
|
||||
class PackageNotification(Base):
|
||||
__tablename__ = "PackageNotifications"
|
||||
__table__ = schema.PackageNotifications
|
||||
__tablename__ = __table__.name
|
||||
__mapper_args__ = {
|
||||
"primary_key": [__table__.c.UserID, __table__.c.PackageBaseID]
|
||||
}
|
||||
|
||||
UserID = Column(
|
||||
Integer, ForeignKey("Users.ID", ondelete="CASCADE"),
|
||||
nullable=False)
|
||||
User = relationship(
|
||||
_User, backref=backref("notifications", lazy="dynamic"),
|
||||
foreign_keys=[UserID])
|
||||
foreign_keys=[__table__.c.UserID])
|
||||
|
||||
PackageBaseID = Column(
|
||||
Integer, ForeignKey("PackageBases.ID", ondelete="CASCADE"),
|
||||
nullable=False)
|
||||
PackageBase = relationship(
|
||||
_PackageBase,
|
||||
backref=backref("notifications", lazy="dynamic"),
|
||||
foreign_keys=[PackageBaseID])
|
||||
|
||||
__mapper_args__ = {"primary_key": [UserID, PackageBaseID]}
|
||||
foreign_keys=[__table__.c.PackageBaseID])
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue