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
16
18
19 op.create_table("mock_chroot",
20 sa.Column("id", sa.Integer(), nullable=False),
21 sa.Column(
22 "os_release", sa.String(length=50), nullable=False),
23 sa.Column(
24 "os_version", sa.String(length=50), nullable=False),
25 sa.Column("arch", sa.String(length=50), nullable=False),
26 sa.Column("is_active", sa.Boolean(), nullable=False),
27 sa.PrimaryKeyConstraint("id")
28 )
29 op.create_table("copr_chroot",
30 sa.Column("mock_chroot_id", sa.Integer(), nullable=False),
31 sa.Column("copr_id", sa.Integer(), nullable=False),
32 sa.ForeignKeyConstraint(["copr_id"], ["copr.id"], ),
33 sa.ForeignKeyConstraint(
34 ["mock_chroot_id"], ["mock_chroot.id"], ),
35 sa.PrimaryKeyConstraint("mock_chroot_id", "copr_id")
36 )
37
38
39
40 metadata = sa.MetaData()
41
42 coprs_table = sa.Table("copr", metadata, sa.Column(
43 "chroots", sa.Text()), sa.Column("id", sa.Integer()))
44
45 chroots = set()
46 for cs in op.get_bind().execute(sa.select([coprs_table.c.chroots])):
47 chroots.update(set(cs[0].split(" ")))
48 chroots = list(chroots)
49
50 mc_table = sa.Table("mock_chroot", metadata,
51 sa.Column("id", sa.Integer(), nullable=False),
52 sa.Column(
53 "os_release", sa.String(length=50), nullable=False),
54 sa.Column(
55 "os_version", sa.String(length=50), nullable=False),
56 sa.Column(
57 "arch", sa.String(length=50), nullable=False),
58 sa.Column("is_active", sa.Boolean(), nullable=False),
59 )
60 cc_table = sa.Table("copr_chroot", metadata,
61 sa.Column(
62 "mock_chroot_id", sa.Integer(), nullable=False),
63 sa.Column("copr_id", sa.Integer(), nullable=False),
64 )
65
66 for i, c in enumerate(chroots):
67 sc = c.split("-")
68 op.bulk_insert(mc_table, [
69 {"id": i + 1,
70 "os_release": sc[0],
71 "os_version": sc[1],
72 "arch": sc[2],
73 "is_active": True}])
74
75
76 for row in op.get_bind().execute(sa.select([coprs_table.c.id, coprs_table.c.chroots])):
77 for c in row[1].split(" "):
78 op.bulk_insert(
79 cc_table, [{"mock_chroot_id": chroots.index(c) + 1,
80 "copr_id": row[0]}])
81
82 if op.get_bind().dialect.name == "sqlite":
83 op.rename_table("copr", "copr_1")
84 op.create_table("copr",
85 sa.Column("id", sa.Integer(), nullable=False),
86 sa.Column(
87 "name", sa.String(length=100), nullable=False),
88 sa.Column("repos", sa.Text(), nullable=True),
89 sa.Column("created_on", sa.Integer(), nullable=True),
90 sa.Column("build_count", sa.Integer(), nullable=True),
91 sa.Column("owner_id", sa.Integer(), nullable=True),
92 sa.ForeignKeyConstraint(["owner_id"], ["user.id"], ),
93 sa.PrimaryKeyConstraint("id")
94 )
95 op.execute(
96 "INSERT INTO copr SELECT id,name,repos,created_on,build_count,owner_id FROM copr_1")
97 op.drop_table("copr_1")
98 else:
99 op.drop_column("copr", u"chroots")
100
101
102
104
105 op.add_column("copr", sa.Column(
106 u"chroots", sa.TEXT(), nullable=False,
107 server_default="fedora-rawhide-x86_64"))
108
109 op.drop_table("copr_chroot")
110 op.drop_table("mock_chroot")
111
112