nullables + Type hints

This commit is contained in:
Jörn-Michael Miehe 2022-03-23 15:00:35 +00:00
parent fba1bf6514
commit 814a19d864

View file

@ -18,7 +18,7 @@ class User(ORMBaseModel):
__tablename__ = "users" __tablename__ = "users"
name = Column(String, primary_key=True, index=True) name = Column(String, primary_key=True, index=True)
password = Column(String) password = Column(String, nullable=False)
capabilities: list[UserCapability] = relationship( capabilities: list[UserCapability] = relationship(
"UserCapability", lazy="joined", cascade="all, delete-orphan" "UserCapability", lazy="joined", cascade="all, delete-orphan"
@ -60,14 +60,14 @@ class DistinguishedName(ORMBaseModel):
id = Column(Integer, primary_key=True, autoincrement=True) id = Column(Integer, primary_key=True, autoincrement=True)
owner_name = Column(String, ForeignKey("users.name")) owner_name = Column(String, ForeignKey("users.name"))
cn_only = Column(Boolean, default=True) cn_only = Column(Boolean, default=True, nullable=False)
country = Column(String(2)) country = Column(String(2))
state = Column(String) state = Column(String)
city = Column(String) city = Column(String)
organization = Column(String) organization = Column(String)
organizational_unit = Column(String) organizational_unit = Column(String)
email = Column(String) email = Column(String)
common_name = Column(String) common_name = Column(String, nullable=False)
UniqueConstraint( UniqueConstraint(
country, country,
@ -86,7 +86,13 @@ class Certificate(ORMBaseModel):
id = Column(Integer, primary_key=True, autoincrement=True) id = Column(Integer, primary_key=True, autoincrement=True)
owner_name = Column(String, ForeignKey("users.name")) owner_name = Column(String, ForeignKey("users.name"))
dn_id = Column(Integer, ForeignKey("distinguished_names.id")) dn_id = Column(
Integer,
ForeignKey("distinguished_names.id"),
nullable=False,
)
expiry = Column(DateTime, default=datetime.datetime.now) expiry = Column(DateTime, default=datetime.datetime.now)
distinguished_name = relationship("DistinguishedName", lazy="joined") distinguished_name: DistinguishedName = relationship(
"DistinguishedName", lazy="joined"
)