Python alembic.op.add_column() Examples

The following are 30 code examples of alembic.op.add_column(). 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 alembic.op , or try the search function .
Example #1
Source File: d2affd5b4172_add_auto_remove_to_volume_mapping.py    From zun with Apache License 2.0 6 votes vote down vote up
def upgrade():
    op.add_column('volume_mapping',
                  sa.Column('auto_remove', sa.Boolean, nullable=True)) 
Example #2
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 #3
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 #4
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 #5
Source File: d73b72ab7cc6_add_container_type_to_container.py    From zun with Apache License 2.0 6 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('container_type', sa.Integer(), index=True,
                            default=consts.TYPE_CONTAINER,
                            server_default=str(consts.TYPE_CONTAINER))) 
Example #6
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 #7
Source File: 5c4f93e5bb4_mysql_float_to_timestamp.py    From gnocchi with Apache License 2.0 5 votes vote down vote up
def upgrade():
    bind = op.get_bind()
    if bind and bind.engine.name == "mysql":
        op.execute("SET time_zone = '+00:00'")
        # NOTE(jd) So that crappy engine that is MySQL does not have "ALTER
        # TABLE … USING …". We need to copy everything and convert…
        for table_name, column_name in (("resource", "started_at"),
                                        ("resource", "ended_at"),
                                        ("resource", "revision_start"),
                                        ("resource_history", "started_at"),
                                        ("resource_history", "ended_at"),
                                        ("resource_history", "revision_start"),
                                        ("resource_history", "revision_end"),
                                        ("resource_type", "updated_at")):

            nullable = column_name == "ended_at"

            existing_type = sa.types.DECIMAL(
                precision=20, scale=6, asdecimal=True)
            existing_col = sa.Column(
                column_name,
                existing_type,
                nullable=nullable)
            temp_col = sa.Column(
                column_name + "_ts",
                sqlalchemy_types.TimestampUTC(),
                nullable=True)
            op.add_column(table_name, temp_col)
            t = sa.sql.table(table_name, existing_col, temp_col)
            op.execute(t.update().values(
                **{column_name + "_ts": func.from_unixtime(existing_col)}))
            op.drop_column(table_name, column_name)
            op.alter_column(table_name,
                            column_name + "_ts",
                            nullable=nullable,
                            type_=sqlalchemy_types.TimestampUTC(),
                            existing_nullable=nullable,
                            existing_type=existing_type,
                            new_column_name=column_name) 
Example #8
Source File: 47d79ffdc582_add_cni_metadata_to_container.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('cni_metadata', MediumText(), nullable=True)) 
Example #9
Source File: df87dbd4846c_add_annotations_to_container.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('annotations', MediumText(), nullable=True)) 
Example #10
Source File: 5458f8394206_add_image_driver_field.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('image_driver', sa.Text(),
                            nullable=True)) 
Example #11
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 #12
Source File: bc56b9932dd9_add_runtime_to_compute_node.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('compute_node',
                  sa.Column('runtimes',
                            zun.db.sqlalchemy.models.JSONEncodedList(),
                            nullable=True)) 
Example #13
Source File: cff60402dd86_add_capsule_id_to_containers.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('capsule_id', sa.Integer(),
                            nullable=True)) 
Example #14
Source File: 1bc34e18180b_add_registry_id_to_container.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('registry_id', sa.Integer(),
                            nullable=True))
    op.create_foreign_key(
        None, 'container', 'registry', ['registry_id'], ['id']) 
Example #15
Source File: 43e1088c3389_add_image_pull_policy_column.py    From zun with 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 #16
Source File: 93fbb05b77b9_add_memory_field_to_container.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('memory', sa.String(length=255),
                            nullable=True)) 
Example #17
Source File: 174cafda0857_add_security_groups.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('container',
                  sa.Column('security_groups',
                            zun.db.sqlalchemy.models.JSONEncodedList(),
                            nullable=True)) 
Example #18
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 #19
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 #20
Source File: 4bf34495d060_add_container_number_info_to_compute_.py    From zun with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('compute_node',
                  sa.Column('total_containers', sa.Integer(), nullable=False))
    op.add_column('compute_node',
                  sa.Column('running_containers',
                            sa.Integer(), nullable=False))
    op.add_column('compute_node',
                  sa.Column('paused_containers', sa.Integer(), nullable=False))
    op.add_column('compute_node',
                  sa.Column('stopped_containers',
                            sa.Integer(), nullable=False)) 
Example #21
Source File: 0718ed97e5b3_add_tablename_to_resource_type.py    From gnocchi with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column("resource_type", sa.Column('tablename', sa.String(18),
                                             nullable=True))

    resource_type = sa.Table(
        'resource_type', sa.MetaData(),
        sa.Column('name', sa.String(255), nullable=False),
        sa.Column('tablename', sa.String(18), nullable=True)
    )
    op.execute(resource_type.update().where(
        resource_type.c.name == "instance_network_interface"
    ).values({'tablename': op.inline_literal("'instance_net_int'")}))
    op.execute(resource_type.update().where(
        resource_type.c.name != "instance_network_interface"
    ).values({'tablename': resource_type.c.name}))

    op.alter_column("resource_type", "tablename", type_=sa.String(18),
                    nullable=False)
    op.create_unique_constraint("uniq_resource_type0tablename",
                                "resource_type", ["tablename"]) 
Example #22
Source File: d24877c22ab0_add_attributes_to_resource_type.py    From gnocchi with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column("resource_type",
                  sa.Column('attributes', sa_utils.JSONType(),)) 
Example #23
Source File: 39b7d449d46a_create_metric_status_column.py    From gnocchi with Apache License 2.0 5 votes vote down vote up
def upgrade():
    enum = sa.Enum("active", "delete", name="metric_status_enum")
    enum.create(op.get_bind(), checkfirst=False)
    op.add_column("metric",
                  sa.Column('status', enum,
                            nullable=False,
                            server_default="active"))
    op.create_index('ix_metric_status', 'metric', ['status'], unique=False)

    op.drop_constraint("fk_metric_resource_id_resource_id",
                       "metric", type_="foreignkey")
    op.create_foreign_key("fk_metric_resource_id_resource_id",
                          "metric", "resource",
                          ("resource_id",), ("id",),
                          ondelete="SET NULL") 
Example #24
Source File: 7e6f9d542f8b_resource_type_state_column.py    From gnocchi with Apache License 2.0 5 votes vote down vote up
def upgrade():
    states = ("active", "creating", "creation_error", "deleting",
              "deletion_error")
    enum = sa.Enum(*states, name="resource_type_state_enum")
    enum.create(op.get_bind(), checkfirst=False)
    op.add_column("resource_type",
                  sa.Column('state', enum, nullable=False,
                            server_default="creating"))
    rt = sa.sql.table('resource_type', sa.sql.column('state', enum))
    op.execute(rt.update().values(state="active")) 
Example #25
Source File: c62df18bf4ee_add_unit_column_for_metric.py    From gnocchi with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('metric', sa.Column('unit',
                                      sa.String(length=31),
                                      nullable=True)) 
Example #26
Source File: 3bc88a29a22_.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('citizen_complaints', 'officer_years_of_service')
    op.add_column('citizen_complaints', sa.Column('officer_years_of_service', sa.String(length=255), nullable=True))
    ### end Alembic commands ### 
Example #27
Source File: 2f13ffb1ce60_.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    op.add_column('pursuits_srpd', sa.Column('bureau', sa.String(length=255), nullable=True))
    op.add_column('pursuits_srpd', sa.Column('division', sa.String(length=255), nullable=True)) 
Example #28
Source File: b13e5a5233_.py    From comport with 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('extractors', sa.Column('last_contact', sa.DateTime(), nullable=True))
    ### end Alembic commands ### 
Example #29
Source File: 1d31622bbed_.py    From comport with 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 #30
Source File: 4713e7ebca9_add_task_status_links.py    From drydock with Apache License 2.0 5 votes vote down vote up
def upgrade():
    for c in tables.Tasks.__add_result_links__:
        op.add_column(tables.Tasks.__tablename__, c)