Script 2fa80e062525_add_mock_chroots_py
|
|
1 """empty message
2
3 Revision ID: 2fa80e062525
4 Revises: 2e30169e58ce
5 Create Date: 2013-01-14 09:04:42.768432
6
7 """
8
9
10 revision = '2fa80e062525'
11 down_revision = '2e30169e58ce'
12
13 from alembic import op
14 import sqlalchemy as sa
15
17
18 op.create_table('mock_chroot',
19 sa.Column('id', sa.Integer(), nullable=False),
20 sa.Column('os_release', sa.String(length=50), nullable=False),
21 sa.Column('os_version', sa.String(length=50), nullable=False),
22 sa.Column('arch', sa.String(length=50), nullable=False),
23 sa.Column('is_active', sa.Boolean(), nullable=False),
24 sa.PrimaryKeyConstraint('id')
25 )
26 op.create_table('copr_chroot',
27 sa.Column('mock_chroot_id', sa.Integer(), nullable=False),
28 sa.Column('copr_id', sa.Integer(), nullable=False),
29 sa.ForeignKeyConstraint(['copr_id'], ['copr.id'], ),
30 sa.ForeignKeyConstraint(['mock_chroot_id'], ['mock_chroot.id'], ),
31 sa.PrimaryKeyConstraint('mock_chroot_id', 'copr_id')
32 )
33
34
35
36
37 session = sa.orm.sessionmaker(bind=op.get_bind())()
38 metadata = sa.MetaData()
39
40 coprs_table = sa.Table('copr', metadata, sa.Column('chroots', sa.Text()), sa.Column('id', sa.Integer()))
41
42 chroots = set()
43 for cs in op.get_bind().execute(sa.select([coprs_table.c.chroots])):
44 chroots.update(set(cs[0].split(' ')))
45 chroots = list(chroots)
46
47 mc_table = sa.Table('mock_chroot', metadata,
48 sa.Column('id', sa.Integer(), nullable=False),
49 sa.Column('os_release', sa.String(length=50), nullable=False),
50 sa.Column('os_version', sa.String(length=50), nullable=False),
51 sa.Column('arch', sa.String(length=50), nullable=False),
52 sa.Column('is_active', sa.Boolean(), nullable=False),
53 )
54 cc_table = sa.Table('copr_chroot', metadata,
55 sa.Column('mock_chroot_id', sa.Integer(), nullable=False),
56 sa.Column('copr_id', sa.Integer(), nullable=False),
57 )
58 for i, c in enumerate(chroots):
59 sc = c.split('-')
60 op.bulk_insert(mc_table, [{'id': i + 1, 'os_release': sc[0], 'os_version': sc[1], 'arch': sc[2], 'is_active': True}])
61
62 for row in op.get_bind().execute(sa.select([coprs_table.c.id, coprs_table.c.chroots])):
63 for c in row[1].split(' '):
64 op.bulk_insert(cc_table, [{'mock_chroot_id': chroots.index(c) + 1, 'copr_id': row[0]}])
65
66
67 if op.get_bind().dialect.name == 'sqlite':
68 op.rename_table('copr', 'copr_1')
69 op.create_table('copr',
70 sa.Column('id', sa.Integer(), nullable=False),
71 sa.Column('name', sa.String(length=100), nullable=False),
72 sa.Column('repos', sa.Text(), nullable=True),
73 sa.Column('created_on', sa.Integer(), nullable=True),
74 sa.Column('build_count', sa.Integer(), nullable=True),
75 sa.Column('owner_id', sa.Integer(), nullable=True),
76 sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ),
77 sa.PrimaryKeyConstraint('id')
78 )
79 op.execute('INSERT INTO copr SELECT id,name,repos,created_on,build_count,owner_id FROM copr_1')
80 op.drop_table('copr_1')
81 else:
82 op.drop_column('copr', u'chroots')
83
84
85
87
88 op.add_column('copr', sa.Column(u'chroots', sa.TEXT(), nullable=False, server_default='fedora-rawhide-x86_64'))
89 op.drop_table('copr_chroot')
90 op.drop_table('mock_chroot')
91
92