Пример #1
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('site_vars')
    # ### end Alembic commands ###
    op.alter_column('artpieces',
                    'art',
                    new_column_name='art_encoding',
                    type_=sa.JSON(),
                    postgresql_using='art::json',
                    nullable=False)
    op.alter_column('artpieces',
                    'picture',
                    new_column_name='raw_image',
                    nullable=True)
    op.alter_column('artpieces',
                    'status',
                    new_column_name='submission_status',
                    nullable=False)
    op.alter_column('artpieces', 'title', nullable=False)
    op.alter_column('artpieces', 'submit_date', nullable=False)

    with session_scope() as session:
        artpieces = session.query(ArtpieceModel).filter(
            ArtpieceModel.raw_image == None).all()
        for artpiece in artpieces:
            artpiece.raw_image = decode_art_to_image(artpiece.art,
                                                     COLOR_SCHEME)

    op.alter_column('artpieces', 'raw_image', nullable=False)
Пример #2
0
def upgrade():
    # create the users table and the artpieces.user_id column
    UserModel.__table__.create(op.get_bind())
    op.add_column(
        'artpieces',
        sa.Column('user_id',
                  sa.Integer,
                  sa.ForeignKey('users.id'),
                  nullable=True))

    # create users from unique email addresses
    with session_scope() as session:
        artpieces_with_unique_email = (session.query(
            ArtpieceModel.email,
            func.min(ArtpieceModel.submit_date).label('submit_date')).group_by(
                ArtpieceModel.email))
        users = {
            artpiece.email: UserModel(email=artpiece.email,
                                      created_at=artpiece.submit_date,
                                      verified=True)
            for artpiece in artpieces_with_unique_email
        }
        session.add_all(users.values())

        # set artpiece user(/creator) based on email address
        for artpiece in session.query(ArtpieceModel):
            artpiece.user = users[artpiece.email]

    op.alter_column('artpieces', 'user_id', nullable=False)
    # don't need email now that user relationship is set up
    op.drop_column('artpieces', 'email')
def downgrade():
    with session_scope() as session:
        artpieces = session.query(ArtpieceModel).all()
        colors = session.query(BacterialColorModel).all()
        color_ids_to_names = {str(color.id): color.name for color in colors}
        color_ids_to_names = replace_color_names(color_ids_to_names)
        for artpiece in artpieces:
            artpiece.art = migrate_colors(artpiece.art, color_ids_to_names)
def upgrade():
    with session_scope() as session:
        artpieces = session.query(ArtpieceModel).all()
        colors = session.query(BacterialColorModel).all()
        color_names_to_ids = {color.name: str(color.id) for color in colors}
        color_names_to_ids = extend_color_names_to_ids(color_names_to_ids)
        # replace art color names with ids
        for artpiece in artpieces:
            artpiece.art = migrate_colors(artpiece.art, color_names_to_ids)
Пример #5
0
def upgrade():
    op.add_column('artpieces', sa.Column('confirmed',
                                         sa.Boolean,
                                         nullable=True))

    with session_scope() as session:
        artpieces = session.query(ArtpieceModel).all()
        for artpiece in artpieces:
            artpiece.confirmed = True

    op.alter_column('artpieces', 'confirmed', nullable=False)
Пример #6
0
def downgrade():
    op.add_column('users', sa.Column('verified', sa.Boolean, nullable=True))

    with session_scope() as session:
        users = session.query(UserModel).all()
        for user in users:
            user.verified = True

    op.alter_column('users', 'verified', nullable=False)
    op.add_column(
        'emailfailures',
        sa.Column('user_id',
                  sa.Integer,
                  sa.ForeignKey('users.id'),
                  nullable=True))
Пример #7
0
def downgrade():
    op.add_column('artpieces', sa.Column('email', sa.String(50),
                                         nullable=True))

    # populate artpiece's email using user_id
    with session_scope() as session:
        users = {
            user.id: user.email
            for user in session.query(UserModel).all()
        }
        artpieces = session.query(ArtpieceModel).all()
        for artpiece in artpieces:
            artpiece.email = users[artpiece.user_id]

    op.alter_column('artpieces', 'email', nullable=False)
    op.drop_column('artpieces', 'user_id')

    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_users_email'), table_name='users')
    op.drop_table('users')
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('artpieces',
                  sa.Column('slug', sa.String(length=60), nullable=True))
    op.create_index(op.f('ix_artpieces_slug'),
                    'artpieces', ['slug'],
                    unique=True)
    # ### end Alembic commands ###
    with session_scope() as session:
        artpieces = session.query(ArtpieceModel).order_by(
            ArtpieceModel.submit_date.asc()).all()
        # create unique slugs
        slug_counts = dict()
        for artpiece in artpieces:
            slug = slugify(artpiece.title)
            count = (slug_counts.get(slug) or 0) + 1
            artpiece.slug = f'{slug}#{count}'
            slug_counts[slug] = count

    op.alter_column('artpieces', 'slug', nullable=False)