Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : enter_the_matrix
---------------------------------------------------------------
commit f771778334459de37009fa066f164855a127a13e
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu Nov 14 14:49:11 2013 +0100
add migration script - add table build_chroot
---------------------------------------------------------------
.../versions/52e53e7b413e_add_build_chroot.py | 70 ++++++++++++++++++++
1 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/coprs_frontend/alembic/versions/52e53e7b413e_add_build_chroot.py
b/coprs_frontend/alembic/versions/52e53e7b413e_add_build_chroot.py
new file mode 100644
index 0000000..afb0cfb
--- /dev/null
+++ b/coprs_frontend/alembic/versions/52e53e7b413e_add_build_chroot.py
@@ -0,0 +1,70 @@
+""" Add BuildChroot table
+
+Revision ID: 52e53e7b413e
+Revises: 246fd2dbf398
+Create Date: 2013-11-14 09:00:43.787717
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '52e53e7b413e'
+down_revision = '246fd2dbf398'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+ ### commands auto generated by Alembic - please adjust! ###
+ op.create_table('build_chroot',
+ sa.Column('mock_chroot_id', sa.Integer(), nullable=False),
+ sa.Column('build_id', sa.Integer(), nullable=False),
+ sa.Column('status', sa.Integer(), nullable=True),
+ sa.ForeignKeyConstraint(['build_id'], ['build.id'], ),
+ sa.ForeignKeyConstraint(['mock_chroot_id'], ['mock_chroot.id'], ),
+ sa.PrimaryKeyConstraint('mock_chroot_id', 'build_id')
+ )
+
+ #transfer data from build table to build_chroot
+ session = sa.orm.sessionmaker(bind=op.get_bind())()
+ metadata = sa.MetaData()
+ # just what we need of copr table
+ build_table = sa.Table('build', metadata,
+ sa.Column('chroots', sa.Text()),
+ sa.Column('status', sa.Integer()),
+ sa.Column('id', sa.Integer()),
+ )
+
+ mc_table = sa.Table('mock_chroot', metadata,
+ sa.Column('id', sa.Integer(), nullable=False),
+ sa.Column('os_release', sa.String(length=50), nullable=False),
+ sa.Column('os_version', sa.String(length=50), nullable=False),
+ sa.Column('arch', sa.String(length=50), nullable=False),
+ sa.Column('is_active', sa.Boolean(), nullable=False),
+ )
+ bc_table = sa.Table('build_chroot', metadata,
+ sa.Column('mock_chroot_id', sa.Integer(), nullable=False),
+ sa.Column('build_id', sa.Integer(), nullable=False),
+ sa.Column('status', sa.Integer(), nullable=True),
+ )
+ for row in op.get_bind().execute(sa.select([build_table.c.id, build_table.c.chroots,
build_table.c.status])):
+ for c in row[1].split(' '):
+ chroot_array = c.split('-')
+ for row2 in (op.get_bind().execute(sa.select([mc_table.c.id], sa.and_(
+ mc_table.c.os_release == op.inline_literal(chroot_array[0]),
+ mc_table.c.os_version == op.inline_literal(chroot_array[1]),
+ mc_table.c.arch == op.inline_literal(chroot_array[2]),
+ )))): # should be just one row
+ op.bulk_insert(bc_table, [{'mock_chroot_id': row2[0],
'build_id': row[0], 'status': row[2]}])
+
+ # drop old columns
+ op.drop_column(u'build', u'status')
+ op.drop_column(u'build', u'chroots')
+
+
+def downgrade():
+ print "Why are you downgrading? You will just lost some data."
+ op.add_column(u'build', sa.Column(u'chroots', sa.TEXT(),
nullable=False))
+ op.add_column(u'build', sa.Column(u'status', sa.INTEGER(),
nullable=True))
+ op.drop_table('build_chroot')
+ print "Data about chroots for builds are gone!"