Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add schedulers and scheduler_masters tables
- Loading branch information
Showing
5 changed files
with
247 additions
and
5 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
101 changes: 101 additions & 0 deletions
101
master/buildbot/db/migrate/versions/024_add_schedulers_table.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,101 @@ | ||
# 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): | ||
|
||
# drop the old scheduler_changes table (that references objects). This | ||
# loses a small, transient bit of information (processed but un-built | ||
# changes), during a cluster-wide downtime. | ||
|
||
metadata = sa.MetaData() | ||
metadata.bind = migrate_engine | ||
scheduler_changes = sa.Table('scheduler_changes', metadata, | ||
sa.Column('objectid', sa.Integer), | ||
sa.Column('changeid', sa.Integer), | ||
# .. | ||
) | ||
|
||
idx = sa.Index('scheduler_changes_objectid', scheduler_changes.c.objectid) | ||
idx.drop() | ||
idx = sa.Index('scheduler_changes_changeid', scheduler_changes.c.changeid) | ||
idx.drop() | ||
idx = sa.Index('scheduler_changes_unique', scheduler_changes.c.objectid, | ||
scheduler_changes.c.changeid, unique=True) | ||
idx.drop() | ||
scheduler_changes.drop() | ||
|
||
# now create the new tables (with new metadata since we're using the same | ||
# table name) | ||
|
||
metadata = sa.MetaData() | ||
metadata.bind = migrate_engine | ||
|
||
sa.Table('masters', metadata, | ||
sa.Column('id', sa.Integer, primary_key=True), | ||
# .. | ||
) | ||
|
||
sa.Table('changes', metadata, | ||
sa.Column('changeid', sa.Integer, primary_key=True), | ||
# .. | ||
) | ||
|
||
schedulers = sa.Table('schedulers', metadata, | ||
sa.Column("id", sa.Integer, primary_key=True), | ||
sa.Column('name', sa.Text, nullable=False), | ||
sa.Column('name_hash', sa.String(40), nullable=False), | ||
) | ||
|
||
scheduler_masters = sa.Table('scheduler_masters', metadata, | ||
sa.Column('schedulerid', sa.Integer, sa.ForeignKey('schedulers.id'), | ||
nullable=False), | ||
sa.Column('masterid', sa.Integer, sa.ForeignKey('masters.id'), | ||
nullable=False), | ||
) | ||
|
||
scheduler_changes = sa.Table('scheduler_changes', metadata, | ||
sa.Column('schedulerid', sa.Integer, sa.ForeignKey('schedulers.id')), | ||
sa.Column('changeid', sa.Integer, sa.ForeignKey('changes.changeid')), | ||
# true (nonzero) if this change is important to this scheduler | ||
sa.Column('important', sa.Integer), | ||
) | ||
|
||
# create the new tables | ||
schedulers.create() | ||
scheduler_masters.create() | ||
scheduler_changes.create() | ||
|
||
# and the indices | ||
idx = sa.Index('scheduler_name_hash', schedulers.c.name_hash, unique=True) | ||
idx.create() | ||
idx = sa.Index('scheduler_masters_schedulerid', | ||
scheduler_masters.c.schedulerid, unique=True) | ||
idx.create() | ||
idx = sa.Index('scheduler_masters_identity', | ||
scheduler_masters.c.schedulerid, scheduler_masters.c.masterid, | ||
unique=True) | ||
idx.create() | ||
idx = sa.Index('scheduler_changes_schedulerid', | ||
scheduler_changes.c.schedulerid) | ||
idx.create() | ||
idx = sa.Index('scheduler_changes_changeid', | ||
scheduler_changes.c.changeid) | ||
idx.create() | ||
idx = sa.Index('scheduler_changes_unique', | ||
scheduler_changes.c.schedulerid, scheduler_changes.c.changeid, | ||
unique=True) | ||
idx.create() |
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
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
83 changes: 83 additions & 0 deletions
83
master/buildbot/test/unit/test_db_migrate_versions_024_add_schedulers_table.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,83 @@ | ||
# 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 test_migration(self): | ||
def setup_thd(conn): | ||
metadata = sa.MetaData() | ||
metadata.bind = conn | ||
scheduler_changes = sa.Table('scheduler_changes', metadata, | ||
sa.Column('objectid', sa.Integer), | ||
sa.Column('changeid', sa.Integer), | ||
# .. | ||
) | ||
scheduler_changes.create() | ||
|
||
sa.Table('masters', metadata, | ||
sa.Column('id', sa.Integer, primary_key=True), | ||
# .. | ||
).create() | ||
|
||
sa.Table('changes', metadata, | ||
sa.Column('changeid', sa.Integer, primary_key=True), | ||
# .. | ||
).create() | ||
|
||
idx = sa.Index('scheduler_changes_objectid', | ||
scheduler_changes.c.objectid) | ||
idx.create() | ||
idx = sa.Index('scheduler_changes_changeid', | ||
scheduler_changes.c.changeid) | ||
idx.create() | ||
idx = sa.Index('scheduler_changes_unique', | ||
scheduler_changes.c.objectid, scheduler_changes.c.changeid, | ||
unique=True) | ||
idx.create() | ||
|
||
def verify_thd(conn): | ||
metadata = sa.MetaData() | ||
metadata.bind = conn | ||
|
||
schedulers = sa.Table('schedulers', metadata, autoload=True) | ||
scheduler_masters = sa.Table('scheduler_masters', metadata, | ||
autoload=True) | ||
scheduler_changes = sa.Table('scheduler_changes', metadata, | ||
autoload=True) | ||
|
||
q = sa.select([ schedulers.c.id, schedulers.c.name, | ||
schedulers.c.name_hash ]) | ||
self.assertEqual(conn.execute(q).fetchall(), []) | ||
|
||
q = sa.select([ scheduler_masters.c.schedulerid, | ||
scheduler_masters.c.masterid ]) | ||
self.assertEqual(conn.execute(q).fetchall(), []) | ||
|
||
q = sa.select([ scheduler_changes.c.schedulerid, | ||
scheduler_changes.c.changeid, | ||
scheduler_changes.c.important ]) | ||
self.assertEqual(conn.execute(q).fetchall(), []) | ||
|
||
return self.do_test_migration(23, 24, setup_thd, verify_thd) |