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   
18  import sys, os 
19  sys.path.append(os.getcwd()) 
20  from coprs.models import MockChroot, DistGitBranch 
21  from coprs.helpers import chroot_to_branch 
22  from coprs.logic.coprs_logic import BranchesLogic 
23   
24 -def upgrade():
25 bind = op.get_bind() 26 Session = sessionmaker() 27 session = Session(bind=bind) 28 29 op.create_table('dist_git_branch', 30 sa.Column('name', sa.String(length=50), nullable=False), 31 sa.PrimaryKeyConstraint('name') 32 ) 33 34 # Nullable at this point. 35 op.add_column(u'mock_chroot', sa.Column('distgit_branch_name', sa.String(length=50), nullable=True)) 36 op.create_foreign_key(None, 'mock_chroot', 'dist_git_branch', ['distgit_branch_name'], ['name']) 37 38 for chroot in session.query(MockChroot).all(): 39 # Pick the predefined default. 40 branch = chroot_to_branch(chroot.name) 41 chroot.distgit_branch = BranchesLogic.get_or_create(branch, session) 42 session.add(chroot.distgit_branch) 43 session.add(chroot) 44 45 session.commit() 46 47 # not nulllable since now.. 48 op.alter_column('mock_chroot', 'distgit_branch_name', 49 existing_type=sa.VARCHAR(length=50), 50 nullable=False)
51 52
53 -def downgrade():
54 op.drop_column(u'mock_chroot', 'distgit_branch_name') 55 op.drop_table('dist_git_branch')
56