Module bf4b5dc74740_map_mock_croots_to_dits_git_branch
[hide private]
[frames] | no frames]

Source Code for Module bf4b5dc74740_map_mock_croots_to_dits_git_branch

 1  """map mock croots to dits-git branch 
 2   
 3  Revision ID: bf4b5dc74740 
 4  Revises: 38ea34def9a 
 5  Create Date: 2017-05-19 07:55:05.743045 
 6   
 7  """ 
 8   
 9  # revision identifiers, used by Alembic. 
10  revision = 'bf4b5dc74740' 
11  down_revision = '38ea34def9a' 
12   
13  from alembic import op 
14  import sqlalchemy as sa 
15   
16  from sqlalchemy.orm import sessionmaker 
17  from coprs.models import MockChroot, DistGitBranch 
18  from coprs.helpers import chroot_to_branch 
19  from coprs.logic.coprs_logic import BranchesLogic 
20   
21 -def upgrade():
22 bind = op.get_bind() 23 Session = sessionmaker() 24 session = Session(bind=bind) 25 26 op.create_table('dist_git_branch', 27 sa.Column('name', sa.String(length=50), nullable=False), 28 sa.PrimaryKeyConstraint('name') 29 ) 30 31 # Nullable at this point. 32 op.add_column(u'mock_chroot', sa.Column('distgit_branch_name', sa.String(length=50), nullable=True)) 33 op.create_foreign_key(None, 'mock_chroot', 'dist_git_branch', ['distgit_branch_name'], ['name']) 34 35 for chroot in session.query(MockChroot).all(): 36 # Pick the predefined default. 37 branch = chroot_to_branch(chroot.name) 38 chroot.distgit_branch = BranchesLogic.get_or_create(branch, session) 39 session.add(chroot.distgit_branch) 40 session.add(chroot) 41 42 session.commit() 43 44 # not nulllable since now.. 45 op.alter_column('mock_chroot', 'distgit_branch_name', 46 existing_type=sa.VARCHAR(length=50), 47 nullable=False)
48 49
50 -def downgrade():
51 op.drop_column(u'mock_chroot', 'distgit_branch_name') 52 op.drop_table('dist_git_branch')
53