"""Add column for profile picture type to User

Revision ID: f37d509e221c
Revises: c997dc927fbc
Create Date: 2020-09-04 15:43:18.413156
"""

import sqlalchemy as sa
from alembic import op

from indico.core.db.sqlalchemy import PyIntEnum
from indico.modules.users.models.users import ProfilePictureSource


# revision identifiers, used by Alembic.
revision = 'f37d509e221c'
down_revision = 'c997dc927fbc'
branch_labels = None
depends_on = None


def upgrade():
    op.add_column('users',
                  sa.Column('picture_source', PyIntEnum(ProfilePictureSource), nullable=False, server_default='0'),
                  schema='users')
    op.alter_column('users', 'picture_source', server_default=None, schema='users')
    op.execute('UPDATE users.users SET picture_source = 3 WHERE picture IS NOT NULL')


def downgrade():
    op.drop_column('users', 'picture_source', schema='users')

"""Add column for profile picture type to User

Revision ID: f37d509e221c
Revises: c997dc927fbc
Create Date: 2020-09-04 15:43:18.413156
"""

from enum import Enum

import sqlalchemy as sa
from alembic import op

from indico.core.db.sqlalchemy import PyIntEnum


# revision identifiers, used by Alembic.
revision = 'f37d509e221c'
down_revision = 'c997dc927fbc'
branch_labels = None
depends_on = None


class _ProfilePictureSource(int, Enum):
    standard = 0
    identicon = 1
    gravatar = 2
    custom = 3


def upgrade():
    op.add_column('users',
                  sa.Column('picture_source', PyIntEnum(_ProfilePictureSource), nullable=False, server_default='0'),
                  schema='users')
    op.alter_column('users', 'picture_source', server_default=None, schema='users')
    op.execute('UPDATE users.users SET picture_source = 3 WHERE picture IS NOT NULL')


def downgrade():
    op.drop_column('users', 'picture_source', schema='users')

Use embedded enum in alembic revision
Use embedded enum in alembic revision

Unlikely to matter here but like this it will work correctly even in a
future where someone may add new sources to the original enum (in that
case this particular revision should not add those newer ones, which
would be the case when using the imported enum)
