Skip to content

Commit

Permalink
add project, repository columns to changes and sourcestamps tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin J. Mitchell committed Mar 10, 2010
1 parent f5caea9 commit 214c120
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
2 changes: 1 addition & 1 deletion buildbot/db/schema/manager.py
Expand Up @@ -2,7 +2,7 @@

# note that schema modules are not loaded unless an upgrade is taking place

CURRENT_VERSION = 1
CURRENT_VERSION = 2

class DBSchemaManager(object):
"""
Expand Down
12 changes: 11 additions & 1 deletion buildbot/db/schema/tables.sql
Expand Up @@ -78,7 +78,15 @@ CREATE TABLE changes (
`revision` VARCHAR(256), -- CVS uses NULL. too short for darcs?
`revlink` VARCHAR(256) NULL,
`when_timestamp` INTEGER NOT NULL, -- copied from incoming Change
`category` VARCHAR(256) NULL
`category` VARCHAR(256) NULL,

-- repository specifies, along with revision and branch, the
-- source tree in which this change was detected.
`repository` text not null default '',

-- project names the project this source code represents. It is used
-- later to filter changes
`project` text not nul default '',
);
CREATE TABLE changes_nextid (next_changeid INTEGER);
CREATE TABLE last_access (
Expand All @@ -99,6 +107,8 @@ CREATE TABLE sourcestamp_changes (
);
CREATE TABLE sourcestamps (
`id` INTEGER PRIMARY KEY,
`repository` TEXT not null default '',
`project` TEXT not null default '',
`branch` VARCHAR(256) default NULL,
`revision` VARCHAR(256) default NULL,
`patchid` INTEGER default NULL
Expand Down
32 changes: 32 additions & 0 deletions buildbot/db/schema/v2.py
@@ -0,0 +1,32 @@
import os

from buildbot.db import util
from buildbot.db.schema import base

class Upgrader(base.Upgrader):
def upgrade(self):
self.add_columns()
self.set_version()

def add_columns(self):
cursor = self.conn.cursor()
cursor.execute("""
ALTER TABLE changes
add column `repository` text not null default ''
""")
cursor.execute("""
ALTER TABLE changes
add column `project` text not null default ''
""")
cursor.execute("""
ALTER TABLE sourcestamps
add column `repository` text not null default ''
""")
cursor.execute("""
ALTER TABLE sourcestamps
add column `project` text not null default ''
""")

def set_version(self):
c = self.conn.cursor()
c.execute("""UPDATE version set version = 2 where version = 1""")
17 changes: 11 additions & 6 deletions buildbot/test/unit/test_db_schema_master.py
Expand Up @@ -125,14 +125,19 @@ def assertDatabaseOKFull(self):

# do a byte-for-byte comparison of the changes table and friends
c.execute("""SELECT changeid, author, comments, is_dir, branch, revision,
revlink, when_timestamp, category FROM changes order by revision""")
revlink, when_timestamp, category, repository, project
FROM changes order by revision""")
res = c.fetchall()
if res != [
(1, u'dustin', 'hi, mom', 1, u'', u'1233', u'http://buildbot.net', 1267419122, u''),
(2, u'warner', u'', 0, u'schedulerdb', u'1234', u'http://pypi.com', 1267419123, u'new'),
(3, u'catlee', u'', 0, u'', u'1235', u'', 1267419132, u''),
(1, u'dustin', 'hi, mom', 1, u'', u'1233',
u'http://buildbot.net', 1267419122, u'', u'', u''),
(2, u'warner', u'', 0, u'schedulerdb', u'1234',
u'http://pypi.com', 1267419123, u'new', u'', u''),
(3, u'catlee', u'', 0, u'', u'1235',
u'', 1267419132, u'', u'', u''),
# note change by bhearsum is missing because its revision=None
(4, u'marcusl', u'', 0, u'jinja', u'1239', u'', 1267419134, u'cool'),
(4, u'marcusl', u'', 0, u'jinja', u'1239',
u'', 1267419134, u'cool', u'', u''),
]:
pprint.pprint(res)
errs.append("changes table does not match expectations")
Expand Down Expand Up @@ -184,7 +189,7 @@ def assertDatabaseOKFull(self):
def test_get_current_version(self):
# this is as much a reminder to write tests for the new version
# as a test of the (very trivial) method
self.assertEqual(self.sm.get_current_version(), 1)
self.assertEqual(self.sm.get_current_version(), 2)

def test_get_db_version_empty(self):
self.assertEqual(self.sm.get_db_version(), 0)
Expand Down

0 comments on commit 214c120

Please sign in to comment.