Python sqlalchemy.String() Examples

The following are 30 code examples of sqlalchemy.String(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlalchemy , or try the search function .
Example #1
Source File: cf46a28f46bc_add_container_actions_table.py    From zun with Apache License 2.0 6 votes vote down vote up
def upgrade():
    op.create_table(
        'container_actions',
        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('action', sa.String(length=255), nullable=True),
        sa.Column('container_uuid', sa.String(length=36), nullable=False),
        sa.Column('request_id', sa.String(length=255), nullable=True),
        sa.Column('user_id', sa.String(length=255), nullable=True),
        sa.Column('project_id', sa.String(length=255), nullable=True),
        sa.Column('start_time', sa.DateTime(), nullable=True),
        sa.Column('finish_time', sa.DateTime(), nullable=True),
        sa.Column('message', sa.String(length=255), nullable=True),
        sa.Index('container_uuid_idx', 'container_uuid'),
        sa.Index('request_id_idx', 'request_id'),
        sa.ForeignKeyConstraint(['container_uuid'], ['container.uuid'], ),
        sa.PrimaryKeyConstraint('id')
    ) 
Example #2
Source File: 9fe371393a24_create_table_container.py    From zun with Apache License 2.0 6 votes vote down vote up
def upgrade():
    op.create_table(
        'container',
        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('project_id', sa.String(length=255), nullable=True),
        sa.Column('user_id', sa.String(length=255), nullable=True),
        sa.Column('uuid', sa.String(length=36), nullable=True),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('image', sa.String(length=255), nullable=True),
        sa.Column('command', sa.String(length=255), nullable=True),
        sa.Column('status', sa.String(length=20), nullable=True),
        sa.Column('environment', zun.db.sqlalchemy.models.JSONEncodedDict(),
                  nullable=True),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('uuid', name='uniq_container0uuid')
    ) 
Example #3
Source File: aba5a217ca9b_merge_created_in_creator.py    From gnocchi with Apache License 2.0 6 votes vote down vote up
def upgrade():
    for table_name in ("resource", "resource_history", "metric"):
        creator_col = sa.Column("creator", sa.String(255))
        created_by_user_id_col = sa.Column("created_by_user_id",
                                           sa.String(255))
        created_by_project_id_col = sa.Column("created_by_project_id",
                                              sa.String(255))
        op.add_column(table_name, creator_col)
        t = sa.sql.table(
            table_name, creator_col,
            created_by_user_id_col, created_by_project_id_col)
        op.execute(
            t.update().values(
                creator=(
                    created_by_user_id_col + ":" + created_by_project_id_col
                )).where((created_by_user_id_col is not None)
                         | (created_by_project_id_col is not None)))
        op.drop_column(table_name, "created_by_user_id")
        op.drop_column(table_name, "created_by_project_id") 
Example #4
Source File: e4d145e195f4_create_allocation_table.py    From zun with Apache License 2.0 6 votes vote down vote up
def upgrade():
    op.create_table(
        'allocation',
        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('resource_provider_id', sa.Integer(), nullable=False),
        sa.Column('consumer_id', sa.String(36), nullable=False),
        sa.Column('resource_class_id', sa.Integer(), nullable=False),
        sa.Column('used', sa.Integer(), nullable=False),
        sa.Column('is_nested', sa.Integer(), nullable=False),
        sa.Column('blob', zun.db.sqlalchemy.models.JSONEncodedList(),
                  nullable=True),
        sa.Index('allocation_resource_provider_class_used_idx',
                 'resource_provider_id', 'resource_class_id', 'used'),
        sa.Index('allocation_consumer_id_idx', 'consumer_id'),
        sa.Index('allocation_resource_class_id_idx', 'resource_class_id'),
        sa.PrimaryKeyConstraint('id'),
    ) 
Example #5
Source File: 33cdd98bb9b2_split_volume_mapping_table.py    From zun with Apache License 2.0 6 votes vote down vote up
def create_volume_table():
    op.create_table(
        'volume',
        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('uuid', sa.String(36), nullable=False),
        sa.Column('project_id', sa.String(length=255), nullable=True),
        sa.Column('user_id', sa.String(length=255), nullable=True),
        sa.Column('cinder_volume_id', sa.String(36), nullable=True),
        sa.Column('volume_provider', sa.String(36), nullable=False),
        sa.Column('connection_info', MediumText(), nullable=True),
        sa.Column('host', sa.String(length=255), nullable=True),
        sa.Column('auto_remove', sa.Boolean(), default=False, nullable=True),
        sa.Column('contents', MediumText(), nullable=True),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('uuid', name='uniq_volume0uuid'),
    ) 
Example #6
Source File: a9c9fb54274a_add_contents_to_volume_mapping_table.py    From zun with Apache License 2.0 6 votes vote down vote up
def upgrade():
    op.add_column('volume_mapping',
                  sa.Column('contents', MediumText(), nullable=True))
    op.alter_column('volume_mapping', 'volume_id',
                    existing_type=sa.String(36),
                    nullable=True) 
Example #7
Source File: 1192ba19a6e9_add_cpu_workdir_ports_hostname_labels_.py    From zun with Apache License 2.0 6 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('cpu', sa.Float(),
                            nullable=True))
    op.add_column('container',
                  sa.Column('workdir', sa.String(length=255),
                            nullable=True))
    op.add_column('container',
                  sa.Column('ports',
                            zun.db.sqlalchemy.models.JSONEncodedList(),
                            nullable=True))
    op.add_column('container',
                  sa.Column('hostname', sa.String(length=255),
                            nullable=True))
    op.add_column('container',
                  sa.Column('labels',
                            zun.db.sqlalchemy.models.JSONEncodedDict(),
                            nullable=True)) 
Example #8
Source File: d502ce8fb705_add_rp_uuid_to_compute_node.py    From zun with Apache License 2.0 6 votes vote down vote up
def upgrade():
    op.add_column('compute_node',
                  sa.Column('rp_uuid', sa.String(length=36), nullable=True))
    op.create_unique_constraint('uniq_compute_node0rp_uuid',
                                'compute_node', ['rp_uuid'])

    # perform data migration between tables
    session = sa.orm.Session(bind=op.get_bind())
    with session.begin(subtransactions=True):
        for row in session.query(COMPUTE_NODE_TABLE):
            session.execute(
                COMPUTE_NODE_TABLE.update().values(
                    rp_uuid=row.uuid).where(
                        COMPUTE_NODE_TABLE.c.uuid == row.uuid)
            )
    # this commit is necessary to allow further operations
    session.commit()

    op.alter_column('compute_node', 'rp_uuid',
                    nullable=False,
                    existing_type=sa.String(length=36),
                    existing_nullable=True,
                    existing_server_default=False) 
Example #9
Source File: a251f1f61217_create_capsule_table.py    From zun with 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 #10
Source File: 2b045cb595db_create_quota_quota_class_tables.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'quotas',
        sa.Column('created_at', sa.DateTime()),
        sa.Column('updated_at', sa.DateTime()),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('project_id', sa.String(length=255), index=True),
        sa.Column('resource', sa.String(length=255), nullable=False),
        sa.Column('hard_limit', sa.Integer()),
        sa.PrimaryKeyConstraint('id'),
        mysql_charset='utf8',
        mysql_engine='InnoDB'
    )

    op.create_table(
        'quota_classes',
        sa.Column('created_at', sa.DateTime()),
        sa.Column('updated_at', sa.DateTime()),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('class_name', sa.String(length=255)),
        sa.Column('resource', sa.String(length=255)),
        sa.Column('hard_limit', sa.Integer()),
        sa.Index('quota_classes_class_name_idx', 'class_name'),
        sa.PrimaryKeyConstraint('id'),
        mysql_charset='utf8',
        mysql_engine='InnoDB'
    )
    # ### end Alembic commands ### 
Example #11
Source File: 012a730926e8_add_quota_usage.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.create_table(
        'quota_usages',
        sa.Column('created_at', sa.DateTime()),
        sa.Column('updated_at', sa.DateTime()),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('project_id', sa.String(length=255), index=True),
        sa.Column('resource', sa.String(length=255), nullable=False),
        sa.Column('in_use', sa.Integer, nullable=False),
        sa.Column('reserved', sa.Integer, nullable=False),
        sa.Column('until_refresh', sa.Integer),
        mysql_engine='InnoDB'
    ) 
Example #12
Source File: a019998b09b5_add_host_to_image.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('image',
                  sa.Column('host', sa.String(length=255), nullable=True))
    op.drop_constraint(constraint_name='uniq_image0repotag',
                       table_name='image', type_='unique')
    op.create_unique_constraint(constraint_name='uniq_image0repotaghost',
                                table_name='image',
                                columns=['repo', 'tag', 'host']) 
Example #13
Source File: 63a08e32cc43_add_task_state_to_container.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('task_state', sa.String(length=20),
                            nullable=True)) 
Example #14
Source File: 37bce72463e3_add_pci_device.py    From zun with 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 #15
Source File: 6ff4d35f4334_change_property_of_restart_policy_in_.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.alter_column('capsule', 'restart_policy',
                    type_=sa.String(length=255)
                    ) 
Example #16
Source File: eeac0d191f5a_add_compute_node_table.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.create_table(
        'compute_node',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('uuid', sa.String(length=36), nullable=False),
        sa.Column('hostname', sa.String(length=255), nullable=False),
        sa.Column('numa_topology', models.JSONEncodedDict(), nullable=True),
        sa.PrimaryKeyConstraint('uuid'),
    ) 
Example #17
Source File: 56189bfb2c5f_.py    From gitlab-tools with GNU General Public License v3.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('fingerprint',
    sa.Column('updated', sa.DateTime(), nullable=True),
    sa.Column('created', sa.DateTime(), nullable=True),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('hostname', sa.String(length=255), nullable=True),
    sa.Column('sha256_fingerprint', sa.String(length=255), nullable=True),
    sa.Column('hashed_hostname', sa.String(length=255), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('user_id', 'hashed_hostname', name='_user_id_hashed_hostname_uc')
    )
    op.create_index(op.f('ix_fingerprint_hashed_hostname'), 'fingerprint', ['hashed_hostname'], unique=False)
    op.create_index(op.f('ix_fingerprint_user_id'), 'fingerprint', ['user_id'], unique=False)
    # ### end Alembic commands ### 
Example #18
Source File: d4841aeeb072_.py    From gitlab-tools with 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 #19
Source File: a9a92eebd9a8_create_table_zun_service.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.create_table(
        'zun_service',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('report_count', sa.Integer(), nullable=False),
        sa.Column('host', sa.String(length=255), nullable=True),
        sa.Column('binary', sa.String(length=255), nullable=True),
        sa.Column('disabled', sa.Boolean(), nullable=True),
        sa.Column('disabled_reason', sa.String(length=255), nullable=True),
        sa.Column('last_seen_up', sa.DateTime(), nullable=True),
        sa.Column('forced_down', sa.Boolean(), nullable=True),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('host', 'binary',
                            name='uniq_zun_service0host0binary')
    ) 
Example #20
Source File: 8192905fd835_add_uuid_to_resource_class.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('resource_class',
                  sa.Column('uuid', sa.String(length=36), nullable=False))
    op.create_unique_constraint('uniq_resource_class0uuid',
                                'resource_class', ['uuid'])
    op.drop_index('uniq_container0name', table_name='resource_class') 
Example #21
Source File: ad43a2179cf2_add_status_detail.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('container', sa.Column('status_detail',
                  sa.String(length=50), nullable=True)) 
Example #22
Source File: 531e4a890480_add_host_to_container.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('host', sa.String(length=255),
                            nullable=True)) 
Example #23
Source File: 3f49fa520409_add_availability_zone_to_service.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('zun_service',
                  sa.Column('availability_zone', sa.String(255),
                            nullable=True)) 
Example #24
Source File: 945569b3669f_add_runtime_column.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('runtime', sa.String(32), nullable=True)) 
Example #25
Source File: 5971a6844738_add_container_id_column_to_container.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('container_id', sa.String(length=255),
                            nullable=True)) 
Example #26
Source File: 04ba87af76bb_add_container_host_operating_system_info.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('compute_node',
                  sa.Column('architecture', sa.String(32), nullable=True))
    op.add_column('compute_node',
                  sa.Column('os_type', sa.String(32), nullable=True))
    op.add_column('compute_node',
                  sa.Column('os', sa.String(64), nullable=True))
    op.add_column('compute_node',
                  sa.Column('kernel_version',
                            sa.String(128), nullable=True)) 
Example #27
Source File: sqlalchemy_extension.py    From gnocchi with Apache License 2.0 5 votes vote down vote up
def satype(self):
        return sqlalchemy.String(self.max_length) 
Example #28
Source File: 828c16f70cce_create_resource_type_table.py    From gnocchi with Apache License 2.0 5 votes vote down vote up
def upgrade():
    resource_type = op.create_table(
        'resource_type',
        sa.Column('name', sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint('name'),
        mysql_charset='utf8',
        mysql_engine='InnoDB'
    )

    resource = sa.Table('resource', sa.MetaData(),
                        type_string_col("type", "resource"))
    op.execute(resource_type.insert().from_select(
        ['name'], sa.select([resource.c.type]).distinct()))

    for table in ["resource", "resource_history"]:
        op.alter_column(table, "type", new_column_name="old_type",
                        existing_type=type_enum)
        op.add_column(table, type_string_col("type", table))
        sa_table = sa.Table(table, sa.MetaData(),
                            type_string_col("type", table),
                            type_enum_col('old_type'))
        op.execute(sa_table.update().values(
            {sa_table.c.type: sa_table.c.old_type}))
        op.drop_column(table, "old_type")
        op.alter_column(table, "type", nullable=False,
                        existing_type=type_string) 
Example #29
Source File: 1c2c61ac1f4c_add_original_resource_id_column.py    From gnocchi with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('resource', sa.Column('original_resource_id',
                                        sa.String(length=255),
                                        nullable=True))
    op.add_column('resource_history', sa.Column('original_resource_id',
                                                sa.String(length=255),
                                                nullable=True)) 
Example #30
Source File: 34c517bcc2dd_shorter_foreign_key.py    From gnocchi with Apache License 2.0 5 votes vote down vote up
def upgrade():
    connection = op.get_bind()

    insp = sqlalchemy.inspect(connection)

    op.alter_column("resource_type", "tablename",
                    type_=sqlalchemy.String(35),
                    existing_type=sqlalchemy.String(18), nullable=False)

    for rt in connection.execute(resource_type_helper.select()):
        if rt.tablename == "generic":
            continue

        fk_names = [fk['name'] for fk in insp.get_foreign_keys("%s_history" %
                                                               rt.tablename)]
        fk_old = ("fk_%s_history_resource_history_revision" %
                  rt.tablename)
        if fk_old not in fk_names:
            # The table have been created from scratch recently
            fk_old = ("fk_%s_history_revision_resource_history_revision" %
                      rt.tablename)

        fk_new = "fk_%s_h_revision_rh_revision" % rt.tablename
        to_rename.append((fk_old, fk_new, 'resource_history', 'revision',
                          "%s_history" % rt.tablename, 'revision', 'CASCADE'))

    for (fk_old, fk_new, src_table, src_col, dst_table, dst_col, ondelete
         ) in to_rename:
        op.drop_constraint(fk_old, dst_table, type_="foreignkey")
        op.create_foreign_key(fk_new, dst_table, src_table,
                              [dst_col], [src_col], ondelete=ondelete)