From c047fa9ce44d7b677a2256240340dde57b99c02a Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Thu, 25 Sep 2014 16:36:12 -0400 Subject: [PATCH] change step state_strings to state_string: DB model --- .../db/migrate/versions/038_step_string.py | 30 +++++++ master/buildbot/db/model.py | 3 +- ...est_db_migrate_versions_038_step_string.py | 78 +++++++++++++++++++ 3 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 master/buildbot/db/migrate/versions/038_step_string.py create mode 100644 master/buildbot/test/unit/test_db_migrate_versions_038_step_string.py diff --git a/master/buildbot/db/migrate/versions/038_step_string.py b/master/buildbot/db/migrate/versions/038_step_string.py new file mode 100644 index 00000000000..c6b78ec68e4 --- /dev/null +++ b/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() diff --git a/master/buildbot/db/model.py b/master/buildbot/db/model.py index 91ebfd4be1a..78e09952893 100644 --- a/master/buildbot/db/model.py +++ b/master/buildbot/db/model.py @@ -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), ) diff --git a/master/buildbot/test/unit/test_db_migrate_versions_038_step_string.py b/master/buildbot/test/unit/test_db_migrate_versions_038_step_string.py new file mode 100644 index 00000000000..9d43aadda59 --- /dev/null +++ b/master/buildbot/test/unit/test_db_migrate_versions_038_step_string.py @@ -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)