Script 38f205566f20_make_data_in_copr_id_name_in_package__py
|
|
1 """make data in (copr_id, name) in package table unique, see Bug 1382243 - Multiple rows were found for one()
2 Assume that there are no two packages with the same name in the same copr both having some builds referencing them
3 (otherwise manual "rebinding" of the builds to just one of the packages is needed).
4
5 Revision ID: 38f205566f20
6 Revises: 15852f9e313f
7 Create Date: 2016-10-10 14:09:03.353726
8
9 """
10
11
12 revision = '38f205566f20'
13 down_revision = '15852f9e313f'
14
15 from alembic import op
16 import sqlalchemy as sa
17
18
20 bind = op.get_bind()
21 connection = bind.connect()
22 connection.execute("""
23 DELETE FROM package WHERE package.id NOT IN (SELECT DISTINCT package_id FROM build WHERE package_id IS NOT NULL) AND EXISTS (SELECT id FROM package AS package2 WHERE package2.copr_id=package.copr_id AND package2.name=package.name AND package2.id!=package.id);
24 """)
25 connection.close()
26
30