Script 52e53e7b413e_add_build_chroot_py
[hide private]
[frames] | no frames]

Source Code for Script script-52e53e7b413e_add_build_chroot_py

 1  """ Add BuildChroot table 
 2   
 3  Revision ID: 52e53e7b413e 
 4  Revises: 246fd2dbf398 
 5  Create Date: 2013-11-14 09:00:43.787717 
 6   
 7  """ 
 8   
 9  # revision identifiers, used by Alembic. 
10  revision = "52e53e7b413e" 
11  down_revision = "246fd2dbf398" 
12   
13  from alembic import op 
14  import sqlalchemy as sa 
15   
16   
17 -def upgrade():
18 ### commands auto generated by Alembic - please adjust! ### 19 op.create_table("build_chroot", 20 sa.Column("mock_chroot_id", sa.Integer(), nullable=False), 21 sa.Column("build_id", sa.Integer(), nullable=False), 22 sa.Column("status", sa.Integer(), nullable=True), 23 sa.ForeignKeyConstraint(["build_id"], ["build.id"], ), 24 sa.ForeignKeyConstraint( 25 ["mock_chroot_id"], ["mock_chroot.id"], ), 26 sa.PrimaryKeyConstraint("mock_chroot_id", "build_id") 27 ) 28 29 # transfer data from build table to build_chroot 30 metadata = sa.MetaData() 31 # just what we need of copr table 32 build_table = sa.Table("build", metadata, 33 sa.Column("chroots", sa.Text()), 34 sa.Column("status", sa.Integer()), 35 sa.Column("id", sa.Integer()), 36 ) 37 38 mc_table = sa.Table("mock_chroot", metadata, 39 sa.Column("id", sa.Integer(), nullable=False), 40 sa.Column( 41 "os_release", sa.String(length=50), nullable=False), 42 sa.Column( 43 "os_version", sa.String(length=50), nullable=False), 44 sa.Column( 45 "arch", sa.String(length=50), nullable=False), 46 sa.Column("is_active", sa.Boolean(), nullable=False), 47 ) 48 bc_table = sa.Table("build_chroot", metadata, 49 sa.Column( 50 "mock_chroot_id", sa.Integer(), nullable=False), 51 sa.Column("build_id", sa.Integer(), nullable=False), 52 sa.Column("status", sa.Integer(), nullable=True), 53 ) 54 for row in op.get_bind().execute(sa.select([build_table.c.id, build_table.c.chroots, build_table.c.status])): 55 for c in row[1].split(" "): 56 chroot_array = c.split("-") 57 for row2 in (op.get_bind().execute(sa.select([mc_table.c.id], sa.and_( 58 mc_table.c.os_release == op.inline_literal(chroot_array[0]), 59 mc_table.c.os_version == op.inline_literal(chroot_array[1]), 60 mc_table.c.arch == op.inline_literal(chroot_array[2]), 61 )))): # should be just one row 62 op.bulk_insert( 63 bc_table, [{"mock_chroot_id": row2[0], "build_id": row[0], "status": row[2]}]) 64 65 # drop old columns 66 op.drop_column(u"build", u"status") 67 op.drop_column(u"build", u"chroots")
68 69
70 -def downgrade():
71 print("Why are you downgrading? You will just lost some data.") 72 op.add_column(u"build", sa.Column(u"chroots", sa.TEXT(), nullable=False)) 73 op.add_column(u"build", sa.Column(u"status", sa.INTEGER(), nullable=True)) 74 op.drop_table("build_chroot") 75 print("Data about chroots for builds are gone!")
76