Skip to content

Commit 3e0a3be

Browse files
authored
Merge pull request #49 from bugout-dev/web3-user-auth
Web3 user authentification
2 parents 66bebb8 + bd2ee0d commit 3e0a3be

File tree

11 files changed

+763
-240
lines changed

11 files changed

+763
-240
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""Web3 users
2+
3+
Revision ID: 6bc0ee79a3ce
4+
Revises: 6ae8af4e1863
5+
Create Date: 2022-09-14 10:41:57.439633
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '6bc0ee79a3ce'
14+
down_revision = '6ae8af4e1863'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.add_column('users', sa.Column('web3_address', sa.String(), nullable=True))
22+
op.alter_column('users', 'email',
23+
existing_type=sa.VARCHAR(),
24+
nullable=True)
25+
op.alter_column('users', 'normalized_email',
26+
existing_type=sa.VARCHAR(),
27+
nullable=True)
28+
op.alter_column('users', 'password_hash',
29+
existing_type=sa.VARCHAR(),
30+
nullable=True)
31+
op.drop_index('uq_users_normalized_email_no_application_id', table_name='users')
32+
op.drop_index('uq_users_username_no_application_id', table_name='users')
33+
op.create_index(op.f('ix_users_web3_address'), 'users', ['web3_address'], unique=False)
34+
op.create_index('uq_users_normalized_email', 'users', ['normalized_email'], unique=True, postgresql_where=sa.text('application_id IS NULL'))
35+
op.create_index('uq_users_username', 'users', ['username'], unique=True, postgresql_where=sa.text('application_id IS NULL'))
36+
op.create_index('uq_users_web3_address', 'users', ['web3_address'], unique=True, postgresql_where=sa.text('application_id IS NULL'))
37+
op.create_index('uq_users_web3_address_application_id', 'users', ['web3_address', 'application_id'], unique=True, postgresql_where=sa.text('application_id IS NOT NULL'))
38+
op.drop_column('users', 'auth_type')
39+
40+
op.execute("ALTER TABLE users ADD CONSTRAINT ck_users_normalized_email_password_hash CHECK ((normalized_email IS NULL) OR (normalized_email IS NOT NULL AND password_hash IS NOT NULL));")
41+
# ### end Alembic commands ###
42+
43+
44+
def downgrade():
45+
# ### commands auto generated by Alembic - please adjust! ###
46+
op.add_column('users', sa.Column('auth_type', sa.VARCHAR(length=50), autoincrement=False, nullable=False))
47+
op.drop_index('uq_users_web3_address_application_id', table_name='users', postgresql_where=sa.text('application_id IS NOT NULL'))
48+
op.drop_index('uq_users_web3_address', table_name='users', postgresql_where=sa.text('application_id IS NULL'))
49+
op.drop_index('uq_users_username', table_name='users', postgresql_where=sa.text('application_id IS NULL'))
50+
op.drop_index('uq_users_normalized_email', table_name='users', postgresql_where=sa.text('application_id IS NULL'))
51+
op.drop_index(op.f('ix_users_web3_address'), table_name='users')
52+
op.create_index('uq_users_username_no_application_id', 'users', ['username'], unique=False)
53+
op.create_index('uq_users_normalized_email_no_application_id', 'users', ['normalized_email'], unique=False)
54+
op.alter_column('users', 'password_hash',
55+
existing_type=sa.VARCHAR(),
56+
nullable=False)
57+
op.alter_column('users', 'normalized_email',
58+
existing_type=sa.VARCHAR(),
59+
nullable=False)
60+
op.alter_column('users', 'email',
61+
existing_type=sa.VARCHAR(),
62+
nullable=False)
63+
op.drop_column('users', 'web3_address')
64+
65+
op.drop_constraint("ck_users_normalized_email_password_hash", table_name="users")
66+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)