<commit_before>"""uploaded_images scema and data migraion

Revision ID: 12fe8d110f7
Revises: <PASSWORD>
Create Date: 2015-08-07 14:12:11.893524

"""

# revision identifiers, used by Alembic.
revision = '1<PASSWORD>1<PASSWORD>'
down_revision = '<PASSWORD>'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import UUID


def upgrade():
    # Start migrating schema
    op.drop_constraint(
        name='uploaded_images_pkey',
        table_name='uploaded_images',
        type_='primary',
    )
    op.alter_column(
        'uploaded_images',
        'uid',
        nullable=True,
    )
    op.add_column(
        'uploaded_images',
        sa.Column('id', sa.Integer, primary_key=True)
    )
    op.add_column(
        'uploaded_images',
        sa.Column('ext', sa.VARCHAR(), nullable=True)
    )
    op.add_column(
        'uploaded_images',
        sa.Column('name', UUID(), nullable=True)
    )
    op.create_primary_key(
        name='uploaded_images_pkey',
        table_name='uploaded_images',
        cols=['id']
    )
    op.create_unique_constraint(
        name='uploaded_images_name_ext_img_category_key',
        source='uploaded_images',
        local_cols=['name', 'ext', 'img_category'],
    )
    # Migrate data:
    op.execute(
        'update uploaded_images set (ext, name) = '
        '(split_part(uid, \'.\', 2), split_part(uid, \'.\', 1)::uuid);'
    )
    # Set notnull and drop unnecessary columns:
    op.alter_column(
        'uploaded_images',
        'ext',
        nullable=False,
    )
    op.alter_column(
        'uploaded_images',<commit_msg>migration now uses GUID type<commit_after>"""uploaded_images scema and data migraion

Revision ID: 12fe8d110f7
Revises: <PASSWORD>
Create Date: 2015-08-07 14:12:11.893524

"""

# revision identifiers, used by Alembic.
revision = '<PASSWORD>'
down_revision = '<PASSWORD>'

from alembic import op
import sqlalchemy as sa
from project.lib.orm.types import GUID


def upgrade():
    # Start migrating schema
    op.drop_constraint(
        name='uploaded_images_pkey',
        table_name='uploaded_images',
        type_='primary',
    )
    op.alter_column(
        'uploaded_images',
        'uid',
        nullable=True,
    )
    op.add_column(
        'uploaded_images',
        sa.Column('id', sa.Integer, primary_key=True)
    )
    op.add_column(
        'uploaded_images',
        sa.Column('ext', sa.VARCHAR(), nullable=True)
    )
    op.add_column(
        'uploaded_images',
        sa.Column('name', GUID(), nullable=True)
    )
    op.create_primary_key(
        name='uploaded_images_pkey',
        table_name='uploaded_images',
        cols=['id']
    )
    op.create_unique_constraint(
        name='uploaded_images_name_ext_img_category_key',
        source='uploaded_images',
        local_cols=['name', 'ext', 'img_category'],
    )
    # Migrate data:
    op.execute(
        'update uploaded_images set (ext, name) = '
        '(split_part(uid, \'.\', 2), split_part(uid, \'.\', 1)::uuid);'
    )
    # Set notnull and drop unnecessary columns:
    op.alter_column(
        'uploaded_images',
        'ext',
        nullable=False,
    )
    op.alter_column(
        'uploaded_images',
{'fraction_non_alphanumeric': 0.12912258867454884, 'fraction_numerical': 0.018668326073428748, 'mean_word_length': 2.721064814814815, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1697832', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1077, 'n_words': 197}