minor DB refactoring
This commit is contained in:
parent
12d39bb923
commit
5dce05816f
2 changed files with 33 additions and 34 deletions
|
@ -21,7 +21,8 @@ class User(ORMBaseModel):
|
|||
password = Column(String)
|
||||
|
||||
capabilities = relationship("UserCapability", lazy="joined")
|
||||
certificates = relationship("Certificate", lazy="joined")
|
||||
certificates = relationship("Certificate", lazy="select")
|
||||
distinguished_names = relationship("DistinguishedName", lazy="select")
|
||||
|
||||
@classmethod
|
||||
def load(cls, db: Session, name: str) -> User | None:
|
||||
|
@ -52,6 +53,7 @@ class DistinguishedName(ORMBaseModel):
|
|||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
owner_name = Column(String, ForeignKey("users.name"))
|
||||
cn_only = Column(Boolean, default=True)
|
||||
country = Column(String(2))
|
||||
state = Column(String)
|
||||
|
@ -61,8 +63,6 @@ class DistinguishedName(ORMBaseModel):
|
|||
email = Column(String)
|
||||
common_name = Column(String)
|
||||
|
||||
certificates = relationship("Certificate", lazy="joined")
|
||||
|
||||
UniqueConstraint(
|
||||
country,
|
||||
state,
|
||||
|
@ -82,3 +82,5 @@ class Certificate(ORMBaseModel):
|
|||
owner_name = Column(String, ForeignKey("users.name"))
|
||||
dn_id = Column(Integer, ForeignKey("distinguished_names.id"))
|
||||
expiry = Column(DateTime, default=datetime.datetime.now)
|
||||
|
||||
distinguished_name = relationship("DistinguishedName", lazy="joined")
|
||||
|
|
|
@ -16,6 +16,30 @@ from sqlalchemy.orm import Session
|
|||
|
||||
from . import models
|
||||
|
||||
##########
|
||||
# table: distinguished_names
|
||||
##########
|
||||
|
||||
|
||||
class DistinguishedNameBase(BaseModel):
|
||||
cn_only: bool
|
||||
country: str
|
||||
state: str
|
||||
city: str
|
||||
organization: str
|
||||
organizational_unit: str
|
||||
email: str
|
||||
common_name: str
|
||||
|
||||
|
||||
class DistinguishedNameCreate(DistinguishedNameBase):
|
||||
pass
|
||||
|
||||
|
||||
class DistinguishedName(DistinguishedNameBase):
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
##########
|
||||
# table: certificates
|
||||
##########
|
||||
|
@ -26,12 +50,11 @@ class CertificateBase(BaseModel):
|
|||
|
||||
|
||||
class CertificateCreate(CertificateBase):
|
||||
owner_name: str
|
||||
dn_id: int
|
||||
pass
|
||||
|
||||
|
||||
class Certificate(CertificateBase):
|
||||
id: int
|
||||
distinguished_name: DistinguishedName
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
@ -76,8 +99,9 @@ class UserCreate(UserBase):
|
|||
|
||||
|
||||
class User(UserBase):
|
||||
certificates: list[Certificate] = []
|
||||
capabilities: list[UserCapability] = []
|
||||
distinguished_names: list[DistinguishedName] = []
|
||||
certificates: list[Certificate] = []
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
@ -178,30 +202,3 @@ class User(UserBase):
|
|||
)
|
||||
|
||||
db.commit()
|
||||
|
||||
##########
|
||||
# table: distinguished_names
|
||||
##########
|
||||
|
||||
|
||||
class DistinguishedNameBase(BaseModel):
|
||||
cn_only: bool
|
||||
country: str
|
||||
state: str
|
||||
city: str
|
||||
organization: str
|
||||
organizational_unit: str
|
||||
email: str
|
||||
common_name: str
|
||||
|
||||
|
||||
class DistinguishedNameCreate(DistinguishedNameBase):
|
||||
pass
|
||||
|
||||
|
||||
class DistinguishedName(DistinguishedNameBase):
|
||||
id: int
|
||||
certificates: list[Certificate]
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
|
Loading…
Reference in a new issue