Skip to content

Commit

Permalink
Fix migration error in token due to missing userid field
Browse files Browse the repository at this point in the history
Replace imports from `h.models` with local ORM classes. The ORM classes in
`h.models` assume the DB has the latest schema, which is not the case when
running migrations. The new code matches how other migrations work.

Fixes #8541
  • Loading branch information
robertknight committed Feb 22, 2024
1 parent b4ecb8a commit 044224b
Showing 1 changed file with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import re

from alembic import op
from sqlalchemy import select
from sqlalchemy.orm import sessionmaker

from h.models import Token, User
from sqlalchemy import Column, ForeignKey, Integer, UnicodeText, select
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Mapped, sessionmaker

revision = "8e3417e3713b"
down_revision = "8fcdcefd8c6f"
Expand All @@ -16,6 +15,29 @@
log = logging.getLogger(__name__)


Base = declarative_base()


class Token(Base):
__tablename__ = "token"

id = Column(Integer, primary_key=True)

# Legacy `userid` column.
userid = Column(UnicodeText())

# Replacement foreign key.
user_id = Column(Integer, ForeignKey("user.id"))


class User(Base):
__tablename__ = "user"

id = Column(Integer, primary_key=True)
username = Column(UnicodeText(), nullable=False)
authority = Column(UnicodeText(), nullable=False)


def split_userid(userid):
return re.match(r"^acct:([^@]+)@(.*)$", userid).groups()

Expand Down

0 comments on commit 044224b

Please # to comment.