-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3197 DB schema: change_properties to text
Alters change_properties.propery_value from String(1024) to Text http://trac.buildbot.net/ticket/3197
- Loading branch information
Fernando J Pando
committed
Jan 11, 2017
1 parent
cd6938e
commit c3ff87a
Showing
5 changed files
with
108 additions
and
3 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
34 changes: 34 additions & 0 deletions
34
master/buildbot/db/migrate/versions/048_change_properties_to_text.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,34 @@ | ||
# 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 migrate import changeset | ||
|
||
|
||
def upgrade(migrate_engine): | ||
metadata = sa.MetaData() | ||
metadata.bind = migrate_engine | ||
|
||
if migrate_engine.dialect.name == "postgresql": | ||
# changeset.alter_column has no effect on postgres, so we do this with raw sql | ||
migrate_engine.execute("alter table change_properties alter column property_value type text") | ||
|
||
else: | ||
# Commit messages can get too big for the normal 1024 String limit. | ||
changeset.alter_column( | ||
sa.Column('property_value', sa.Text, nullable=False), | ||
table='change_properties', | ||
metadata=metadata, | ||
engine=migrate_engine) |
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
1 change: 1 addition & 0 deletions
1
master/buildbot/newsfragments/db_schema_change_properties.bugfix
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 @@ | ||
Change properties value changed to type text and can be at least (tested for) 4096 bytes. This was previously max 1024 bytes. Requires upgrade master. (:bug:`3197`) |
72 changes: 72 additions & 0 deletions
72
master/buildbot/test/unit/test_db_migrate_versions_048_change_properties_to_text.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,72 @@ | ||
# 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 | ||
|
||
from random import choice | ||
from string import ascii_lowercase | ||
import sqlalchemy as sa | ||
from twisted.trial import unittest | ||
from buildbot.test.util import migration | ||
from buildbot.util import sautils | ||
|
||
|
||
class Migration(migration.MigrateTestMixin, unittest.TestCase): | ||
|
||
def setUp(self): | ||
return self.setUpMigrateTest() | ||
|
||
def tearDown(self): | ||
return self.tearDownMigrateTest() | ||
|
||
def create_table_thd(self, conn): | ||
metadata = sa.MetaData() | ||
metadata.bind = conn | ||
|
||
change_properties = sautils.Table( | ||
'change_properties', metadata, | ||
sa.Column('changeid', sa.Integer, nullable=False), | ||
sa.Column('property_name', sa.String(256), nullable=False), | ||
sa.Column('property_value', sa.String(1024), nullable=False), | ||
) | ||
|
||
change_properties.create() | ||
|
||
def test_update(self): | ||
def setup_thd(conn): | ||
self.create_table_thd(conn) | ||
|
||
def verify_thd(conn): | ||
metadata = sa.MetaData() | ||
metadata.bind = conn | ||
random_length = 4096 | ||
random_string = ''.join(choice(ascii_lowercase) for byte in range(random_length)) | ||
|
||
# Test column type is text | ||
change_properties = sautils.Table('change_properties', metadata, autoload=True) | ||
self.assertIsInstance(change_properties.c.property_value.type, sa.Text) | ||
|
||
# Test insert random string | ||
conn.execute(change_properties.insert(), [ | ||
dict(changeid=1, | ||
property_name="test_change_properties_property_value_length", | ||
property_value=random_string), | ||
]) | ||
|
||
# Test db string length | ||
# Using raw sql due to error via sa | ||
# q = conn.execute(sa.select([sa.func.length(change_properties.c.property_value)]).where(changeid==1)) | ||
q = conn.execute("select length(property_value) from change_properties where changeid == 1") | ||
[ self.assertEqual(q_length[0], random_length) for q_length in q ] | ||
|
||
return self.do_test_migration(47, 48, setup_thd, verify_thd) |