Skip to content

Commit

Permalink
Merge pull request #49 from bugout-dev/web3-user-auth
Browse files Browse the repository at this point in the history
Web3 user authentification
  • Loading branch information
zomglings committed Oct 17, 2022
2 parents 66bebb8 + bd2ee0d commit 3e0a3be
Show file tree
Hide file tree
Showing 11 changed files with 763 additions and 240 deletions.
66 changes: 66 additions & 0 deletions alembic/versions/6bc0ee79a3ce_web3_users.py
@@ -0,0 +1,66 @@
"""Web3 users
Revision ID: 6bc0ee79a3ce
Revises: 6ae8af4e1863
Create Date: 2022-09-14 10:41:57.439633
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '6bc0ee79a3ce'
down_revision = '6ae8af4e1863'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('users', sa.Column('web3_address', sa.String(), nullable=True))
op.alter_column('users', 'email',
existing_type=sa.VARCHAR(),
nullable=True)
op.alter_column('users', 'normalized_email',
existing_type=sa.VARCHAR(),
nullable=True)
op.alter_column('users', 'password_hash',
existing_type=sa.VARCHAR(),
nullable=True)
op.drop_index('uq_users_normalized_email_no_application_id', table_name='users')
op.drop_index('uq_users_username_no_application_id', table_name='users')
op.create_index(op.f('ix_users_web3_address'), 'users', ['web3_address'], unique=False)
op.create_index('uq_users_normalized_email', 'users', ['normalized_email'], unique=True, postgresql_where=sa.text('application_id IS NULL'))
op.create_index('uq_users_username', 'users', ['username'], unique=True, postgresql_where=sa.text('application_id IS NULL'))
op.create_index('uq_users_web3_address', 'users', ['web3_address'], unique=True, postgresql_where=sa.text('application_id IS NULL'))
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'))
op.drop_column('users', 'auth_type')

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));")
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('users', sa.Column('auth_type', sa.VARCHAR(length=50), autoincrement=False, nullable=False))
op.drop_index('uq_users_web3_address_application_id', table_name='users', postgresql_where=sa.text('application_id IS NOT NULL'))
op.drop_index('uq_users_web3_address', table_name='users', postgresql_where=sa.text('application_id IS NULL'))
op.drop_index('uq_users_username', table_name='users', postgresql_where=sa.text('application_id IS NULL'))
op.drop_index('uq_users_normalized_email', table_name='users', postgresql_where=sa.text('application_id IS NULL'))
op.drop_index(op.f('ix_users_web3_address'), table_name='users')
op.create_index('uq_users_username_no_application_id', 'users', ['username'], unique=False)
op.create_index('uq_users_normalized_email_no_application_id', 'users', ['normalized_email'], unique=False)
op.alter_column('users', 'password_hash',
existing_type=sa.VARCHAR(),
nullable=False)
op.alter_column('users', 'normalized_email',
existing_type=sa.VARCHAR(),
nullable=False)
op.alter_column('users', 'email',
existing_type=sa.VARCHAR(),
nullable=False)
op.drop_column('users', 'web3_address')

op.drop_constraint("ck_users_normalized_email_password_hash", table_name="users")
# ### end Alembic commands ###

0 comments on commit 3e0a3be

Please sign in to comment.