Script 57be43049e9b_added_columns_to_buildchroot_py
|
|
1 """added columns to BuildChroot
2
3 Revision ID: 57be43049e9b
4 Revises: 552455e5910e
5 Create Date: 2015-07-09 12:30:57.326992
6
7 """
8
9
10 revision = '57be43049e9b'
11 down_revision = '552455e5910e'
12
13 from alembic import op
14 import sqlalchemy as sa
15
16
18 op.add_column(u'build_chroot', sa.Column('ended_on', sa.Integer(), nullable=True))
19 op.add_column(u'build_chroot', sa.Column('started_on', sa.Integer(), nullable=True))
20
21 bind = op.get_bind()
22 connection = bind.connect()
23
24 m_build_table = sa.Table(
25 u"build",
26 sa.MetaData(),
27 sa.Column("id", sa.Integer, nullable=False),
28 sa.Column('ended_on', sa.Integer(), nullable=True),
29 sa.Column('started_on', sa.Integer(), nullable=True),
30 )
31 m_build_chroot_table = sa.Table(
32 u"build_chroot",
33 sa.MetaData(),
34 sa.Column("mock_chroot_id", sa.Integer, nullable=False),
35 sa.Column("build_id", sa.Integer),
36 sa.Column('ended_on', sa.Integer(), nullable=True),
37 sa.Column('started_on', sa.Integer(), nullable=True)
38 )
39
40 counter = 0
41 for build in connection.execute(m_build_table.select()):
42 connection.execute(
43 m_build_chroot_table.update()
44 .where(m_build_chroot_table.c.build_id == build.id)
45 .values(
46 started_on=build.started_on,
47 ended_on=build.ended_on,
48 )
49 )
50 counter += 1
51 if counter % 1000 == 0:
52 print("Processed: {} builds".format(counter))
53
54
56 op.drop_column(u'build_chroot', 'started_on')
57 op.drop_column(u'build_chroot', 'ended_on')
58