aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/test/unit/test_db_migrate_versions_019_merge_schedulers_to_objects.py
blob: 452fc74354b14f1f8d7040676fb986a97a7d42cd (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# 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 twisted.trial import unittest
from buildbot.test.util import migration

class Migration(migration.MigrateTestMixin, unittest.TestCase):

    def setUp(self):
        return self.setUpMigrateTest()

    def tearDown(self):
        return self.tearDownMigrateTest()

    def create_tables_thd(self, conn):
        metadata = sa.MetaData()
        metadata.bind = conn

        changes = sa.Table('changes', metadata,
            sa.Column('changeid', sa.Integer,  primary_key=True),
            # the rest is unimportant
        )
        changes.create()

        buildsets = sa.Table('buildsets', metadata,
            sa.Column('id', sa.Integer,  primary_key=True),
            # the rest is unimportant
        )
        buildsets.create()

        self.schedulers = sa.Table("schedulers", metadata,
            sa.Column('schedulerid', sa.Integer, primary_key=True),
            sa.Column('name', sa.String(128), nullable=False),
            sa.Column('class_name', sa.String(128), nullable=False),
        )
        self.schedulers.create(bind=conn)
        sa.Index('name_and_class', self.schedulers.c.name,
                self.schedulers.c.class_name).create()

        self.scheduler_changes = sa.Table('scheduler_changes', metadata,
            sa.Column('schedulerid', sa.Integer,
                sa.ForeignKey('schedulers.schedulerid')),
            sa.Column('changeid', sa.Integer,
                sa.ForeignKey('changes.changeid')),
            sa.Column('important', sa.SmallInteger),
        )
        self.scheduler_changes.create()
        sa.Index('scheduler_changes_schedulerid',
                self.scheduler_changes.c.schedulerid).create()
        sa.Index('scheduler_changes_changeid',
                self.scheduler_changes.c.changeid).create()
        sa.Index('scheduler_changes_unique',
                self.scheduler_changes.c.schedulerid,
                self.scheduler_changes.c.changeid, unique=True).create()

        self.scheduler_upstream_buildsets = sa.Table(
                    'scheduler_upstream_buildsets', metadata,
            sa.Column('buildsetid', sa.Integer, sa.ForeignKey('buildsets.id')),
            sa.Column('schedulerid', sa.Integer,
                sa.ForeignKey('schedulers.schedulerid')),
        )
        self.scheduler_upstream_buildsets.create()

        sa.Index('scheduler_upstream_buildsets_buildsetid',
                self.scheduler_upstream_buildsets.c.buildsetid).create()
        sa.Index('scheduler_upstream_buildsets_schedulerid',
                self.scheduler_upstream_buildsets.c.schedulerid).create()

        self.objects = sa.Table("objects", metadata,
            sa.Column("id", sa.Integer, primary_key=True),
            sa.Column('name', sa.String(128), nullable=False),
            sa.Column('class_name', sa.String(128), nullable=False),
        )
        self.objects.create(bind=conn)

        sa.Index('object_identity', self.objects.c.name,
                self.objects.c.class_name, unique=True).create()

    # tests

    def test_update(self):
        # this upgrade script really just drops a bunch of tables, so
        # there's not much to test!
        def setup_thd(conn):
            self.create_tables_thd(conn)

        def verify_thd(conn):
            metadata = sa.MetaData()
            metadata.bind = conn

            # these tables are gone
            for tbl in 'schedulers', 'scheduler_upstream_buildsets':
                try:
                    conn.execute("select * from %s" % tbl)
                except:
                    pass
                else:
                    self.fail("%s table still exists" % tbl)

            # but scheduler_changes is not
            s_c_tbl = sa.Table("scheduler_changes", metadata,
                    autoload=True)
            q = sa.select(
               [ s_c_tbl.c.objectid, s_c_tbl.c.changeid, s_c_tbl.c.important ])
            self.assertEqual(conn.execute(q).fetchall(), [])

        return self.do_test_migration(18, 19, setup_thd, verify_thd)