/
test_db_migrate_versions_036_build_parent.py
95 lines (82 loc) · 4.48 KB
/
test_db_migrate_versions_036_build_parent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 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
import datetime
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
# This table contains basic information about each build.
builds = sa.Table('builds', metadata,
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('number', sa.Integer, nullable=False),
sa.Column('builderid', sa.Integer),
# note that there is 1:N relationship here.
# In case of slave loss, build has results RETRY
# and buildrequest is unclaimed
sa.Column('buildrequestid', sa.Integer,
nullable=False),
# slave which performed this build
# TODO: ForeignKey to buildslaves table, named buildslaveid
# TODO: keep nullable to support slave-free builds
sa.Column('buildslaveid', sa.Integer),
# master which controlled this build
sa.Column('masterid', sa.Integer,
nullable=False),
# start/complete times
sa.Column('started_at', sa.Integer, nullable=False),
sa.Column('complete_at', sa.Integer),
# a list of strings describing the build's state
sa.Column('state_strings_json', sa.Text, nullable=False),
sa.Column('results', sa.Integer),
)
builds.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),
)
buildsets.create()
conn.execute(buildsets.insert(), [
dict(external_idstring='extid', reason='rsn1', sourcestamps=[91],
submitted_at=datetime.datetime(1978, 6, 15, 12, 31, 15),
complete_at=datetime.datetime(1979, 6, 15, 12, 31, 15),
complete=False, results=-1, bsid=91)
])
def verify_thd(conn):
metadata = sa.MetaData()
metadata.bind = conn
buildsets = sa.Table('buildsets', metadata, autoload=True)
q = sa.select([buildsets.c.parent_buildid, buildsets.c.parent_relationship])
num_rows = 0
for row in conn.execute(q):
# verify that the default value was set correctly
self.assertEqual(row.parent_buildid, None)
self.assertEqual(row.parent_relationship, None)
num_rows += 1
self.assertEqual(num_rows, 1)
return self.do_test_migration(35, 36, setup_thd, verify_thd)