modify schema primary keys to be nullable+defaulted

This fixes SQLAlchemy warnings related to primary keys not
having an auto_increment or nullable.

We've done this by making all foreign primary keys nullable.

In ApiRateLimit's case, we can set a default str to act as
a null, which seems a bit more sensible.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-06-04 00:31:15 -07:00
parent e5df083d45
commit d7481b9649
5 changed files with 42 additions and 11 deletions

View file

@ -1,4 +1,5 @@
from sqlalchemy.orm import mapper
from sqlalchemy.exc import IntegrityError
from aurweb.db import make_relationship
from aurweb.models.package_base import PackageBase
@ -10,6 +11,12 @@ class PackageKeyword:
PackageBase: PackageBase = None,
Keyword: str = None):
self.PackageBase = PackageBase
if not self.PackageBase:
raise IntegrityError(
statement="Primary key PackageBaseID cannot be null.",
orig="PackageKeywords.PackageBaseID",
params=("NULL"))
self.Keyword = Keyword