Script 24e9054d4155_fix_results_paths_py
[hide private]
[frames] | no frames]

Source Code for Script script-24e9054d4155_fix_results_paths_py

 1  """fix results paths 
 2   
 3  Revision ID: 24e9054d4155 
 4  Revises: 465202bfb9ce 
 5  Create Date: 2018-03-23 23:42:26.434785 
 6   
 7  """ 
 8   
 9  # revision identifiers, used by Alembic. 
10  revision = '24e9054d4155' 
11  down_revision = '465202bfb9ce' 
12   
13  from alembic import op 
14  import sqlalchemy as sa 
15   
16   
17 -def upgrade():
18 session = sa.orm.sessionmaker(bind=op.get_bind())() 19 20 op.add_column('build', sa.Column('result_dir', sa.Text(), nullable=False, server_default='')) 21 op.add_column('build_chroot', sa.Column('result_dir', sa.Text(), nullable=True, server_default='')) 22 23 # Note that there are old builddirs on backend that do not conform to 00123456-package_name naming 24 # they come from era before dist-git, hence SELECT CASE WHEN build_chroot.git_hash is not NULL AND build_chroot.git_hash != '' 25 session.execute(""" 26 UPDATE build_chroot AS updated_build_chroot SET 27 result_dir=(SELECT CASE WHEN build_chroot.git_hash is not NULL AND build_chroot.git_hash != '' 28 THEN concat(lpad(CAST(build.id AS text), 8, '0'), '-', package.name) 29 ELSE regexp_replace((regexp_split_to_array(build.pkgs, '/'))[array_length(regexp_split_to_array(build.pkgs, '/'), 1)], '.src.rpm$', '') END 30 FROM build_chroot JOIN build ON build.id = build_chroot.build_id JOIN package ON build.package_id = package.id 31 WHERE updated_build_chroot.build_id = build_chroot.build_id AND updated_build_chroot.mock_chroot_id = build_chroot.mock_chroot_id AND 32 build.results is not NULL AND build.results != ''); 33 """) 34 session.execute("UPDATE build_chroot SET result_dir = '' WHERE result_dir IS NULL;") 35 session.execute("ALTER TABLE build_chroot ALTER COLUMN result_dir SET NOT NULL;") 36 session.execute("UPDATE build SET result_dir=lpad(CAST(build.id AS text), 8, '0') WHERE build.results is not NULL and build.results != '';")
37
38 -def downgrade():
39 op.drop_column('build', 'result_dir') 40 op.drop_column('build_chroot', 'result_dir')
41