Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web3 user authentification #49

Merged
merged 15 commits into from Oct 17, 2022
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 ###