mirror of
https://github.com/simple-login/app.git
synced 2024-09-20 15:05:59 +08:00
add User.alternative_id column
This commit is contained in:
parent
f525c951c6
commit
fdc23b3107
|
@ -350,6 +350,17 @@ class User(db.Model, ModelMixin, UserMixin, PasswordOracle):
|
|||
db.Boolean, default=False, nullable=False, server_default="0"
|
||||
)
|
||||
|
||||
# used for flask-login as an "alternative token"
|
||||
# cf https://flask-login.readthedocs.io/en/latest/#alternative-tokens
|
||||
alternative_id = db.Column(db.String(128), unique=True, nullable=True)
|
||||
|
||||
# implement flask-login "alternative token"
|
||||
def get_id(self):
|
||||
if self.alternative_id:
|
||||
return self.alternative_id
|
||||
else:
|
||||
return str(self.id)
|
||||
|
||||
@classmethod
|
||||
def create(cls, email, name="", password=None, **kwargs):
|
||||
user: User = super(User, cls).create(email=email, name=name, **kwargs)
|
||||
|
|
34
migrations/versions/2021_101111_2fbcad5527d7_.py
Normal file
34
migrations/versions/2021_101111_2fbcad5527d7_.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 2fbcad5527d7
|
||||
Revises: 0b1c9ea11aef
|
||||
Create Date: 2021-10-11 11:17:46.750252
|
||||
|
||||
"""
|
||||
import sqlalchemy_utils
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '2fbcad5527d7'
|
||||
down_revision = '0b1c9ea11aef'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('users', sa.Column('alternative_id', sa.String(length=128), nullable=True))
|
||||
op.create_unique_constraint(None, 'users', ['alternative_id'])
|
||||
|
||||
# set alternative_id to id
|
||||
op.execute('UPDATE users SET alternative_id = id')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, 'users', type_='unique')
|
||||
op.drop_column('users', 'alternative_id')
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in a new issue