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.group import Group
@ -9,7 +10,18 @@ from aurweb.schema import PackageGroups
class PackageGroup:
def __init__(self, Package: Package = None, Group: Group = None):
self.Package = Package
if not self.Package:
raise IntegrityError(
statement="Primary key PackageID cannot be null.",
orig="PackageGroups.PackageID",
params=("NULL"))
self.Group = Group
if not self.Group:
raise IntegrityError(
statement="Primary key GroupID cannot be null.",
orig="PackageGroups.GroupID",
params=("NULL"))
properties = {

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

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.license import License
@ -9,7 +10,18 @@ from aurweb.schema import PackageLicenses
class PackageLicense:
def __init__(self, Package: Package = None, License: License = None):
self.Package = Package
if not self.Package:
raise IntegrityError(
statement="Primary key PackageID cannot be null.",
orig="PackageLicenses.PackageID",
params=("NULL"))
self.License = License
if not self.License:
raise IntegrityError(
statement="Primary key LicenseID cannot be null.",
orig="PackageLicenses.LicenseID",
params=("NULL"))
properties = {
@ -21,6 +33,8 @@ properties = {
PackageLicenses.c.LicenseID,
"package_license",
uselist=False)
}
mapper(PackageLicense, PackageLicenses, properties=properties,