Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1316 from djmitche/bug2986
Update migration 037 and tests to work on Postgres Fixes ticket:2986
- Loading branch information
Showing
4 changed files
with
142 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
master/buildbot/test/unit/test_db_migrate_versions_037_buildrequests_builderid.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# This file is part of Buildbot. Buildbot is free software: you can | ||
# redistribute it and/or modify it under the terms of the GNU General Public | ||
# License as published by the Free Software Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright Buildbot Team Members | ||
|
||
import sqlalchemy as sa | ||
|
||
from buildbot.test.util import migration | ||
from twisted.trial import unittest | ||
|
||
|
||
class Migration(migration.MigrateTestMixin, unittest.TestCase): | ||
|
||
def setUp(self): | ||
return self.setUpMigrateTest() | ||
|
||
def tearDown(self): | ||
return self.tearDownMigrateTest() | ||
|
||
def test_migration(self): | ||
def setup_thd(conn): | ||
metadata = sa.MetaData() | ||
metadata.bind = conn | ||
|
||
builders = sa.Table( | ||
'builders', metadata, | ||
sa.Column('id', sa.Integer, primary_key=True), | ||
sa.Column('name', sa.Text, nullable=False), | ||
sa.Column('name_hash', sa.String(40), nullable=False), | ||
) | ||
builders.create() | ||
|
||
buildsets = sa.Table( | ||
'buildsets', metadata, | ||
sa.Column('id', sa.Integer, primary_key=True), | ||
sa.Column('external_idstring', sa.String(256)), | ||
sa.Column('reason', sa.String(256)), | ||
sa.Column('submitted_at', sa.Integer, nullable=False), | ||
sa.Column('complete', sa.SmallInteger, nullable=False, | ||
server_default=sa.DefaultClause("0")), | ||
sa.Column('complete_at', sa.Integer), | ||
sa.Column('results', sa.SmallInteger), | ||
sa.Column('parent_buildid', sa.Integer), | ||
sa.Column('parent_relationship', sa.Text), | ||
) | ||
buildsets.create() | ||
|
||
buildrequests = sa.Table( | ||
'buildrequests', metadata, | ||
sa.Column('id', sa.Integer, primary_key=True), | ||
sa.Column('buildsetid', sa.Integer, | ||
sa.ForeignKey("buildsets.id"), nullable=False), | ||
sa.Column('buildername', sa.String(length=256), | ||
nullable=False), | ||
sa.Column('priority', sa.Integer, nullable=False, | ||
server_default=sa.DefaultClause("0")), | ||
sa.Column('complete', sa.Integer, | ||
server_default=sa.DefaultClause("0")), | ||
sa.Column('results', sa.SmallInteger), | ||
sa.Column('submitted_at', sa.Integer, nullable=False), | ||
sa.Column('complete_at', sa.Integer), | ||
sa.Column('waited_for', sa.SmallInteger, | ||
server_default=sa.DefaultClause("0")), | ||
) | ||
buildrequests.create() | ||
|
||
idx = sa.Index('buildrequests_buildsetid', | ||
buildrequests.c.buildsetid) | ||
idx.create() | ||
idx = sa.Index('buildrequests_buildername', | ||
buildrequests.c.buildername) | ||
idx.create() | ||
idx = sa.Index('buildrequests_complete', buildrequests.c.complete) | ||
idx.create() | ||
idx = sa.Index('buildsets_complete', buildsets.c.complete) | ||
idx.create() | ||
idx = sa.Index('buildsets_submitted_at', buildsets.c.submitted_at) | ||
idx.create() | ||
|
||
brargs = dict(buildsetid=10, priority=1, submitted_at=1234) | ||
conn.execute(buildsets.insert(), id=10, submitted_at=1233) | ||
conn.execute(builders.insert(), id=20, name='bldr1', | ||
name_hash='88103b2fbeb05bdd81c066b58a11bcf9b0d29300') | ||
conn.execute(buildrequests.insert(), | ||
id=30, buildername='bldr1', **brargs) | ||
conn.execute(buildrequests.insert(), | ||
id=31, buildername='bldr1', **brargs) | ||
conn.execute(buildrequests.insert(), | ||
id=32, buildername='bldr2', **brargs) | ||
self.assertTrue(hasattr(buildrequests.c, 'buildername')) | ||
self.assertFalse(hasattr(buildrequests.c, 'builderid')) | ||
|
||
def verify_thd(conn): | ||
metadata = sa.MetaData() | ||
metadata.bind = conn | ||
|
||
buildrequests = sa.Table('buildrequests', metadata, autoload=True) | ||
builders = sa.Table('builders', metadata, autoload=True) | ||
|
||
self.assertFalse(hasattr(buildrequests.c, 'buildername')) | ||
self.assertTrue(hasattr(buildrequests.c, 'builderid')) | ||
|
||
self.assertEqual( | ||
sorted([i.name for i in buildrequests.indexes]), [ | ||
'buildrequests_builderid', | ||
'buildrequests_buildsetid', | ||
'buildrequests_complete', | ||
]) | ||
|
||
# get the new builderid | ||
bldr2_id = conn.execute( | ||
sa.select( | ||
[builders.c.id], | ||
whereclause=(builders.c.name == 'bldr2'))).first()[0] | ||
res = conn.execute( | ||
sa.select([buildrequests.c.id, buildrequests.c.builderid])) | ||
self.assertEqual(sorted(map(tuple, res)), | ||
[(30, 20), (31, 20), (32, bldr2_id)]) | ||
|
||
return self.do_test_migration(36, 37, setup_thd, verify_thd) |