mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat: Switch to postgres
Migrate from MariaDB to PostgreSQL. Signed-off-by: moson <moson@archlinux.org>
This commit is contained in:
parent
3220cf886e
commit
db8e2458f9
64 changed files with 572 additions and 629 deletions
|
@ -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)
|
||||
|
|
|
@ -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():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue