mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-17 11:23:49 +08:00
first api-interaction, fix auth_method unique-index
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""add_auth_method_to_ix_person_username
|
||||
|
||||
Revision ID: 0daec5f8135f
|
||||
Revises: 6368515778c5
|
||||
Create Date: 2022-12-22 18:35:59.609013
|
||||
|
||||
"""
|
||||
import sqlalchemy as sa # noqa: F401
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "0daec5f8135f"
|
||||
down_revision = "6368515778c5"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index("ix_person_username", table_name="person")
|
||||
op.create_index("ix_person_username", "person", ["api_client_id", "username", "auth_method"], unique=True)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index("ix_person_username", table_name="person")
|
||||
op.create_index("ix_person_username", "person", ["api_client_id", "username"], unique=False)
|
||||
# ### end Alembic commands ###
|
||||
@@ -10,7 +10,7 @@ from sqlmodel import Field, Index, SQLModel
|
||||
|
||||
class Person(SQLModel, table=True):
|
||||
__tablename__ = "person"
|
||||
__table_args__ = (Index("ix_person_username", "api_client_id", "username", unique=True),)
|
||||
__table_args__ = (Index("ix_person_username", "api_client_id", "username", "auth_method", unique=True),)
|
||||
|
||||
id: Optional[UUID] = Field(
|
||||
sa_column=sa.Column(
|
||||
|
||||
@@ -32,7 +32,12 @@ class PromptRepository:
|
||||
)
|
||||
if person is None:
|
||||
# user is unknown, create new record
|
||||
person = Person(username=user.id, display_name=user.display_name, api_client_id=self.api_client.id)
|
||||
person = Person(
|
||||
username=user.id,
|
||||
display_name=user.display_name,
|
||||
api_client_id=self.api_client.id,
|
||||
auth_method=user.auth_method,
|
||||
)
|
||||
self.db.add(person)
|
||||
self.db.commit()
|
||||
self.db.refresh(person)
|
||||
|
||||
Reference in New Issue
Block a user