How to use the buildbot.util.sautils.Table function in buildbot

To help you get started, we’ve selected a few buildbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github buildbot / buildbot / master / buildbot / db / migrate / versions / 021_fix_postgres_sequences.py View on Github external
to_fix = [
        'buildrequests.id',
        'builds.id',
        'buildsets.id',
        'changes.changeid',
        'patches.id',
        'sourcestampsets.id',
        'sourcestamps.id',
        'objects.id',
        'users.uid',
    ]

    for col in to_fix:
        tbl_name, col_name = col.split('.')
        tbl = sautils.Table(tbl_name, metadata, autoload=True)
        col = tbl.c[col_name]

        res = migrate_engine.execute(sa.select([sa.func.max(col)]))
        max = res.fetchall()[0][0]

        if max:
            seq_name = "%s_%s_seq" % (tbl_name, col_name)
            r = migrate_engine.execute("SELECT setval('%s', %d)"
                                       % (seq_name, max))
            r.close()
github buildbot / buildbot / master / buildbot / db / model.py View on Github external
# builds

    # This table contains the build properties
    build_properties = sautils.Table(
        'build_properties', metadata,
        sa.Column('buildid', sa.Integer,
                  sa.ForeignKey('builds.id', ondelete='CASCADE'),
                  nullable=False),
        sa.Column('name', sa.String(256), nullable=False),
        # JSON encoded value
        sa.Column('value', sa.Text, nullable=False),
        sa.Column('source', sa.String(256), nullable=False),
    )

    # This table contains basic information about each build.
    builds = sautils.Table(
        'builds', metadata,
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('number', sa.Integer, nullable=False),
        sa.Column('builderid', sa.Integer,
                  sa.ForeignKey('builders.id', ondelete='CASCADE'),
                  nullable=False),
        # note that there is 1:N relationship here.
        # In case of worker loss, build has results RETRY
        # and buildrequest is unclaimed.
        # We use use_alter to prevent circular reference
        # (buildrequests -> buildsets -> builds).
        sa.Column('buildrequestid', sa.Integer,
                  sa.ForeignKey(
                      'buildrequests.id', use_alter=True,
                      name='buildrequestid', ondelete='CASCADE'),
                  nullable=False),
github buildbot / buildbot / master / buildbot / db / migrate / versions / 042_add_build_properties_table.py View on Github external
def upgrade(migrate_engine):
    metadata = sa.MetaData()
    metadata.bind = migrate_engine

    sautils.Table('builds', metadata,
                  sa.Column('id', sa.Integer, primary_key=True),
                  # ..
                  )

    # This table contains input properties for builds
    build_properties = sautils.Table(
        'build_properties', metadata,
        sa.Column('buildid', sa.Integer, sa.ForeignKey('builds.id'), nullable=False),
        sa.Column('name', sa.String(256), nullable=False),
        # JSON-encoded value
        sa.Column('value', sa.Text, nullable=False),
        sa.Column('source', sa.Text, nullable=False),
    )

    # create the new table
    build_properties.create()
github buildbot / buildbot / master / buildbot / db / migrate / versions / 045_worker_transition.py View on Github external
def _migrate_builds_table_data(migrate_engine):
    metadata = sa.MetaData()
    metadata.bind = migrate_engine

    builds = sautils.Table('builds', metadata, autoload=True)

    s = builds.update().values(workerid=builds.c.buildslaveid)
    migrate_engine.execute(s)
github buildbot / buildbot / master / buildbot / db / migrate / versions / 028_sourcestamps_refactor.py View on Github external
def add_new_schema_parts(migrate_engine):
    metadata = sa.MetaData()
    metadata.bind = migrate_engine

    # add new sourcestamps table, with proper indexing
    sautils.Table('patches', metadata,
                  sa.Column('id', sa.Integer, primary_key=True),
                  # ...
                  )
    sourcestamps = sautils.Table(
        'sourcestamps', metadata,
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('ss_hash', sa.String(40), nullable=False),
        sa.Column('branch', sa.String(256)),
        sa.Column('revision', sa.String(256)),
        sa.Column('patchid', sa.Integer, sa.ForeignKey('patches.id')),
        sa.Column('repository', sa.String(length=512), nullable=False,
                  server_default=''),
        sa.Column('codebase', sa.String(256), nullable=False,
                  server_default=sa.DefaultClause("")),
        sa.Column('project', sa.String(length=512), nullable=False,
                  server_default=''),
        sa.Column('created_at', sa.Integer, nullable=False),
    )
    sourcestamps.create()
github buildbot / buildbot / master / buildbot / db / migrate / versions / 046_mysql_innodb_compatibility.py View on Github external
def _incompatible_users(metadata, migrate_engine):
    users = sautils.Table('users', metadata, autoload=True)
    c = users.c
    q = sa.select([c.uid]).where(func.length(c.identifier) > 255)
    invalid_users = q.execute().fetchall()
    errors = []
    if invalid_users:

        def format(res):
            return ("    users.uid={id} "
                    "has identifier longer than 255".format(id=res[0]))
        errors = ["- 'users_state' table has invalid data:\n"
                  "{0}".format("\n".join(map(format, invalid_users)))]
    return errors
github buildbot / buildbot / master / buildbot / db / migrate / versions / 045_worker_transition.py View on Github external
def _remove_invalid_references_in_builds(migrate_engine):
    # 'buildslaveid' column of 'builds' table don't have Foreign Key
    # constraint on 'id' column of 'buildslaves' table, so it is
    # possible that that reference is invalid.
    # Remove such invalid references for easier resolve of #3088 later.

    metadata = sa.MetaData()
    metadata.bind = migrate_engine

    builds = sautils.Table('builds', metadata, autoload=True)
    buildslaves = sautils.Table('buildslaves', metadata, autoload=True)

    q = sa.select(
        [builds.c.id, builds.c.buildslaveid, buildslaves.c.id]
    ).select_from(
        builds.outerjoin(
            buildslaves, builds.c.buildslaveid == buildslaves.c.id)
    ).where(
        (buildslaves.c.id == None) & (builds.c.buildslaveid != None)
    )

    invalid_references = q.execute().fetchall()
    if invalid_references:
        # Report invalid references.
        def format(res):
            return ("builds.id={id} builds.buildslaveid={buildslaveid} "
github buildbot / buildbot / master / buildbot / db / model.py View on Github external
# link workers to all builder/master pairs for which they are
    # configured
    configured_workers = sautils.Table(
        'configured_workers', metadata,
        sa.Column('id', sa.Integer, primary_key=True, nullable=False),
        sa.Column('buildermasterid', sa.Integer,
                  sa.ForeignKey('builder_masters.id', ondelete='CASCADE'),
                  nullable=False),
        sa.Column('workerid', sa.Integer,
                  sa.ForeignKey('workers.id', ondelete='CASCADE'),
                  nullable=False),
    )

    # link workers to the masters they are currently connected to
    connected_workers = sautils.Table(
        'connected_workers', metadata,
        sa.Column('id', sa.Integer, primary_key=True, nullable=False),
        sa.Column('masterid', sa.Integer,
                  sa.ForeignKey('masters.id', ondelete='CASCADE'),
                  nullable=False),
        sa.Column('workerid', sa.Integer,
                  sa.ForeignKey('workers.id', ondelete='CASCADE'),
                  nullable=False),
    )

    # changes

    # Files touched in changes
    change_files = sautils.Table(
        'change_files', metadata,
        sa.Column('changeid', sa.Integer,
github buildbot / buildbot / master / buildbot / db / migrate / versions / 020_remove_change_links.py View on Github external
def upgrade(migrate_engine):
    metadata = sa.MetaData()
    metadata.bind = migrate_engine

    tbl = sautils.Table('change_links', metadata, autoload=True)
    tbl.drop()
github buildbot / buildbot / master / buildbot / db / model.py View on Github external
#   scripts, but they should not be depended on - all code accessing these
    #   tables should supply default values as necessary.  The defaults are
    #   required during migration when adding non-nullable columns to existing
    #   tables.
    #
    # * dates are stored as unix timestamps (UTC-ish epoch time)
    #
    # * sqlalchemy does not handle sa.Boolean very well on MySQL or Postgres;
    #   use sa.SmallInteger instead

    # build requests

    # A BuildRequest is a request for a particular build to be performed.  Each
    # BuildRequest is a part of a Buildset.  BuildRequests are claimed by
    # masters, to avoid multiple masters running the same build.
    buildrequests = sautils.Table(
        'buildrequests', metadata,
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('buildsetid', sa.Integer,
                  sa.ForeignKey('buildsets.id', ondelete='CASCADE'),
                  nullable=False),
        sa.Column('builderid', sa.Integer,
                  sa.ForeignKey('builders.id', ondelete='CASCADE'),
                  nullable=False),
        sa.Column('priority', sa.Integer, nullable=False,
                  server_default=sa.DefaultClause("0")),

        # if this is zero, then the build is still pending
        sa.Column('complete', sa.Integer,
                  server_default=sa.DefaultClause("0")),

        # results is only valid when complete == 1; 0 = SUCCESS, 1 = WARNINGS,