From 814a19d86427f647f47561e32da25dc018b23789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Wed, 23 Mar 2022 15:00:35 +0000 Subject: [PATCH] nullables + Type hints --- api/kiwi_vpn_api/db/models.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/api/kiwi_vpn_api/db/models.py b/api/kiwi_vpn_api/db/models.py index 421dbed..633e78a 100644 --- a/api/kiwi_vpn_api/db/models.py +++ b/api/kiwi_vpn_api/db/models.py @@ -18,7 +18,7 @@ class User(ORMBaseModel): __tablename__ = "users" name = Column(String, primary_key=True, index=True) - password = Column(String) + password = Column(String, nullable=False) capabilities: list[UserCapability] = relationship( "UserCapability", lazy="joined", cascade="all, delete-orphan" @@ -60,14 +60,14 @@ class DistinguishedName(ORMBaseModel): id = Column(Integer, primary_key=True, autoincrement=True) 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)) state = Column(String) city = Column(String) organization = Column(String) organizational_unit = Column(String) email = Column(String) - common_name = Column(String) + common_name = Column(String, nullable=False) UniqueConstraint( country, @@ -86,7 +86,13 @@ class Certificate(ORMBaseModel): id = Column(Integer, primary_key=True, autoincrement=True) 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) - distinguished_name = relationship("DistinguishedName", lazy="joined") + distinguished_name: DistinguishedName = relationship( + "DistinguishedName", lazy="joined" + )