feat: remove pydantic from list generation
This commit is contained in:
parent
1e70ec8fa6
commit
d08388c339
8 changed files with 164 additions and 197 deletions
|
@ -3,6 +3,8 @@ from abc import abstractmethod
|
|||
from datetime import datetime
|
||||
from typing import Union, List, Optional, Any, Dict
|
||||
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.brm.brn import BRN
|
||||
from app.extensions import db
|
||||
|
||||
|
@ -10,11 +12,11 @@ from app.extensions import db
|
|||
class AbstractConfiguration(db.Model): # type: ignore
|
||||
__abstract__ = True
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
description = db.Column(db.String(255), nullable=False)
|
||||
added = db.Column(db.DateTime(), default=datetime.utcnow, nullable=False)
|
||||
updated = db.Column(db.DateTime(), default=datetime.utcnow, nullable=False)
|
||||
destroyed = db.Column(db.DateTime(), nullable=True)
|
||||
id: Mapped[int] = mapped_column(db.Integer, primary_key=True)
|
||||
description: Mapped[str] = mapped_column(db.String(255), nullable=False)
|
||||
added: Mapped[datetime] = mapped_column(db.DateTime(), default=datetime.utcnow, nullable=False)
|
||||
updated: Mapped[datetime] = mapped_column(db.DateTime(), default=datetime.utcnow, nullable=False)
|
||||
destroyed: Mapped[datetime] = mapped_column(db.DateTime())
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
|
@ -38,12 +40,12 @@ class AbstractConfiguration(db.Model): # type: ignore
|
|||
|
||||
|
||||
class Deprecation(db.Model): # type: ignore[name-defined,misc]
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
resource_type = db.Column(db.String(50))
|
||||
resource_id = db.Column(db.Integer)
|
||||
deprecated_at = db.Column(db.DateTime(), default=datetime.utcnow, nullable=False)
|
||||
meta = db.Column(db.JSON())
|
||||
reason = db.Column(db.String(), nullable=False)
|
||||
id: Mapped[int] = mapped_column(db.Integer, primary_key=True)
|
||||
resource_type: Mapped[str] = mapped_column(db.String(50))
|
||||
resource_id: Mapped[int] = mapped_column(db.Integer)
|
||||
deprecated_at: Mapped[datetime] = mapped_column(db.DateTime(), default=datetime.utcnow, nullable=False)
|
||||
meta: Mapped[Optional[Dict[str, Any]]] = mapped_column(db.JSON())
|
||||
reason: Mapped[str] = mapped_column(db.String(), nullable=False)
|
||||
|
||||
@property
|
||||
def resource(self) -> "AbstractResource":
|
||||
|
@ -55,12 +57,12 @@ class Deprecation(db.Model): # type: ignore[name-defined,misc]
|
|||
class AbstractResource(db.Model): # type: ignore
|
||||
__abstract__ = True
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
added = db.Column(db.DateTime(), default=datetime.utcnow, nullable=False)
|
||||
updated = db.Column(db.DateTime(), default=datetime.utcnow, nullable=False)
|
||||
deprecated = db.Column(db.DateTime(), nullable=True)
|
||||
deprecation_reason = db.Column(db.String(), nullable=True)
|
||||
destroyed = db.Column(db.DateTime(), nullable=True)
|
||||
id: Mapped[int] = mapped_column(db.Integer, primary_key=True)
|
||||
added: Mapped[datetime] = mapped_column(db.DateTime(), default=datetime.utcnow, nullable=False)
|
||||
updated: Mapped[datetime] = mapped_column(db.DateTime(), default=datetime.utcnow, nullable=False)
|
||||
deprecated: Mapped[Optional[datetime]] = mapped_column(db.DateTime())
|
||||
deprecation_reason: Mapped[Optional[str]] = mapped_column(db.String())
|
||||
destroyed: Mapped[Optional[datetime]] = mapped_column(db.DateTime())
|
||||
|
||||
def __init__(self, *,
|
||||
id: Optional[int] = None,
|
||||
|
@ -70,6 +72,10 @@ class AbstractResource(db.Model): # type: ignore
|
|||
deprecation_reason: Optional[str] = None,
|
||||
destroyed: Optional[datetime] = None,
|
||||
**kwargs: Any) -> None:
|
||||
if added is None:
|
||||
added = datetime.utcnow()
|
||||
if updated is None:
|
||||
updated = datetime.utcnow()
|
||||
super().__init__(id=id,
|
||||
added=added,
|
||||
updated=updated,
|
||||
|
@ -77,10 +83,6 @@ class AbstractResource(db.Model): # type: ignore
|
|||
deprecation_reason=deprecation_reason,
|
||||
destroyed=destroyed,
|
||||
**kwargs)
|
||||
if self.added is None:
|
||||
self.added = datetime.utcnow()
|
||||
if self.updated is None:
|
||||
self.updated = datetime.utcnow()
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue