Skip to content

Commit

Permalink
Add pubid to User model
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomilov committed Jan 14, 2025
1 parent dac0c3f commit 420846d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions h/migrations/versions/3bae642f2b36_add_pubid_to_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Add pubid to user"""

from alembic import op

revision = "3bae642f2b36"
down_revision = "9c0efdf762a6"


def upgrade():
op.add_column("user", sa.Column("pubid", sa.Text(), nullable=True))
op.create_unique_constraint(op.f("uq__user__pubid"), "user", ["pubid"])


def downgrade():
op.drop_constraint(op.f("uq__user__pubid"), "user", type_="unique")
op.drop_column("user", "pubid")
7 changes: 7 additions & 0 deletions h/models/user.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import datetime
import re
from functools import partial
from typing import TYPE_CHECKING

import sqlalchemy as sa
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.ext.hybrid import Comparator, hybrid_property

from h import pubid
from h.db import Base
from h.exceptions import InvalidUserId
from h.models import helpers
Expand Down Expand Up @@ -158,6 +160,11 @@ def __table_args__(cls): # pylint:disable=no-self-argument

id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)

#: A publicly visible unique identifier for the user
pubid = sa.Column(
sa.Text(), default=partial(pubid.generate, 12), unique=True, nullable=True
)

#: Username as chosen by the user on registration
_username = sa.Column("username", sa.UnicodeText(), nullable=False)

Expand Down

0 comments on commit 420846d

Please sign in to comment.