Skip to content

Commit

Permalink
change step state_strings to state_string: DB model
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Oct 19, 2014
1 parent bfc6fbf commit c047fa9
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 2 deletions.
30 changes: 30 additions & 0 deletions master/buildbot/db/migrate/versions/038_step_string.py
@@ -0,0 +1,30 @@
# 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


def upgrade(migrate_engine):
metadata = sa.MetaData()
metadata.bind = migrate_engine

steps_table = sa.Table('steps', metadata, autoload=True)

# no attempt is made here to move data from one table to the other, since
# there was no released version of Buildbot with a 'steps' table yet.

col = sa.Column('state_string', sa.Text, nullable=False, server_default='')
col.create(steps_table)
steps_table.c.state_strings_json.drop()
3 changes: 1 addition & 2 deletions master/buildbot/db/model.py
Expand Up @@ -130,8 +130,7 @@ class Model(base.DBConnectorComponent):
sa.Column('buildid', sa.Integer, sa.ForeignKey('builds.id')),
sa.Column('started_at', sa.Integer),
sa.Column('complete_at', sa.Integer),
# a list of strings describing the step's state
sa.Column('state_strings_json', sa.Text, nullable=False),
sa.Column('state_string', sa.Text, nullable=False, server_default=''),
sa.Column('results', sa.Integer),
sa.Column('urls_json', sa.Text, nullable=False),
)
Expand Down
@@ -0,0 +1,78 @@
# 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 create_tables_thd(self, conn):
metadata = sa.MetaData()
metadata.bind = conn

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),
sa.Column('buildrequestid', sa.Integer, nullable=False),
sa.Column('buildslaveid', sa.Integer),
sa.Column('masterid', sa.Integer, nullable=False),
sa.Column('started_at', sa.Integer, nullable=False),
sa.Column('complete_at', sa.Integer),
sa.Column('state_strings_json', sa.Text, nullable=False),
sa.Column('results', sa.Integer),
)
builds.create()

steps = sa.Table('steps', metadata,
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('number', sa.Integer, nullable=False),
sa.Column('name', sa.String(50), nullable=False),
sa.Column('buildid', sa.Integer, sa.ForeignKey('builds.id')),
sa.Column('started_at', sa.Integer),
sa.Column('complete_at', sa.Integer),
sa.Column('state_strings_json', sa.Text, nullable=False),
sa.Column('results', sa.Integer),
sa.Column('urls_json', sa.Text, nullable=False),
)
steps.create()

# tests

def test_update(self):
def setup_thd(conn):
self.create_tables_thd(conn)

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

steps = sa.Table('steps', metadata, autoload=True)
self.failIf(hasattr(steps.c, 'state_strings_json'))
self.failUnless(hasattr(steps.c, 'state_string'))
self.assertIsInstance(steps.c.state_string.type, sa.Text)

# TODO: also test that data is transferred? Or just hell with it

return self.do_test_migration(37, 38, setup_thd, verify_thd)

0 comments on commit c047fa9

Please sign in to comment.