Skip to content

Commit

Permalink
chore(auth): strengthen check constraints related to auth method (#4704)
Browse files Browse the repository at this point in the history
  • Loading branch information
axiomofjoy authored and RogerHYang committed Sep 21, 2024
1 parent 87227b7 commit afe991c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,18 @@ def upgrade() -> None:
sa.TIMESTAMP(timezone=True),
nullable=True,
),
sa.CheckConstraint("password_hash is null or password_salt is not null", name="salt"),
sa.CheckConstraint(
"(password_hash IS NULL) = (password_salt IS NULL)",
name="password_hash_and_salt",
),
sa.CheckConstraint(
"(oauth2_client_id IS NULL) = (oauth2_user_id IS NULL)",
name="oauth2_client_id_and_user_id",
),
sa.CheckConstraint(
"password_hash IS NULL or oauth2_client_id IS NULL",
name="at_most_one_auth_method",
),
sa.UniqueConstraint(
"oauth2_client_id",
"oauth2_user_id",
Expand Down
13 changes: 12 additions & 1 deletion src/phoenix/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,18 @@ def _auth_method_expression(cls) -> ColumnElement[Optional[str]]:
)

__table_args__ = (
CheckConstraint("password_hash is null or password_salt is not null", name="salt"),
CheckConstraint(
"(password_hash IS NULL) = (password_salt IS NULL)",
name="password_hash_and_salt",
),
CheckConstraint(
"(oauth2_client_id IS NULL) = (oauth2_user_id IS NULL)",
name="oauth2_client_id_and_user_id",
),
CheckConstraint(
"password_hash IS NULL or oauth2_client_id IS NULL",
name="at_most_one_auth_method",
),
UniqueConstraint(
"oauth2_client_id",
"oauth2_user_id",
Expand Down

0 comments on commit afe991c

Please sign in to comment.