Python sqlalchemy.Text() Examples

The following are code examples for showing how to use sqlalchemy.Text(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: flasky   Author: RoseOu   File: 51f5ccfba190_comments.py    MIT License 7 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('comments',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('body', sa.Text(), nullable=True),
    sa.Column('body_html', sa.Text(), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('disabled', sa.Boolean(), nullable=True),
    sa.Column('author_id', sa.Integer(), nullable=True),
    sa.Column('post_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['post_id'], ['posts.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_comments_timestamp', 'comments', ['timestamp'], unique=False)
    ### end Alembic commands ### 
Example 2
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 001_cell_mapping.py    Apache License 2.0 6 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    cell_mappings = Table('cell_mappings', meta,
        Column('created_at', DateTime),
        Column('updated_at', DateTime),
        Column('id', Integer, primary_key=True, nullable=False),
        Column('uuid', String(length=36), nullable=False),
        Column('name', String(length=255)),
        Column('transport_url', Text()),
        Column('database_connection', Text()),
        UniqueConstraint('uuid', name='uniq_cell_mappings0uuid'),
        mysql_engine='InnoDB',
        mysql_charset='utf8'
    )

    # NOTE(mriedem): DB2 creates an index when a unique constraint is created
    # so trying to add a second index on the uuid column will fail with
    # error SQL0605W, so omit the index in the case of DB2.
    if migrate_engine.name != 'ibm_db_sa':
        Index('uuid_idx', cell_mappings.c.uuid)

    cell_mappings.create(checkfirst=True) 
Example 3
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 004_add_request_spec.py    Apache License 2.0 6 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    request_specs = Table('request_specs', meta,
        Column('created_at', DateTime),
        Column('updated_at', DateTime),
        Column('id', Integer, primary_key=True, nullable=False),
        Column('instance_uuid', String(36), nullable=False),
        Column('spec', Text, nullable=False),
        UniqueConstraint('instance_uuid',
            name='uniq_request_specs0instance_uuid'),
        mysql_engine='InnoDB',
        mysql_charset='utf8'
    )

    # NOTE(mriedem): DB2 creates an index when a unique constraint is created
    # so trying to add a second index on the host column will fail with error
    # SQL0605W, so omit the index in the case of DB2.
    if migrate_engine.name != 'ibm_db_sa':
        Index('request_spec_instance_uuid_idx', request_specs.c.instance_uuid)

    request_specs.create(checkfirst=True) 
Example 4
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 233_add_stats_in_compute_nodes.py    Apache License 2.0 6 votes vote down vote up
def upgrade(engine):
    meta = MetaData()
    meta.bind = engine

    # Drop the compute_node_stats table and add a 'stats' column to
    # compute_nodes directly.  The data itself is transient and doesn't
    # need to be copied over.
    table_names = ('compute_node_stats', 'shadow_compute_node_stats')
    for table_name in table_names:
        table = Table(table_name, meta, autoload=True)
        table.drop()

    # Add a new stats column to compute nodes
    table_names = ('compute_nodes', 'shadow_compute_nodes')
    for table_name in table_names:
        table = Table(table_name, meta, autoload=True)
        stats = Column('stats', Text, default='{}')
        table.create_column(stats) 
Example 5
Project: zun   Author: openstack   File: a251f1f61217_create_capsule_table.py    Apache License 2.0 6 votes vote down vote up
def upgrade():
    op.create_table(
        'capsule',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('capsule_version', sa.String(length=255), nullable=True),
        sa.Column('kind', sa.String(length=36), nullable=True),
        sa.Column('project_id', sa.String(length=255), nullable=True),
        sa.Column('user_id', sa.String(length=255), nullable=True),
        sa.Column('restart_policy', sa.String(length=255), nullable=True),
        sa.Column('host_selector', sa.String(length=255), nullable=True),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('uuid', sa.String(length=36), nullable=False),
        sa.Column('status', sa.String(length=255), nullable=True),
        sa.Column('status_reason', sa.Text(), nullable=True),
        sa.Column('message', models.JSONEncodedDict(), nullable=True),
        sa.Column('spec', models.JSONEncodedDict(), nullable=True),
        sa.Column('cpu', sa.Float(), nullable=True),
        sa.Column('memory', sa.String(length=255), nullable=True),
        sa.Column('meta_name', sa.String(length=255), nullable=True),
        sa.Column('meta_labels', models.JSONEncodedList(), nullable=True),
        sa.Column('containers_uuids', models.JSONEncodedList(), nullable=True),
        sa.PrimaryKeyConstraint('id'),
    ) 
Example 6
Project: zun   Author: openstack   File: b6bfca998431_add_container_actions_events_table.py    Apache License 2.0 6 votes vote down vote up
def upgrade():
    op.create_table(
        'container_actions_events',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('event', sa.String(length=255), nullable=True),
        sa.Column('action_id', sa.Integer(), nullable=False),
        sa.Column('start_time', sa.DateTime(), nullable=True),
        sa.Column('finish_time', sa.DateTime(), nullable=True),
        sa.Column('result', sa.String(length=255), nullable=True),
        sa.Column('traceback', sa.Text(), nullable=True),
        sa.Column('details', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(['action_id'], ['container_actions.id'], ),
        sa.PrimaryKeyConstraint('id')
    ) 
Example 7
Project: gitlab-tools   Author: Salamek   File: 20bcb4b2673c_.py    GNU General Public License v3.0 6 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('task_result',
    sa.Column('updated', sa.DateTime(), nullable=True),
    sa.Column('created', sa.DateTime(), nullable=True),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('pull_mirror_id', sa.Integer(), nullable=True),
    sa.Column('push_mirror_id', sa.Integer(), nullable=True),
    sa.Column('task_id', sa.String(length=155), nullable=True),
    sa.Column('status', sa.String(length=50), nullable=True),
    sa.Column('task_name', sa.String(length=255), nullable=True),
    sa.Column('invoked_by', sa.Integer(), nullable=True),
    sa.Column('result', sa.PickleType(), nullable=True),
    sa.Column('date_done', sa.DateTime(), nullable=True),
    sa.Column('traceback', sa.Text(), nullable=True),
    sa.ForeignKeyConstraint(['pull_mirror_id'], ['pull_mirror.id'], ),
    sa.ForeignKeyConstraint(['push_mirror_id'], ['push_mirror.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('task_id')
    )
    op.create_index(op.f('ix_task_result_pull_mirror_id'), 'task_result', ['pull_mirror_id'], unique=False)
    op.create_index(op.f('ix_task_result_push_mirror_id'), 'task_result', ['push_mirror_id'], unique=False)
    # ### end Alembic commands ### 
Example 8
Project: maubot   Author: maubot   File: d295f8dcfa64_initial_revision.py    GNU Affero General Public License v3.0 6 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('client',
    sa.Column('id', sa.String(length=255), nullable=False),
    sa.Column('homeserver', sa.String(length=255), nullable=False),
    sa.Column('access_token', sa.Text(), nullable=False),
    sa.Column('enabled', sa.Boolean(), nullable=False),
    sa.Column('next_batch', sa.String(length=255), nullable=False),
    sa.Column('filter_id', sa.String(length=255), nullable=False),
    sa.Column('sync', sa.Boolean(), nullable=False),
    sa.Column('autojoin', sa.Boolean(), nullable=False),
    sa.Column('displayname', sa.String(length=255), nullable=False),
    sa.Column('avatar_url', sa.String(length=255), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('plugin',
    sa.Column('id', sa.String(length=255), nullable=False),
    sa.Column('type', sa.String(length=255), nullable=False),
    sa.Column('enabled', sa.Boolean(), nullable=False),
    sa.Column('primary_user', sa.String(length=255), nullable=False),
    sa.Column('config', sa.Text(), nullable=False),
    sa.ForeignKeyConstraint(['primary_user'], ['client.id'], onupdate='CASCADE', ondelete='RESTRICT'),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ### 
Example 9
Project: Akeso   Author: ameserole   File: c7225db614c1_adding_hints_and_unlocks_tables.py    MIT License 6 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('hints',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('type', sa.Integer(), nullable=True),
    sa.Column('chal', sa.Integer(), nullable=True),
    sa.Column('hint', sa.Text(), nullable=True),
    sa.Column('cost', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['chal'], ['challenges.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('unlocks',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('teamid', sa.Integer(), nullable=True),
    sa.Column('date', sa.DateTime(), nullable=True),
    sa.Column('itemid', sa.Integer(), nullable=True),
    sa.Column('model', sa.String(length=32), nullable=True),
    sa.ForeignKeyConstraint(['teamid'], ['teams.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ### 
Example 10
Project: openeo-openshift-driver   Author: Open-EO   File: 61d8d82e139b_initial_setup.py    Apache License 2.0 6 votes vote down vote up
def upgrade():
    op.create_table(
        'identity_providers',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('issuer_url', sa.Text, nullable=False),
        sa.Column('scopes', sa.Text, nullable=False),
        sa.Column('title', sa.Text, nullable=False, unique=True),
        sa.Column('description', sa.Text),
    )
    op.create_table(
        'users',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('auth_type', auth_type, nullable=False),
        sa.Column('username', sa.Text),
        sa.Column('password_hash', sa.Text),
        sa.Column('email', sa.Text),
        sa.Column('identity_provider_id', sa.Integer),
        sa.Column('created_at', sa.DateTime, nullable=False),
        sa.Column('updated_at', sa.DateTime, nullable=False),
    )
    op.create_foreign_key('fkey_identity_provider_user', 'users', 'identity_providers', ['identity_provider_id'], ['id']) 
Example 11
Project: nova   Author: ZhanHan   File: 001_cell_mapping.py    Apache License 2.0 6 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    cell_mappings = Table('cell_mappings', meta,
        Column('created_at', DateTime),
        Column('updated_at', DateTime),
        Column('id', Integer, primary_key=True, nullable=False),
        Column('uuid', String(length=36), nullable=False),
        Column('name', String(length=255)),
        Column('transport_url', Text()),
        Column('database_connection', Text()),
        UniqueConstraint('uuid', name='uniq_cell_mappings0uuid'),
        Index('uuid_idx', 'uuid'),
        mysql_engine='InnoDB',
        mysql_charset='utf8'
    )

    cell_mappings.create(checkfirst=True) 
Example 12
Project: nova   Author: ZhanHan   File: 004_add_request_spec.py    Apache License 2.0 6 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    request_specs = Table('request_specs', meta,
        Column('created_at', DateTime),
        Column('updated_at', DateTime),
        Column('id', Integer, primary_key=True, nullable=False),
        Column('instance_uuid', String(36), nullable=False),
        Column('spec', Text, nullable=False),
        UniqueConstraint('instance_uuid',
            name='uniq_request_specs0instance_uuid'),
        Index('request_spec_instance_uuid_idx', 'instance_uuid'),
        mysql_engine='InnoDB',
        mysql_charset='utf8'
    )

    request_specs.create(checkfirst=True) 
Example 13
Project: nova   Author: ZhanHan   File: 233_add_stats_in_compute_nodes.py    Apache License 2.0 6 votes vote down vote up
def upgrade(engine):
    meta = MetaData()
    meta.bind = engine

    # Drop the compute_node_stats table and add a 'stats' column to
    # compute_nodes directly.  The data itself is transient and doesn't
    # need to be copied over.
    table_names = ('compute_node_stats', 'shadow_compute_node_stats')
    for table_name in table_names:
        table = Table(table_name, meta, autoload=True)
        table.drop()

    # Add a new stats column to compute nodes
    table_names = ('compute_nodes', 'shadow_compute_nodes')
    for table_name in table_names:
        table = Table(table_name, meta, autoload=True)
        stats = Column('stats', Text, default='{}')
        table.create_column(stats) 
Example 14
Project: flasky   Author: RoseOu   File: 288cd3dc5a8_rich_text_posts.py    MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('posts', sa.Column('body_html', sa.Text(), nullable=True))
    ### end Alembic commands ### 
Example 15
Project: flasky   Author: RoseOu   File: d66f086b258_user_information.py    MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users', sa.Column('about_me', sa.Text(), nullable=True))
    op.add_column('users', sa.Column('last_seen', sa.DateTime(), nullable=True))
    op.add_column('users', sa.Column('location', sa.String(length=64), nullable=True))
    op.add_column('users', sa.Column('member_since', sa.DateTime(), nullable=True))
    op.add_column('users', sa.Column('name', sa.String(length=64), nullable=True))
    ### end Alembic commands ### 
Example 16
Project: flasky   Author: RoseOu   File: 1b966e7f4b9e_post_model.py    MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('posts',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('body', sa.Text(), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('author_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_posts_timestamp', 'posts', ['timestamp'], unique=False)
    ### end Alembic commands ### 
Example 17
Project: comport   Author: codeforamerica   File: 4ffa73ef2b8_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('chart_block_defaults',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=255), nullable=False),
    sa.Column('caption', sa.String(length=255), nullable=True),
    sa.Column('slug', sa.String(length=255), nullable=False),
    sa.Column('dataset', sa.String(length=255), nullable=False),
    sa.Column('content', sa.Text(convert_unicode=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('chart_blocks',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('department_id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=255), nullable=False),
    sa.Column('caption', sa.String(length=255), nullable=True),
    sa.Column('slug', sa.String(length=255), nullable=False),
    sa.Column('dataset', sa.String(length=255), nullable=False),
    sa.Column('content', sa.Text(), nullable=True),
    sa.Column('date_updated', sa.DateTime(), nullable=True),
    sa.Column('date_edited', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('use_of_force_incidents', sa.Column('received_date', sa.DateTime(), nullable=True))
    ### end Alembic commands ### 
Example 18
Project: comport   Author: codeforamerica   File: 1d31622bbed_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('departments', sa.Column('contact_us', sa.Text(convert_unicode=True), nullable=True))
    op.add_column('departments', sa.Column('how_you_can_use_this_data', sa.Text(convert_unicode=True), nullable=True))
    op.add_column('departments', sa.Column('what_this_is', sa.Text(convert_unicode=True), nullable=True))
    op.add_column('departments', sa.Column('why_we_are_doing_this', sa.Text(convert_unicode=True), nullable=True))
    ### end Alembic commands ### 
Example 19
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 006_build_request.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    request_specs = Table('request_specs', meta, autoload=True)
    build_requests = Table('build_requests', meta,
        Column('created_at', DateTime),
        Column('updated_at', DateTime),
        Column('id', Integer, primary_key=True, nullable=False),
        Column('request_spec_id', Integer, nullable=False),
        Column('project_id', String(length=255), nullable=False),
        Column('user_id', String(length=255), nullable=False),
        Column('display_name', String(length=255)),
        Column('instance_metadata', Text),
        Column('progress', Integer),
        Column('vm_state', String(length=255)),
        Column('task_state', String(length=255)),
        Column('image_ref', String(length=255)),
        Column('access_ip_v4', InetSmall()),
        Column('access_ip_v6', InetSmall()),
        Column('info_cache', Text),
        Column('security_groups', Text, nullable=False),
        Column('config_drive', Boolean, default=False, nullable=False),
        Column('key_name', String(length=255)),
        Column('locked_by', Enum('owner', 'admin',
            name='build_requests0locked_by')),
        UniqueConstraint('request_spec_id',
            name='uniq_build_requests0request_spec_id'),
        Index('build_requests_project_id_idx', 'project_id'),
        ForeignKeyConstraint(columns=['request_spec_id'],
            refcolumns=[request_specs.c.id]),
        mysql_engine='InnoDB',
        mysql_charset='utf8'
    )

    build_requests.create(checkfirst=True) 
Example 20
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 230_add_details_column_to_instance_actions_events.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    actions_events = utils.get_table(migrate_engine, 'instance_actions_events')
    host = Column('host', String(255))
    details = Column('details', Text)
    actions_events.create_column(host)
    actions_events.create_column(details)
    shadow_actions_events = utils.get_table(migrate_engine,
            api._SHADOW_TABLE_PREFIX + 'instance_actions_events')
    shadow_actions_events.create_column(host.copy())
    shadow_actions_events.create_column(details.copy()) 
Example 21
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 270_flavor_data_in_extra.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    for prefix in ('', 'shadow_'):
        table = Table(prefix + BASE_TABLE_NAME, meta, autoload=True)
        new_column = Column(NEW_COLUMN_NAME, Text, nullable=True)
        if not hasattr(table.c, NEW_COLUMN_NAME):
            table.create_column(new_column) 
Example 22
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 216_havana.py    Apache License 2.0 5 votes vote down vote up
def MediumText():
    return Text().with_variant(dialects.mysql.MEDIUMTEXT(), 'mysql') 
Example 23
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 251_add_numa_topology_to_comput_nodes.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    compute_nodes = Table('compute_nodes', meta, autoload=True)
    shadow_compute_nodes = Table('shadow_compute_nodes', meta, autoload=True)

    numa_topology = Column('numa_topology', Text, nullable=True)
    shadow_numa_topology = Column('numa_topology', Text, nullable=True)
    compute_nodes.create_column(numa_topology)
    shadow_compute_nodes.create_column(shadow_numa_topology) 
Example 24
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 300_migration_context.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    for prefix in ('', 'shadow_'):
        table = Table(prefix + BASE_TABLE_NAME, meta, autoload=True)
        new_column = Column(NEW_COLUMN_NAME, Text, nullable=True)
        if not hasattr(table.c, NEW_COLUMN_NAME):
            table.create_column(new_column) 
Example 25
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 252_add_instance_extra_table.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    columns = [
        (('created_at', DateTime), {}),
        (('updated_at', DateTime), {}),
        (('deleted_at', DateTime), {}),
        (('deleted', Integer), {}),
        (('id', Integer), dict(primary_key=True, nullable=False)),
        (('instance_uuid', String(length=36)), dict(nullable=False)),
        (('numa_topology', Text), dict(nullable=True)),
     ]
    for prefix in ('', 'shadow_'):
        instances = Table(prefix + 'instances', meta, autoload=True)
        basename = prefix + 'instance_extra'
        if migrate_engine.has_table(basename):
            continue
        _columns = tuple([Column(*args, **kwargs)
                          for args, kwargs in columns])
        table = Table(basename, meta, *_columns, mysql_engine='InnoDB',
                      mysql_charset='utf8')
        table.create()

        # Index
        instance_uuid_index = Index(basename + '_idx',
                                    table.c.instance_uuid)
        instance_uuid_index.create(migrate_engine)

        # Foreign key
        # NOTE(mriedem): DB2 won't create the ForeignKey over the
        # instances.uuid column since it doesn't have a UniqueConstraint (added
        # later in the 267 migration). The ForeignKey will be created for DB2
        # in the 296 migration.
        if not prefix and migrate_engine.name != 'ibm_db_sa':
            fkey_columns = [table.c.instance_uuid]
            fkey_refcolumns = [instances.c.uuid]
            instance_fkey = ForeignKeyConstraint(
                columns=fkey_columns, refcolumns=fkey_refcolumns)
            instance_fkey.create() 
Example 26
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 276_vcpu_model.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    for prefix in ('', 'shadow_'):
        table = Table(prefix + BASE_TABLE_NAME, meta, autoload=True)
        new_column = Column(NEW_COLUMN_NAME, Text, nullable=True)
        if not hasattr(table.c, NEW_COLUMN_NAME):
            table.create_column(new_column) 
Example 27
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 229_add_extra_resources_in_compute_nodes.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    # Add a new column extra_resources to save extra_resources info for
    # compute nodes
    compute_nodes = Table('compute_nodes', meta, autoload=True)
    shadow_compute_nodes = Table('shadow_compute_nodes', meta, autoload=True)

    extra_resources = Column('extra_resources', Text, nullable=True)
    shadow_extra_resources = Column('extra_resources', Text, nullable=True)
    compute_nodes.create_column(extra_resources)
    shadow_compute_nodes.create_column(shadow_extra_resources) 
Example 28
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: models.py    Apache License 2.0 5 votes vote down vote up
def MediumText():
    return Text().with_variant(MEDIUMTEXT(), 'mysql') 
Example 29
Project: gnocchi   Author: gnocchixyz   File: 8f376189b9eb_migrate_legacy_resources_to_db.py    Apache License 2.0 5 votes vote down vote up
def upgrade():
    resource_type = sa.Table(
        'resource_type', sa.MetaData(),
        sa.Column('name', sa.String(255), nullable=False),
        sa.Column('attributes', sa.Text, nullable=False)
    )

    for name, attributes in legacy.ceilometer_resources.items():
        text_attributes = json.dumps(attributes)
        op.execute(resource_type.update().where(
            resource_type.c.name == name
        ).values({resource_type.c.attributes: text_attributes})) 
Example 30
Project: gnocchi   Author: gnocchixyz   File: ffc7bbeec0b0_migrate_legacy_resources_to_db2.py    Apache License 2.0 5 votes vote down vote up
def upgrade():
    bind = op.get_bind()

    resource_type = sa.Table(
        'resource_type', sa.MetaData(),
        sa.Column('name', sa.String(255), nullable=False),
        sa.Column('tablename', sa.String(18), nullable=False),
        sa.Column('attributes', sa.Text, nullable=False)
    )

    # NOTE(gordc): fix for incorrect migration:
    # 0718ed97e5b3_add_tablename_to_resource_type.py#L46
    op.execute(resource_type.update().where(
        resource_type.c.name == "instance_network_interface"
    ).values({'tablename': 'instance_net_int'}))

    resource_type_names = [rt.name for rt in
                           list(bind.execute(resource_type.select()))]

    for name, attributes in legacy.ceilometer_resources.items():
        if name in resource_type_names:
            continue
        tablename = legacy.ceilometer_tablenames.get(name, name)
        text_attributes = json.dumps(attributes)
        op.execute(resource_type.insert().values({
            resource_type.c.attributes: text_attributes,
            resource_type.c.name: name,
            resource_type.c.tablename: tablename,
        })) 
Example 31
Project: zun   Author: openstack   File: models.py    Apache License 2.0 5 votes vote down vote up
def MediumText():
    return Text().with_variant(MEDIUMTEXT(), 'mysql') 
Example 32
Project: zun   Author: openstack   File: df87dbd4846c_add_annotations_to_container.py    Apache License 2.0 5 votes vote down vote up
def MediumText():
    return sa.Text().with_variant(sa.dialects.mysql.MEDIUMTEXT(), 'mysql') 
Example 33
Project: zun   Author: openstack   File: a9c9fb54274a_add_contents_to_volume_mapping_table.py    Apache License 2.0 5 votes vote down vote up
def MediumText():
    return sa.Text().with_variant(sa.dialects.mysql.MEDIUMTEXT(), 'mysql') 
Example 34
Project: zun   Author: openstack   File: 37bce72463e3_add_pci_device.py    Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.create_table(
        'pci_device',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('uuid', sa.String(length=36)),
        sa.Column('compute_node_uuid', sa.String(length=36), nullable=False),
        sa.Column('address', sa.String(length=12), nullable=False),
        sa.Column('vendor_id', sa.String(length=4), nullable=False),
        sa.Column('product_id', sa.String(length=4), nullable=False),
        sa.Column('dev_type', sa.String(length=8), nullable=False),
        sa.Column('dev_id', sa.String(255)),
        sa.Column('label', sa.String(255), nullable=False),
        sa.Column('status', sa.String(36), nullable=False),
        sa.Column('request_id', sa.String(36), nullable=False),
        sa.Column('extra_info', sa.Text()),
        sa.Column('container_uuid', sa.String(36)),
        sa.Column('numa_node', sa.Integer(), nullable=True),
        sa.Column('parent_addr', sa.String(12), nullable=True),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('compute_node_uuid', 'address',
                            name='uniq_pci_device0compute_node_uuid0address'),
        sa.Index('ix_pci_device_compute_node_uuid', 'compute_node_uuid'),
        sa.Index('ix_pci_device_container_uuid', 'container_uuid'),
        sa.Index('ix_pci_device_compute_node_uuid_parent_addr',
                 'compute_node_uuid', 'parent_addr'),
    ) 
Example 35
Project: zun   Author: openstack   File: 43e1088c3389_add_image_pull_policy_column.py    Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('image_pull_policy', sa.Text(),
                            nullable=True)) 
Example 36
Project: zun   Author: openstack   File: ff7b9665d504_add_pci_stats_to_compute_node.py    Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('compute_node',
                  sa.Column('pci_stats', sa.Text())) 
Example 37
Project: zun   Author: openstack   File: 10d65e285a59_create_volume_mapping_table.py    Apache License 2.0 5 votes vote down vote up
def MediumText():
    return sa.Text().with_variant(dialects.mysql.MEDIUMTEXT(), 'mysql') 
Example 38
Project: zun   Author: openstack   File: 3e80bbfd8da7_convert_type_of_command_from_string_to_.py    Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.alter_column('container', 'command', type_=sa.Text())
    # Convert 'command' from string to json-encoded list
    session = sa.orm.Session(bind=op.get_bind())
    with session.begin(subtransactions=True):
        for row in session.query(TABLE_MODEL):
            if row[1]:
                command = shlex.split(row[1])
                command = jsonutils.dumps(command)
                session.execute(
                    TABLE_MODEL.update().values(
                        command=command).where(
                            TABLE_MODEL.c.id == row[0]))
    session.commit() 
Example 39
Project: zun   Author: openstack   File: 33cdd98bb9b2_split_volume_mapping_table.py    Apache License 2.0 5 votes vote down vote up
def MediumText():
    return sa.Text().with_variant(dialects.mysql.MEDIUMTEXT(), 'mysql') 
Example 40
Project: gitlab-tools   Author: Salamek   File: d4841aeeb072_.py    GNU General Public License v3.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('celery_taskmeta',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('task_id', sa.String(length=155), nullable=True),
    sa.Column('status', sa.String(length=50), nullable=True),
    sa.Column('result', sa.PickleType(), nullable=True),
    sa.Column('date_done', sa.DateTime(), nullable=True),
    sa.Column('traceback', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('task_id'),
    sqlite_autoincrement=True
    )
    op.create_table('celery_tasksetmeta',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('taskset_id', sa.String(length=155), nullable=True),
    sa.Column('result', sa.PickleType(), nullable=True),
    sa.Column('date_done', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('taskset_id'),
    sqlite_autoincrement=True
    )
    op.add_column('task_result', sa.Column('celery_taskmeta_id', sa.Integer(), nullable=False))
    op.create_index(op.f('ix_task_result_celery_taskmeta_id'), 'task_result', ['celery_taskmeta_id'], unique=False)
    op.drop_constraint('task_result_task_id_key', 'task_result', type_='unique')
    op.create_foreign_key(None, 'task_result', 'celery_taskmeta', ['celery_taskmeta_id'], ['id'])
    op.drop_column('task_result', 'result')
    op.drop_column('task_result', 'status')
    op.drop_column('task_result', 'date_done')
    op.drop_column('task_result', 'task_id')
    op.drop_column('task_result', 'traceback')
    # ### end Alembic commands ### 
Example 41
Project: orcid-service   Author: adsabs   File: 51f3b3b5cd5d_creating_basic_db_structure.py    MIT License 5 votes vote down vote up
def upgrade():
    op.create_table('users',
        sa.Column('orcid_id', sa.String(length=255), nullable=False),
        sa.Column('access_token', sa.String(length=255), nullable=True),
        sa.Column('created', sa.DateTime(), nullable=True, default=datetime.datetime.utcnow),
        sa.Column('updated', sa.DateTime(), nullable=True, default=datetime.datetime.utcnow),
        sa.Column('profile', sa.Text, nullable=True),
        sa.PrimaryKeyConstraint('orcid_id')
    ) 
Example 42
Project: orcid-service   Author: adsabs   File: 386337178a2f_adding_info_field.py    MIT License 5 votes vote down vote up
def upgrade():
    op.add_column('users', sa.Column('info', sa.Text)) 
Example 43
Project: plexivity   Author: mutschler   File: 2fbb8ebcb2da_recently_added_table.py    GNU General Public License v3.0 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('recently_added', sa.Column('filename', sa.Text(), nullable=True))
    op.add_column('recently_added', sa.Column('title', sa.Text(), nullable=True))
    ### end Alembic commands ### 
Example 44
Project: lando-api   Author: mozilla-conduit   File: 79cefec5be09_add_sec_approval_tables.py    Mozilla Public License 2.0 5 votes vote down vote up
def upgrade():
    op.create_table(
        "secapproval_requests",
        sa.Column("id", sa.Integer(), primary_key=True),
        sa.Column("revision_id", sa.Integer(), nullable=False, index=True),
        sa.Column("diff_phid", sa.Text(), nullable=False),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column(
            "comment_candidates",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=False,
        ),
    ) 
Example 45
Project: SUMSarizer   Author: SUMSarizer   File: f71b10058f31_.py    MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('study_uploads', sa.Column('error_message', sa.Text(), nullable=True))
    op.add_column('study_uploads', sa.Column('state', sa.String(length=64), nullable=True))
    ### end Alembic commands ### 
Example 46
Project: sqlalchemy_bulk_lazy_loader   Author: operator   File: _fixtures.py    MIT License 5 votes vote down vote up
def define_tables(cls, metadata):
        Table('users', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('name', String(30), nullable=False),
              Column('parent_id', None, ForeignKey('users.id')),
              test_needs_acid=True,
              test_needs_fk=True)

        Table('user_infos', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('details', Text),
              Column('user_id', None, ForeignKey('users.id')),
              test_needs_acid=True,
              test_needs_fk=True)

        Table('addresses', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('user_id', None, ForeignKey('users.id')),
              Column('email_address', String(50), nullable=False),
              test_needs_acid=True,
              test_needs_fk=True)

        Table('things', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('name', String(30), nullable=False),
              test_needs_acid=True,
              test_needs_fk=True)

        Table('user_to_things', metadata,
              Column('user_id', None, ForeignKey('users.id')),
              Column('thing_id', None, ForeignKey('things.id')),
              test_needs_acid=True,
              test_needs_fk=True) 
Example 47
Project: backend.ai-manager   Author: lablup   File: 9c89b9011872_add_attached_devices_field_in_kernels.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('kernels', sa.Column('attached_devices',
                                       postgresql.JSONB(astext_type=sa.Text()),
                                       nullable=True))
    # ### end Alembic commands ### 
Example 48
Project: backend.ai-manager   Author: lablup   File: 22964745c12b_add_total_resource_slots_to_group.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('domains', sa.Column('integration_id', sa.String(length=512), nullable=True))
    op.alter_column('domains', 'total_resource_slots',
                    existing_type=postgresql.JSONB(astext_type=sa.Text()),
                    nullable=True)
    op.add_column('groups', sa.Column('integration_id', sa.String(length=512), nullable=True))
    op.add_column('groups', sa.Column('total_resource_slots',
                                      postgresql.JSONB(astext_type=sa.Text()), nullable=True))
    op.add_column('users', sa.Column('integration_id', sa.String(length=512), nullable=True))
    # ### end Alembic commandk ###

    print('\nSet group\'s total_resource_slots with empty dictionary.')
    query = textwrap.dedent('''\
        UPDATE groups SET total_resource_slots = '{}'::jsonb;
    ''')
    connection = op.get_bind()
    connection.execute(query) 
Example 49
Project: backend.ai-manager   Author: lablup   File: 22964745c12b_add_total_resource_slots_to_group.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'integration_id')
    op.drop_column('groups', 'total_resource_slots')
    op.drop_column('groups', 'integration_id')
    op.alter_column('domains', 'total_resource_slots',
                    existing_type=postgresql.JSONB(astext_type=sa.Text()),
                    nullable=False)
    op.drop_column('domains', 'integration_id')
    # ### end Alembic commands ### 
Example 50
Project: backend.ai-manager   Author: lablup   File: 02950808ca3d_add_agent_version.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        'agents',
        # Set the defualt to "19.06.0" for now (since it is the first version to have this field)
        # and let the heartbeat handler route to update with the exact value.
        sa.Column('compute_plugins', postgresql.JSONB(astext_type=sa.Text()), nullable=False,
                  server_default=sa.text("'{}'::jsonb")))
    op.add_column(
        'agents',
        sa.Column('version', sa.String(length=64), nullable=False,
                  server_default=sa.literal('19.06.0')))
    # ### end Alembic commands ### 
Example 51
Project: backend.ai-manager   Author: lablup   File: c092dabf3ee5_add_batch_session.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('kernels', sa.Column('startup_command', sa.Text(), nullable=True))
    op.drop_column('kernels', 'type')
    op.add_column('kernels',
                  sa.Column('sess_type', sa.Enum('INTERACTIVE', 'BATCH', name='sessiontypes'),
                            nullable=False, server_default='INTERACTIVE'))
    op.create_index(op.f('ix_kernels_sess_type'), 'kernels', ['sess_type'], unique=False)
    # ### end Alembic commands ### 
Example 52
Project: backend.ai-manager   Author: lablup   File: 202b6dcbc159_add_internal_data_to_kernels.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('kernels', sa.Column('internal_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
    # ### end Alembic commands ### 
Example 53
Project: backend.ai-manager   Author: lablup   File: 5b45f28d2cac_add_resource_opts_in_kernels.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('kernels', sa.Column('resource_opts',
                                       postgresql.JSONB(astext_type=sa.Text()),
                                       nullable=True))
    # ### end Alembic commands ### 
Example 54
Project: Akeso   Author: ameserole   File: a4e30c94c360_adds_data_column_to_keys_table.py    MIT License 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('keys', sa.Column('data', sa.Text(), nullable=True))
    # ### end Alembic commands ### 
Example 55
Project: ara-archive   Author: dmsimard   File: 005_ansible_metadata.py    GNU General Public License v3.0 5 votes vote down vote up
def upgrade():
    op.add_column('playbooks', sa.Column('options', models.CompressedData((2 ** 32) - 1), nullable=True))
    op.add_column('tasks', sa.Column('tags', sa.Text(), nullable=True))
    # ### end Alembic commands ### 
Example 56
Project: pyglottolog   Author: glottolog   File: bibfiles_db.py    Apache License 2.0 5 votes vote down vote up
def to_csvfile(self, filename, encoding='utf-8', dialect='excel'):
        """Write a CSV file with one row for each entry in each bibfile."""
        select_rows = sa.select(
            [
                File.name.label('filename'), Entry.bibkey, Entry.hash,
                sa.cast(Entry.id, sa.Text).label('id'),
            ]).select_from(sa.join(File, Entry))\
            .order_by(sa.func.lower(File.name), sa.func.lower(Entry.bibkey), Entry.hash, Entry.id)
        with self.execute(select_rows) as cursor:
            with dsv.UnicodeWriter(filename, encoding=encoding, dialect=dialect) as writer:
                writer.writerow(cursor.keys())
                for row in cursor:
                    writer.writerow(row) 
Example 57
Project: pyglottolog   Author: glottolog   File: bibfiles_db.py    Apache License 2.0 5 votes vote down vote up
def trickle(self, bibfiles):
        """Write new/changed glottolog_ref_ids back into the given bibfiles."""
        assert Entry.allid(self.engine)
        if not self.is_uptodate(bibfiles, verbose=True):
            raise RuntimeError('trickle with an outdated db')  # pragma: no cover
        changed = (Entry.id != sa.func.coalesce(Entry.refid, -1))
        select_files = sa.select([File.pk, File.name])\
            .where(sa.exists().where(Entry.file_pk == File.pk).where(changed))\
            .order_by(File.name)
        select_changed = sa.select(
            [
                Entry.bibkey,
                sa.cast(Entry.refid, sa.Text).label('refid'),
                sa.cast(Entry.id, sa.Text).label('id'),
            ]).where(Entry.file_pk == sa.bindparam('file_pk')).where(changed)\
            .order_by(sa.func.lower(Entry.bibkey))
        with self.engine.connect() as conn:
            for file_pk, filename in conn.execute(select_files).fetchall():
                b = bibfiles[filename]
                entries = b.load()
                added = changed = 0
                for bibkey, refid, new in conn.execute(select_changed, file_pk=file_pk):
                    entrytype, fields = entries[bibkey]
                    old = fields.pop('glottolog_ref_id', None)
                    assert old == refid
                    if old is None:
                        added += 1
                    else:
                        changed += 1
                    fields['glottolog_ref_id'] = new
                print('%d changed %d added in %s' % (changed, added, b.id))
                b.save(entries) 
Example 58
Project: eventsourcing   Author: johnbywater   File: test_process.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def define_projection_record_class(self):
        class ProjectionRecord(Base):
            __tablename__ = "projections"

            # Projection ID.
            projection_id = Column(UUIDType(), primary_key=True)

            # State of the projection (serialized dict, possibly encrypted).
            state = Column(Text())

        self.projection_record_class = ProjectionRecord 
Example 59
Project: rucio   Author: rucio   File: 90f47792bb76_add_clob_payload_to_messages.py    Apache License 2.0 5 votes vote down vote up
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('messages', sa.Column('payload_nolimit', sa.Text), schema=schema)
        add_column('messages_history', sa.Column('payload_nolimit', sa.Text), schema=schema) 
Example 60
Project: openeo-openshift-driver   Author: Open-EO   File: 943d0bb2c339_fix_missing_role.py    Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('users', sa.Column('role', sa.Text, nullable=False, default='user')) 
Example 61
Project: openeo-openshift-driver   Author: Open-EO   File: 17295e67b0c5_add_roles_and_profiles.py    Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.create_table(
        'profiles',
        sa.Column('id', sa.String, primary_key=True),
        sa.Column('name', sa.Text, nullable=False, unique=True),
        sa.Column('data_access', sa.Text, nullable=False),
    )
    op.add_column(
        'users',
        sa.Column('profile_id', sa.String, nullable=False)
    )
    op.create_foreign_key('fkey_profile_user', 'users', 'profiles', ['profile_id'], ['id']) 
Example 62
Project: openeo-openshift-driver   Author: Open-EO   File: 1efc54cd3649_correct_users_id_type.py    Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.drop_column('users', 'id')
    op.add_column('users',
        sa.Column('id', sa.String(), nullable=False, unique=True)
    )
    op.drop_column('users', 'username')
    op.add_column('users',
        sa.Column('username', sa.Text(), unique=True)
    )
    op.drop_column('users', 'password_hash')
    op.add_column('users',
        sa.Column('password_hash', sa.Text(), unique=True)
    ) 
Example 63
Project: nova   Author: ZhanHan   File: 019_build_request_add_block_device_mapping.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    build_requests = Table('build_requests', meta, autoload=True)

    if not hasattr(build_requests.c, 'block_device_mappings'):
        build_requests.create_column(Column('block_device_mappings', Text())) 
Example 64
Project: nova   Author: ZhanHan   File: 013_build_request_extended_attrs.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    build_requests = Table('build_requests', meta, autoload=True)

    columns_to_add = [
            ('instance_uuid',
                Column('instance_uuid', String(length=36))),
            ('instance',
                Column('instance', Text())),
    ]
    for (col_name, column) in columns_to_add:
        if not hasattr(build_requests.c, col_name):
            build_requests.create_column(column)

    for index in build_requests.indexes:
        if [c.name for c in index.columns] == ['instance_uuid']:
            break
    else:
        index = Index('build_requests_instance_uuid_idx',
                build_requests.c.instance_uuid)
        index.create()

    inspector = reflection.Inspector.from_engine(migrate_engine)
    constrs = inspector.get_unique_constraints('build_requests')
    constr_names = [constr['name'] for constr in constrs]
    if 'uniq_build_requests0instance_uuid' not in constr_names:
        UniqueConstraint('instance_uuid', table=build_requests,
                name='uniq_build_requests0instance_uuid').create() 
Example 65
Project: nova   Author: ZhanHan   File: 006_build_request.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    request_specs = Table('request_specs', meta, autoload=True)
    build_requests = Table('build_requests', meta,
        Column('created_at', DateTime),
        Column('updated_at', DateTime),
        Column('id', Integer, primary_key=True, nullable=False),
        Column('request_spec_id', Integer, nullable=False),
        Column('project_id', String(length=255), nullable=False),
        Column('user_id', String(length=255), nullable=False),
        Column('display_name', String(length=255)),
        Column('instance_metadata', Text),
        Column('progress', Integer),
        Column('vm_state', String(length=255)),
        Column('task_state', String(length=255)),
        Column('image_ref', String(length=255)),
        Column('access_ip_v4', InetSmall()),
        Column('access_ip_v6', InetSmall()),
        Column('info_cache', Text),
        Column('security_groups', Text, nullable=False),
        Column('config_drive', Boolean, default=False, nullable=False),
        Column('key_name', String(length=255)),
        Column('locked_by', Enum('owner', 'admin',
            name='build_requests0locked_by')),
        UniqueConstraint('request_spec_id',
            name='uniq_build_requests0request_spec_id'),
        Index('build_requests_project_id_idx', 'project_id'),
        ForeignKeyConstraint(columns=['request_spec_id'],
            refcolumns=[request_specs.c.id]),
        mysql_engine='InnoDB',
        mysql_charset='utf8'
    )

    build_requests.create(checkfirst=True) 
Example 66
Project: nova   Author: ZhanHan   File: 230_add_details_column_to_instance_actions_events.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    actions_events = utils.get_table(migrate_engine, 'instance_actions_events')
    host = Column('host', String(255))
    details = Column('details', Text)
    actions_events.create_column(host)
    actions_events.create_column(details)
    shadow_actions_events = utils.get_table(migrate_engine,
            api._SHADOW_TABLE_PREFIX + 'instance_actions_events')
    shadow_actions_events.create_column(host.copy())
    shadow_actions_events.create_column(details.copy()) 
Example 67
Project: nova   Author: ZhanHan   File: 334_device_metadata_in_extra.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    for prefix in ('', 'shadow_'):
        table = Table(prefix + 'instance_extra', meta, autoload=True)
        new_column = Column('device_metadata', Text, nullable=True)
        if not hasattr(table.c, 'device_metadata'):
            table.create_column(new_column) 
Example 68
Project: nova   Author: ZhanHan   File: 332_keypair_in_extra.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    for prefix in ('', 'shadow_'):
        table = Table(prefix + 'instance_extra', meta, autoload=True)
        new_column = Column('keypairs', Text, nullable=True)
        if not hasattr(table.c, 'keypairs'):
            table.create_column(new_column) 
Example 69
Project: nova   Author: ZhanHan   File: 270_flavor_data_in_extra.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    for prefix in ('', 'shadow_'):
        table = Table(prefix + BASE_TABLE_NAME, meta, autoload=True)
        new_column = Column(NEW_COLUMN_NAME, Text, nullable=True)
        if not hasattr(table.c, NEW_COLUMN_NAME):
            table.create_column(new_column) 
Example 70
Project: nova   Author: ZhanHan   File: 253_add_pci_requests_to_instance_extra_table.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    for prefix in ('', 'shadow_'):
        table = Table(prefix + BASE_TABLE_NAME, meta, autoload=True)
        new_column = Column(NEW_COLUMN_NAME, Text, nullable=True)
        if not hasattr(table.c, NEW_COLUMN_NAME):
            table.create_column(new_column) 
Example 71
Project: nova   Author: ZhanHan   File: 251_add_numa_topology_to_comput_nodes.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    compute_nodes = Table('compute_nodes', meta, autoload=True)
    shadow_compute_nodes = Table('shadow_compute_nodes', meta, autoload=True)

    numa_topology = Column('numa_topology', Text, nullable=True)
    shadow_numa_topology = Column('numa_topology', Text, nullable=True)
    compute_nodes.create_column(numa_topology)
    shadow_compute_nodes.create_column(shadow_numa_topology) 
Example 72
Project: nova   Author: ZhanHan   File: 300_migration_context.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    for prefix in ('', 'shadow_'):
        table = Table(prefix + BASE_TABLE_NAME, meta, autoload=True)
        new_column = Column(NEW_COLUMN_NAME, Text, nullable=True)
        if not hasattr(table.c, NEW_COLUMN_NAME):
            table.create_column(new_column) 
Example 73
Project: nova   Author: ZhanHan   File: 252_add_instance_extra_table.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    columns = [
        (('created_at', DateTime), {}),
        (('updated_at', DateTime), {}),
        (('deleted_at', DateTime), {}),
        (('deleted', Integer), {}),
        (('id', Integer), dict(primary_key=True, nullable=False)),
        (('instance_uuid', String(length=36)), dict(nullable=False)),
        (('numa_topology', Text), dict(nullable=True)),
     ]
    for prefix in ('', 'shadow_'):
        instances = Table(prefix + 'instances', meta, autoload=True)
        basename = prefix + 'instance_extra'
        if migrate_engine.has_table(basename):
            continue
        _columns = tuple([Column(*args, **kwargs)
                          for args, kwargs in columns])
        table = Table(basename, meta, *_columns, mysql_engine='InnoDB',
                      mysql_charset='utf8')
        table.create()

        # Index
        instance_uuid_index = Index(basename + '_idx',
                                    table.c.instance_uuid)
        instance_uuid_index.create(migrate_engine)

        # Foreign key
        if not prefix:
            fkey_columns = [table.c.instance_uuid]
            fkey_refcolumns = [instances.c.uuid]
            instance_fkey = ForeignKeyConstraint(
                columns=fkey_columns, refcolumns=fkey_refcolumns)
            instance_fkey.create() 
Example 74
Project: nova   Author: ZhanHan   File: 276_vcpu_model.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    for prefix in ('', 'shadow_'):
        table = Table(prefix + BASE_TABLE_NAME, meta, autoload=True)
        new_column = Column(NEW_COLUMN_NAME, Text, nullable=True)
        if not hasattr(table.c, NEW_COLUMN_NAME):
            table.create_column(new_column) 
Example 75
Project: nova   Author: ZhanHan   File: 228_add_metrics_in_compute_nodes.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    # Add a new column metrics to save metrics info for compute nodes
    compute_nodes = Table('compute_nodes', meta, autoload=True)
    shadow_compute_nodes = Table('shadow_compute_nodes', meta, autoload=True)

    metrics = Column('metrics', Text, nullable=True)
    shadow_metrics = Column('metrics', Text, nullable=True)
    compute_nodes.create_column(metrics)
    shadow_compute_nodes.create_column(shadow_metrics) 
Example 76
Project: nova   Author: ZhanHan   File: models.py    Apache License 2.0 5 votes vote down vote up
def MediumText():
    return Text().with_variant(MEDIUMTEXT(), 'mysql') 
Example 77
Project: pinnwand   Author: supakeen   File: database.py    MIT License 4 votes vote down vote up
def __init__(
        self,
        raw: str,
        lexer: str = "text",
        expiry: datetime.timedelta = datetime.timedelta(days=7),
        src: str = None,
        filename: Optional[str] = None,
    ) -> None:
        # Start with some basic housekeeping related to size
        if len(raw) > configuration.paste_size:
            raise error.ValidationError(
                f"Text exceeds size limit {configuration.paste_size//1024} (kB)"
            )

        self.pub_date = datetime.datetime.utcnow()
        self.chg_date = datetime.datetime.utcnow()

        # Generate a paste_id and a removal_id
        # Unless someone proves me wrong that I need to check for collisions
        # my famous last words will be that the odds are astronomically small
        self.paste_id = self.create_paste_id()
        self.removal_id = self.create_removal_id()

        self.raw = raw

        self.src = src

        self.filename = filename

        self.lexer = lexer

        lexer = pygments.lexers.get_lexer_by_name(lexer)
        formatter = pygments.formatters.HtmlFormatter(  # pylint: disable=no-member
            linenos=True, cssclass="source"
        )

        formatted = pygments.highlight(self.raw, lexer, formatter)

        if len(formatted) >= configuration.paste_size:
            raise error.ValidationError(
                f"Highlighted text exceeds size limit ({configuration.paste_size//1024} kB)"
            )

        self.fmt = formatted

        # The expires date is the pub_date with the delta of the expiry
        if expiry:
            self.exp_date = self.pub_date + expiry
        else:
            self.exp_date = None 
Example 78
Project: circleci-demo-python-flask   Author: CircleCI-Public   File: 7257da855061_.py    MIT License 4 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('roles',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.Column('default', sa.Boolean(), nullable=True),
    sa.Column('permissions', sa.Integer(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_index(op.f('ix_roles_default'), 'roles', ['default'], unique=False)
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('email', sa.String(length=64), nullable=True),
    sa.Column('username', sa.String(length=64), nullable=True),
    sa.Column('role_id', sa.Integer(), nullable=True),
    sa.Column('password_hash', sa.String(length=128), nullable=True),
    sa.Column('confirmed', sa.Boolean(), nullable=True),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.Column('location', sa.String(length=64), nullable=True),
    sa.Column('about_me', sa.Text(), nullable=True),
    sa.Column('member_since', sa.DateTime(), nullable=True),
    sa.Column('last_seen', sa.DateTime(), nullable=True),
    sa.Column('avatar_hash', sa.String(length=32), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
    op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
    op.create_table('follows',
    sa.Column('follower_id', sa.Integer(), nullable=False),
    sa.Column('followed_id', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['followed_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['follower_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('follower_id', 'followed_id')
    )
    op.create_table('posts',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('body', sa.Text(), nullable=True),
    sa.Column('body_html', sa.Text(), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('author_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_posts_timestamp'), 'posts', ['timestamp'], unique=False)
    op.create_table('comments',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('body', sa.Text(), nullable=True),
    sa.Column('body_html', sa.Text(), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('disabled', sa.Boolean(), nullable=True),
    sa.Column('author_id', sa.Integer(), nullable=True),
    sa.Column('post_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['post_id'], ['posts.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_comments_timestamp'), 'comments', ['timestamp'], unique=False)
    # ### end Alembic commands ### 
Example 79
Project: backend.ai-manager   Author: lablup   File: bae1a7326e8a_add_domain_model.py    GNU Lesser General Public License v3.0 4 votes vote down vote up
def upgrade():
    metadata = sa.MetaData(naming_convention=convention)

    # partial table to insert "default" domain
    domains = sa.Table(
        'domains', metadata,
        sa.Column('name', sa.String(length=64), primary_key=True),
        sa.Column('description', sa.String(length=512)),
        sa.Column('is_active', sa.Boolean, default=True),
        sa.Column('total_resource_slots', ResourceSlotColumn(), nullable=False),
    )

    op.create_table(
        'domains',
        sa.Column('name', sa.String(length=64), nullable=False),
        sa.Column('description', sa.String(length=512), nullable=True),
        sa.Column('is_active', sa.Boolean(), nullable=True),
        sa.Column('created_at', sa.DateTime(timezone=True),
                  server_default=sa.text('now()'), nullable=True),
        sa.Column('modified_at', sa.DateTime(timezone=True),
                  server_default=sa.text('now()'), nullable=True),
        sa.Column('total_resource_slots',
                  postgresql.JSONB(astext_type=sa.Text()), nullable=False),
        sa.PrimaryKeyConstraint('name', name=op.f('pk_domains'))
    )
    op.add_column('users', sa.Column('domain_name', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_users_domain_name'), 'users', ['domain_name'], unique=False)
    op.create_foreign_key(op.f('fk_users_domain_name_domains'),
                          'users', 'domains', ['domain_name'], ['name'])

    # Fill in users' domain_name column with default domain.
    # Create default domain if not exist.
    connection = op.get_bind()
    query = sa.select([domains]).select_from(domains).where(domains.c.name == 'default')
    results = connection.execute(query).fetchone()
    if results is None:
        query = (sa.insert(domains)
                   .values(name='default',
                           description='Default domain',
                           is_active=True,
                           total_resource_slots='{}'))
        query = textwrap.dedent('''\
            INSERT INTO domains (name, description, is_active, total_resource_slots)
            VALUES ('default', 'Default domain', True, '{}'::jsonb);''')
        connection.execute(query)

    # Fill in users' domain_name field.
    query = "UPDATE users SET domain_name = 'default' WHERE email != 'admin@lablup.com';"
    connection.execute(query) 
Example 80
Project: rucio   Author: rucio   File: 7541902bf173_add_didsfollowed_and_followevents_table.py    Apache License 2.0 4 votes vote down vote up
def upgrade():
    '''
    Upgrade the database to this revision
    '''

    if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']:
        create_table('dids_followed',
                     sa.Column('scope', sa.String(25)),
                     sa.Column('name', sa.String(255)),
                     sa.Column('account', sa.String(25)),
                     sa.Column('did_type', DIDType.db_type(name='DIDS_FOLLOWED_TYPE_CHK')),
                     sa.Column('updated_at', sa.DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow),
                     sa.Column('created_at', sa.DateTime, default=datetime.datetime.utcnow))

        create_primary_key('DIDS_FOLLOWED_PK', 'dids_followed', ['scope', 'name', 'account'])
        create_check_constraint('DIDS_FOLLOWED_SCOPE_NN', 'dids_followed', 'scope is not null')
        create_check_constraint('DIDS_FOLLOWED_NAME_NN', 'dids_followed', 'name is not null')
        create_check_constraint('DIDS_FOLLOWED_ACCOUNT_NN', 'dids_followed', 'account is not null')
        create_check_constraint('DIDS_FOLLOWED_DID_TYPE_NN', 'dids_followed', 'did_type is not null')
        create_check_constraint('DIDS_FOLLOWED_CREATED_NN', 'dids_followed', 'created_at is not null')
        create_check_constraint('DIDS_FOLLOWED_UPDATED_NN', 'dids_followed', 'updated_at is not null')
        create_foreign_key('DIDS_FOLLOWED_ACCOUNT_FK', 'dids_followed', 'accounts',
                           ['account'], ['account'])
        create_foreign_key('DIDS_FOLLOWED_SCOPE_NAME_FK', 'dids_followed', 'dids',
                           ['scope', 'name'], ['scope', 'name'])

        create_table('dids_followed_events',
                     sa.Column('scope', sa.String(25)),
                     sa.Column('name', sa.String(255)),
                     sa.Column('account', sa.String(25)),
                     sa.Column('did_type', DIDType.db_type(name='DIDS_FOLLOWED_EVENTS_TYPE_CHK')),
                     sa.Column('event_type', sa.String(1024)),
                     sa.Column('payload', sa.Text),
                     sa.Column('updated_at', sa.DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow),
                     sa.Column('created_at', sa.DateTime, default=datetime.datetime.utcnow))

        create_primary_key('DIDS_FOLLOWED_EVENTS_PK', 'dids_followed_events', ['scope', 'name', 'account'])
        create_check_constraint('DIDS_FOLLOWED_EVENTS_SCOPE_NN', 'dids_followed_events', 'scope is not null')
        create_check_constraint('DIDS_FOLLOWED_EVENTS_NAME_NN', 'dids_followed_events', 'name is not null')
        create_check_constraint('DIDS_FOLLOWED_EVENTS_ACC_NN', 'dids_followed_events', 'account is not null')
        create_check_constraint('DIDS_FOLLOWED_EVENTS_TYPE_NN', 'dids_followed_events', 'did_type is not null')
        create_check_constraint('DIDS_FOLLOWED_EVENTS_CRE_NN', 'dids_followed_events', 'created_at is not null')
        create_check_constraint('DIDS_FOLLOWED_EVENTS_UPD_NN', 'dids_followed_events', 'updated_at is not null')
        create_foreign_key('DIDS_FOLLOWED_EVENTS_ACC_FK', 'dids_followed_events', 'accounts',
                           ['account'], ['account'])
        create_index('DIDS_FOLLOWED_EVENTS_ACC_IDX', 'dids_followed_events', ['account'])