28 lines
848 B
Python
28 lines
848 B
Python
|
"""Backfill the namespace_user fields.
|
||
|
|
||
|
Revision ID: 3f4fe1194671
|
||
|
Revises: 6f2ecf5afcf
|
||
|
Create Date: 2014-09-24 14:29:45.192179
|
||
|
|
||
|
"""
|
||
|
|
||
|
# revision identifiers, used by Alembic.
|
||
|
revision = '3f4fe1194671'
|
||
|
down_revision = '6f2ecf5afcf'
|
||
|
|
||
|
from alembic import op
|
||
|
import sqlalchemy as sa
|
||
|
|
||
|
|
||
|
def upgrade(tables):
|
||
|
conn = op.get_bind()
|
||
|
conn.execute('update repository set namespace_user_id = (select id from user where user.username == repository.namespace) where namespace_user_id is NULL')
|
||
|
|
||
|
op.alter_column('repository', 'namespace_user_id', nullable=False)
|
||
|
op.create_index('repository_namespace_user_id_name', 'repository', ['namespace_user_id', 'name'], unique=True)
|
||
|
|
||
|
|
||
|
def downgrade(tables):
|
||
|
op.drop_index('repository_namespace_user_id_name', table_name='repository')
|
||
|
op.alter_column('repository', 'namespace_user_id', nullable=True)
|