class InMemoryConfig(InMemoryBase, ModelBase): __tablename__ = 'configs_' + generate_uuid() section = Column(String(128)) opt = Column(String(128)) value = Column(String(4000)) _table_args = (PrimaryKeyConstraint('section', 'opt', name='CONFIGS_PK'), )
def upgrade(): ''' upgrade method ''' if context.get_context().dialect.name != 'sqlite': add_column('rules', sa.Column('comments', String(255))) add_column('rules_hist_recent', sa.Column('comments', String(255))) add_column('rules_history', sa.Column('comments', String(255)))
def upgrade(): ''' upgrade method ''' if context.get_context().dialect.name not in ('sqlite'): drop_constraint('heartbeats_pk', 'heartbeats', type_='primary') drop_column('heartbeats', 'executable') add_column('heartbeats', sa.Column('executable', String(64))) add_column('heartbeats', sa.Column('readable', String(4000))) create_primary_key('HEARTBEATS_PK', 'heartbeats', ['executable', 'hostname', 'pid', 'thread_id'])
def upgrade(): ''' Upgrade the database to this revision ''' if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']: schema = context.get_context().version_table_schema if context.get_context().version_table_schema else '' add_column('rules', sa.Column('comments', String(255)), schema=schema) add_column('rules_hist_recent', sa.Column('comments', String(255)), schema=schema) add_column('rules_history', sa.Column('comments', String(255)), schema=schema)
def upgrade(): ''' Upgrade the database to this revision ''' if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']: schema = context.get_context().version_table_schema if context.get_context().version_table_schema else '' drop_index('HEARTBEATS_UPDATED_AT', 'heartbeats') add_column('heartbeats', sa.Column('payload', String(3000)), schema=schema)
def upgrade(): ''' Upgrade the database to this revision ''' if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']: drop_constraint('heartbeats_pk', 'heartbeats', type_='primary') schema = context.get_context( ).version_table_schema if context.get_context( ).version_table_schema else '' drop_column('heartbeats', 'executable', schema=schema) add_column('heartbeats', sa.Column('executable', String(64)), schema=schema) add_column('heartbeats', sa.Column('readable', String(4000)), schema=schema) create_primary_key('HEARTBEATS_PK', 'heartbeats', ['executable', 'hostname', 'pid', 'thread_id'])
def upgrade(): ''' Upgrade the database to this revision ''' if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']: schema = context.get_context( ).version_table_schema if context.get_context( ).version_table_schema else '' add_column('requests', sa.Column('bytes', sa.BigInteger), schema=schema) add_column('requests', sa.Column('md5', String(32)), schema=schema) add_column('requests', sa.Column('adler32', String(8)), schema=schema) add_column('requests', sa.Column('dest_url', String(2048)), schema=schema) add_column('requests_history', sa.Column('bytes', sa.BigInteger), schema=schema) add_column('requests_history', sa.Column('md5', String(32)), schema=schema) add_column('requests_history', sa.Column('adler32', String(8)), schema=schema) add_column('requests_history', sa.Column('dest_url', String(2048)), schema=schema)
def core_config_mock(request): """ Fixture to allow having per-test core.config tables without affecting the other parallel tests. This override works only in tests which use core function calls directly, not in the ones working via the API, because the normal config table is not touched and the rucio instance answering API calls is not aware of this mock. This fixture acts by creating a new copy of the "config" sql table using the :memory: sqlite engine. Accesses to the "models.Config" table are then redirected to this temporary table via mock.patch(). """ from unittest import mock from rucio.common.utils import generate_uuid from rucio.db.sqla.models import Column, String, PrimaryKeyConstraint from rucio.db.sqla.session import get_session # Get the fixture parameters table_content = [] params = __get_fixture_param(request) if params: table_content = params.get("table_content", table_content) InMemoryConfig = __create_in_memory_db_table( 'configs_' + generate_uuid(), Column('section', String(128)), Column('opt', String(128)), Column('value', String(4000)), table_args=(PrimaryKeyConstraint('section', 'opt', name='CONFIGS_PK'), ), ) # Fill the table with the requested mock data session = get_session()() for section, option, value in (table_content or []): InMemoryConfig(section=section, opt=option, value=value).save(flush=True, session=session) session.commit() with mock.patch('rucio.core.config.models.Config', new=InMemoryConfig): yield
def message_mock(): """ Fixture which overrides the Message table with a private instance """ from unittest import mock from rucio.common.utils import generate_uuid from rucio.db.sqla.models import Column, String, PrimaryKeyConstraint, CheckConstraint, Text, Index, GUID InMemoryMessage = __create_in_memory_db_table( 'message_' + generate_uuid(), Column('id', GUID(), default=generate_uuid), Column('event_type', String(256)), Column('payload', String(4000)), Column('payload_nolimit', Text), Column('services', String(256)), table_args=(PrimaryKeyConstraint('id', name='MESSAGES_ID_PK'), CheckConstraint('EVENT_TYPE IS NOT NULL', name='MESSAGES_EVENT_TYPE_NN'), CheckConstraint('PAYLOAD IS NOT NULL', name='MESSAGES_PAYLOAD_NN'), Index('MESSAGES_SERVICES_IDX', 'services', 'event_type'))) with mock.patch('rucio.core.message.Message', new=InMemoryMessage): yield
def upgrade(): ''' upgrade method ''' add_column('requests', sa.Column('bytes', BigInteger)) add_column('requests', sa.Column('md5', String(32))) add_column('requests', sa.Column('adler32', String(8))) add_column('requests', sa.Column('dest_url', String(2048))) add_column('requests_history', sa.Column('bytes', BigInteger)) add_column('requests_history', sa.Column('md5', String(32))) add_column('requests_history', sa.Column('adler32', String(8))) add_column('requests_history', sa.Column('dest_url', String(2048)))
def upgrade(): ''' upgrade method ''' create_table('archive_contents', sa.Column('child_scope', String(25)), sa.Column('child_name', String(255)), sa.Column('scope', String(25)), sa.Column('name', String(255)), sa.Column('bytes', sa.BigInteger), sa.Column('adler32', String(8)), sa.Column('md5', String(32)), sa.Column('guid', GUID()), sa.Column('length', sa.BigInteger)) create_table('archive_contents_history', sa.Column('child_scope', String(25)), sa.Column('child_name', String(255)), sa.Column('scope', String(25)), sa.Column('name', String(255)), sa.Column('bytes', sa.BigInteger), sa.Column('adler32', String(8)), sa.Column('md5', String(32)), sa.Column('guid', GUID()), sa.Column('length', sa.BigInteger)) if context.get_context().dialect.name != 'sqlite': create_primary_key('ARCH_CONTENTS_PK', 'archive_contents', ['scope', 'name', 'child_scope', 'child_name']) create_foreign_key('ARCH_CONTENTS_PARENT_FK', 'archive_contents', 'dids', ['scope', 'name'], ['scope', 'name']) create_foreign_key('ARCH_CONTENTS_CHILD_FK', 'archive_contents', 'dids', ['child_scope', 'child_name'], ['scope', 'name']) create_index('ARCH_CONTENTS_CHILD_IDX', 'archive_contents', ['child_scope', 'child_name', 'scope', 'name']) create_index('ARCH_CONT_HIST_IDX', 'archive_contents_history', ['scope', 'name']) add_column('dids', sa.Column('is_archive', sa.Boolean(name='DIDS_ARCHIVE_CHK'))) add_column('dids', sa.Column('constituent', sa.Boolean(name='DIDS_CONSTITUENT_CHK'))) add_column('deleted_dids', sa.Column('is_archive', sa.Boolean())) add_column('deleted_dids', sa.Column('constituent', sa.Boolean()))
def upgrade(): ''' Upgrade the database to this revision ''' if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']: create_table( 'archive_contents', sa.Column('child_scope', String(25)), sa.Column('child_name', String(255)), sa.Column('scope', String(25)), sa.Column('name', String(255)), sa.Column('bytes', sa.BigInteger), sa.Column('adler32', String(8)), sa.Column('md5', String(32)), sa.Column('guid', GUID()), sa.Column('length', sa.BigInteger), sa.Column('created_at', sa.DateTime, default=datetime.datetime.utcnow), sa.Column("updated_at", sa.DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow)) create_table( 'archive_contents_history', sa.Column('child_scope', String(25)), sa.Column('child_name', String(255)), sa.Column('scope', String(25)), sa.Column('name', String(255)), sa.Column('bytes', sa.BigInteger), sa.Column('adler32', String(8)), sa.Column('md5', String(32)), sa.Column('guid', GUID()), sa.Column('length', sa.BigInteger), sa.Column('created_at', sa.DateTime, default=datetime.datetime.utcnow), sa.Column("updated_at", sa.DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow)) create_primary_key('ARCH_CONTENTS_PK', 'archive_contents', ['scope', 'name', 'child_scope', 'child_name']) create_primary_key('ARCH_CONT_HIST_PK', 'archive_contents_history', ['scope', 'name', 'child_scope', 'child_name']) create_foreign_key('ARCH_CONTENTS_PARENT_FK', 'archive_contents', 'dids', ['scope', 'name'], ['scope', 'name']) create_foreign_key('ARCH_CONTENTS_CHILD_FK', 'archive_contents', 'dids', ['child_scope', 'child_name'], ['scope', 'name']) create_index('ARCH_CONTENTS_CHILD_IDX', 'archive_contents', ['child_scope', 'child_name', 'scope', 'name']) create_index('ARCH_CONT_HIST_IDX', 'archive_contents_history', ['scope', 'name']) schema = context.get_context( ).version_table_schema if context.get_context( ).version_table_schema else '' add_column('dids', sa.Column( 'is_archive', sa.Boolean(name='DIDS_ARCHIVE_CHK', create_constraint=True)), schema=schema) add_column('dids', sa.Column( 'constituent', sa.Boolean(name='DIDS_CONSTITUENT_CHK', create_constraint=True)), schema=schema) add_column('deleted_dids', sa.Column('is_archive', sa.Boolean()), schema=schema) add_column('deleted_dids', sa.Column('constituent', sa.Boolean()), schema=schema)