Skip to content

Commit

Permalink
specify string lengths for MySQL's benefit, limit index lengths
Browse files Browse the repository at this point in the history
MySQL limits indexes to 1000 bytes, which means about 500 characters.
  • Loading branch information
djmitche committed Mar 27, 2011
1 parent bde9051 commit 9762f13
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions master/buildbot/db/migrate/versions/001_initial.py
Expand Up @@ -33,10 +33,10 @@

changes = sa.Table('changes', metadata,
sa.Column('changeid', sa.Integer, autoincrement=False, primary_key=True),
sa.Column('author', sa.String(1024), nullable=False),
sa.Column('author', sa.String(256), nullable=False),
sa.Column('comments', sa.String(1024), nullable=False),
sa.Column('is_dir', sa.SmallInteger, nullable=False),
sa.Column('branch', sa.String(1024)),
sa.Column('branch', sa.String(256)),
sa.Column('revision', sa.String(256)),
sa.Column('revlink', sa.String(256)),
sa.Column('when_timestamp', sa.Integer, nullable=False),
Expand Down Expand Up @@ -116,11 +116,11 @@
buildrequests = sa.Table('buildrequests', metadata,
sa.Column('id', sa.Integer, autoincrement=False, primary_key=True),
sa.Column('buildsetid', sa.Integer, sa.ForeignKey("buildsets.id"), nullable=False),
sa.Column('buildername', sa.String(length=None), nullable=False),
sa.Column('buildername', sa.String(length=256), nullable=False),
sa.Column('priority', sa.Integer, nullable=False, server_default=sa.DefaultClause("0")),
sa.Column('claimed_at', sa.Integer, server_default=sa.DefaultClause("0")),
sa.Column('claimed_by_name', sa.String(length=None)),
sa.Column('claimed_by_incarnation', sa.String(length=None)),
sa.Column('claimed_by_name', sa.String(length=256)),
sa.Column('claimed_by_incarnation', sa.String(length=256)),
sa.Column('complete', sa.Integer, server_default=sa.DefaultClause("0")),
sa.Column('results', sa.SmallInteger),
sa.Column('submitted_at', sa.Integer, nullable=False),
Expand All @@ -142,7 +142,7 @@ def test_unicode(migrate_engine):
submeta.bind = migrate_engine

test_unicode = sa.Table('test_unicode', submeta,
sa.Column('u', sa.Unicode),
sa.Column('u', sa.Unicode(length=100)),
sa.Column('b', sa.LargeBinary),
)
test_unicode.create()
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/db/migrate/versions/002_add_proj_repo.py
Expand Up @@ -21,9 +21,9 @@ def upgrade(migrate_engine):

# add project and repository columns to 'changes' an 'sourcestamps'
def add_cols(table):
repository = sa.Column('repository', sa.Text, nullable=False, server_default=sa.DefaultClause(''))
repository = sa.Column('repository', sa.String(512), nullable=False, server_default=sa.DefaultClause(''))
repository.create(table, populate_default=True)
project = sa.Column('project', sa.Text, nullable=False, server_default=sa.DefaultClause(''))
project = sa.Column('project', sa.String(512), nullable=False, server_default=sa.DefaultClause(''))
project.create(table, populate_default=True)

add_cols(sa.Table('changes', metadata, autoload=True))
Expand Down
Expand Up @@ -21,7 +21,7 @@ def upgrade(migrate_engine):

# add an empty class_name to the schedulers table
schedulers = sa.Table('schedulers', metadata, autoload=True)
class_name = sa.Column('class_name', sa.Text, nullable=False, server_default=sa.DefaultClause(''))
class_name = sa.Column('class_name', sa.String(length=128), nullable=False, server_default=sa.DefaultClause(''))
class_name.create(schedulers, populate_default=True)

# and an index since we'll be selecting with (name= AND class=)
Expand Down
Expand Up @@ -30,7 +30,7 @@ def upgrade(migrate_engine):
object_state = sa.Table("object_state", metadata,
sa.Column("objectid", sa.Integer, sa.ForeignKey('objects.id'),
nullable=False),
sa.Column("name", sa.String(length=None), nullable=False),
sa.Column("name", sa.String(length=256), nullable=False),
sa.Column("value_json", sa.Text, nullable=False),
sa.UniqueConstraint('objectid', 'name', name='name_per_object'),
)
Expand Down
22 changes: 11 additions & 11 deletions master/buildbot/db/model.py
Expand Up @@ -64,7 +64,7 @@ class Model(base.DBConnectorComponent):
buildrequests = sa.Table('buildrequests', metadata,
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('buildsetid', sa.Integer, sa.ForeignKey("buildsets.id"), nullable=False),
sa.Column('buildername', sa.String(length=None), nullable=False),
sa.Column('buildername', sa.String(length=256), nullable=False),
sa.Column('priority', sa.Integer, nullable=False, server_default=sa.DefaultClause("0")), # TODO: used?

# claimed_at is the time at which a master most recently asserted that
Expand All @@ -79,8 +79,8 @@ class Model(base.DBConnectorComponent):
# and will be different for subsequent runs. This allows each buildmaster
# to distinguish their current claims, their old claims, and the claims
# of other buildmasters, to treat them each appropriately.
sa.Column('claimed_by_name', sa.String(length=None)),
sa.Column('claimed_by_incarnation', sa.String(length=None)),
sa.Column('claimed_by_name', sa.String(length=256)),
sa.Column('claimed_by_incarnation', sa.String(length=256)),

# if this is zero, then the build is still pending
sa.Column('complete', sa.Integer, server_default=sa.DefaultClause("0")), # TODO: boolean
Expand Down Expand Up @@ -175,7 +175,7 @@ class Model(base.DBConnectorComponent):
sa.Column('changeid', sa.Integer, primary_key=True), # TODO: rename to 'id'

# author's name (usually an email address)
sa.Column('author', sa.String(1024), nullable=False),
sa.Column('author', sa.String(256), nullable=False),

# commit comment
sa.Column('comments', sa.String(1024), nullable=False), # TODO: too short?
Expand All @@ -185,7 +185,7 @@ class Model(base.DBConnectorComponent):

# The branch where this change occurred. When branch is NULL, that
# means the main branch (trunk, master, etc.)
sa.Column('branch', sa.String(1024)),
sa.Column('branch', sa.String(256)),

# revision identifier for this change
sa.Column('revision', sa.String(256)), # CVS uses NULL
Expand All @@ -203,11 +203,11 @@ class Model(base.DBConnectorComponent):

# repository specifies, along with revision and branch, the
# source tree in which this change was detected.
sa.Column('repository', sa.Text, nullable=False, server_default=''),
sa.Column('repository', sa.String(length=512), nullable=False, server_default=''),

# project names the project this source code represents. It is used
# later to filter changes
sa.Column('project', sa.Text, nullable=False, server_default=''),
sa.Column('project', sa.String(length=512), nullable=False, server_default=''),
)
"""Changes to the source code, produced by ChangeSources"""

Expand Down Expand Up @@ -248,10 +248,10 @@ class Model(base.DBConnectorComponent):
sa.Column('patchid', sa.Integer, sa.ForeignKey('patches.id')),

# the repository from which this source should be checked out
sa.Column('repository', sa.Text(length=None), nullable=False, server_default=''),
sa.Column('repository', sa.String(length=512), nullable=False, server_default=''),

# the project this source code represents
sa.Column('project', sa.Text(length=None), nullable=False, server_default=''),
sa.Column('project', sa.String(length=512), nullable=False, server_default=''),
)
"""A sourcestamp identifies a particular instance of the source code.
Ideally, this would always be absolute, but in practice source stamps can
Expand Down Expand Up @@ -315,9 +315,9 @@ class Model(base.DBConnectorComponent):
object_state = sa.Table("object_state", metadata,
# object for which this value is set
sa.Column("objectid", sa.Integer, sa.ForeignKey('objects.id'),
nullable=False),
nullable=False),
# name for this value (local to the object)
sa.Column("name", sa.String(length=None), nullable=False),
sa.Column("name", sa.String(length=256), nullable=False),
# value, as a JSON string
sa.Column("value_json", sa.Text, nullable=False),

Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/test/unit/test_db_pool.py
Expand Up @@ -125,7 +125,7 @@ def tearDown(self):
def test_ddl_and_queries(self):
meta = sa.MetaData()
native_tests = sa.Table("native_tests", meta,
sa.Column('name', sa.String()))
sa.Column('name', sa.String(length=200)))

# perform a DDL operation and immediately try to access that table;
# this has caused problems in the past, so this is basically a
Expand Down

0 comments on commit 9762f13

Please sign in to comment.