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 e7fa258
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,40 @@
import re

from alembic import op
from sqlalchemy import select
from sqlalchemy import Column, ForeignKey, Integer, UnicodeText, select
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

from h.models import Token, User

revision = "8e3417e3713b"
down_revision = "8fcdcefd8c6f"


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 e7fa258

Please # to comment.