feat: Switch to postgres

Migrate from MariaDB to PostgreSQL.

Signed-off-by: moson <moson@archlinux.org>
This commit is contained in:
moson 2023-11-30 15:13:42 +01:00
parent 3220cf886e
commit db8e2458f9
No known key found for this signature in database
GPG key ID: 4A4760AB4EE15296
64 changed files with 572 additions and 629 deletions

View file

@ -1,6 +1,7 @@
from http import HTTPStatus
from fastapi import HTTPException
from sqlalchemy import func
from aurweb import db
from aurweb.models import User
@ -13,7 +14,7 @@ def get_user_by_name(username: str) -> User:
:param username: User.Username
:return: User instance
"""
user = db.query(User).filter(User.Username == username).first()
user = db.query(User).filter(func.lower(User.Username) == username.lower()).first()
if not user:
raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND))
return db.refresh(user)

View file

@ -7,7 +7,7 @@ All functions in this module raise aurweb.exceptions.ValidationError
when encountering invalid criteria and return silently otherwise.
"""
from fastapi import Request
from sqlalchemy import and_
from sqlalchemy import and_, func
from aurweb import aur_logging, config, db, l10n, models, time, util
from aurweb.auth import creds
@ -157,7 +157,11 @@ def username_in_use(
) -> None:
exists = (
db.query(models.User)
.filter(and_(models.User.ID != user.ID, models.User.Username == U))
.filter(
and_(
models.User.ID != user.ID, func.lower(models.User.Username) == U.lower()
)
)
.exists()
)
if db.query(exists).scalar():
@ -175,7 +179,9 @@ def email_in_use(
) -> None:
exists = (
db.query(models.User)
.filter(and_(models.User.ID != user.ID, models.User.Email == E))
.filter(
and_(models.User.ID != user.ID, func.lower(models.User.Email) == E.lower())
)
.exists()
)
if db.query(exists).scalar():