Python alembic.op 模块,add_column() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用alembic.op.add_column()

项目:zun    作者:openstack    | 项目源码 | 文件源码
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))
项目:kuberdock-platform    作者:cloudlinux    | 项目源码 | 文件源码
def upgrade():
    op.execute(sa.schema.CreateSequence(sa.Sequence('pod_states_id_seq')))
    op.add_column('pod_states', sa.Column('id', sa.Integer(), nullable=False,
                  server_default=sa.text("nextval('pod_states_id_seq'::regclass)")))
    op.execute("ALTER TABLE pod_states DROP CONSTRAINT pod_states_pkey, "
               "ADD CONSTRAINT pod_states_pkey PRIMARY KEY (id);")

    op.add_column('container_states', sa.Column('exit_code', sa.Integer(), nullable=True))
    op.add_column('container_states', sa.Column('pod_state_id', sa.Integer(), nullable=True))
    op.add_column('container_states', sa.Column('reason', sa.Text(), nullable=True))
    op.create_index('ix_pod_id_start_time', 'pod_states', ['pod_id', 'start_time'], unique=True)
    op.create_foreign_key('container_states_pod_state_id_fkey', 'container_states',
                          'pod_states', ['pod_state_id'], ['id'])

    upgrade_data()

    op.alter_column('container_states', 'pod_state_id',
                    existing_type=sa.INTEGER(), nullable=False)
    op.drop_constraint(u'container_states_pod_id_fkey', 'container_states',
                       type_='foreignkey')
    op.drop_column('container_states', 'pod_id')
项目:kuberdock-platform    作者:cloudlinux    | 项目源码 | 文件源码
def downgrade():
    op.add_column('container_states', sa.Column('pod_id', postgresql.UUID(),
                  autoincrement=False, nullable=True))
    op.create_foreign_key(u'container_states_pod_id_fkey',
                          'container_states', 'pods', ['pod_id'], ['id'])

    downgrade_data()

    op.drop_column('container_states', 'reason')
    op.drop_column('container_states', 'exit_code')
    op.drop_constraint('container_states_pod_state_id_fkey', 'container_states',
                       type_='foreignkey')
    op.drop_index('ix_pod_id_start_time', table_name='pod_states')
    op.drop_column('container_states', 'pod_state_id')
    op.execute("ALTER TABLE pod_states DROP CONSTRAINT pod_states_pkey, "
               "ADD CONSTRAINT pod_states_pkey PRIMARY KEY (pod_id, start_time);")
    op.drop_column('pod_states', 'id')
    op.execute(sa.schema.DropSequence(sa.Sequence('pod_states_id_seq')))
项目:kuberdock-platform    作者:cloudlinux    | 项目源码 | 文件源码
def upgrade():
    bind = op.get_bind()
    session = Session(bind=bind)
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users', sa.Column('timezone', sa.String(length=64), server_default='UTC', nullable=False))
    ### end Alembic commands ###
    key = 'timezone'
    for user in session.query(User):
        settings = json.loads(user.settings) if user.settings else {}
        if key in settings:
            user.timezone = settings[key]
            del settings[key]
            user.settings = json.dumps(settings)
        else:
            user.timezone = DEFAULT_TIMEZONE
    session.commit()
项目:fuel-nailgun-extension-iac    作者:openstack    | 项目源码 | 文件源码
def upgrade():
    table_prefix = context.config.get_main_option('table_prefix')
    op.add_column(
        table_prefix + 'repos',
        sa.Column('manage_master', sa.Boolean(), nullable=True)
    )
项目:fuel-nailgun-extension-iac    作者:openstack    | 项目源码 | 文件源码
def upgrade():
    table_prefix = context.config.get_main_option('table_prefix')
    op.add_column(
        table_prefix + 'changes_whitelist',
        sa.Column('fuel_task', sa.String, server_default='', nullable=False)
    )
项目:zlktqa    作者:NunchakusHuang    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('answers', sa.Column('create_time', sa.DateTime(), nullable=True))
    # ### end Alembic commands ###
项目:zlktqa    作者:NunchakusHuang    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('questions', sa.Column('create_time', sa.DateTime(), nullable=True))
    # ### end Alembic commands ###
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def batch_alter_column(
        cls, operations, column_name,
        nullable=None,
        server_default=False,
        new_column_name=None,
        type_=None,
        existing_type=None,
        existing_server_default=False,
        existing_nullable=None,
        **kw
    ):
        """Issue an "alter column" instruction using the current
        batch migration context.

        .. seealso::

            :meth:`.Operations.add_column`

        """
        alt = cls(
            operations.impl.table_name, column_name,
            schema=operations.impl.schema,
            existing_type=existing_type,
            existing_server_default=existing_server_default,
            existing_nullable=existing_nullable,
            modify_name=new_column_name,
            modify_type=type_,
            modify_server_default=server_default,
            modify_nullable=nullable,
            **kw
        )

        return operations.invoke(alt)
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def to_diff_tuple(self):
        return ("add_column", self.schema, self.table_name, self.column)
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def batch_add_column(cls, operations, column):
        """Issue an "add column" instruction using the current
        batch migration context.

        .. seealso::

            :meth:`.Operations.add_column`

        """
        op = cls(
            operations.impl.table_name, column,
            schema=operations.impl.schema
        )
        return operations.invoke(op)
项目:BookCloud    作者:livro-aberto    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('named_tag', sa.Column('file_regexp', sa.String(length=200), nullable=True))
    # ### end Alembic commands ###
项目:BookCloud    作者:livro-aberto    | 项目源码 | 文件源码
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('user_tag', sa.Column('id', mysql.INTEGER(display_width=11), nullable=False))
    op.add_column('likes', sa.Column('id', mysql.INTEGER(display_width=11), nullable=False))
    op.add_column('custom_tag', sa.Column('id', mysql.INTEGER(display_width=11), nullable=False))
    # ### end Alembic commands ###
项目:gloss    作者:openhealthcare    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('subscription', sa.Column('end_point', sa.String(length=250), nullable=True))
    ### end Alembic commands ###
项目:gloss    作者:openhealthcare    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('result', sa.Column('profile_description', sa.String(length=250), nullable=True))
    ### end Alembic commands ###
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('user', sa.Column('privacy_mode', sa.Boolean, default=True))
    query = 'UPDATE "user" SET privacy_mode=true;'
    op.execute(query)
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('app', sa.Column('long_description', sa.Unicode))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('blogpost', sa.Column('published', sa.Boolean, default=False))
    op.add_column('blogpost', sa.Column('updated', sa.Text,
                                       default=make_timestamp))
    sql = 'update blogpost set published=true'
    op.execute(sql)
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('user', sa.Column('admin', sa.Boolean, default=False))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    # First, create column and fill all records with default value.
    # To avoid integrity error, the constraint non-nullable will be set after that
    op.add_column('app', sa.Column('featured', sa.Boolean, default=False))
    query = 'UPDATE "app" SET featured=false;'
    op.execute(query)
    op.alter_column('app', 'featured', nullable=False)
    query = 'UPDATE "app" SET featured=true WHERE app.id IN (SELECT app_id FROM FEATURED);'
    op.execute(query)
    op.drop_table('featured')
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def downgrade():
    op.add_column('project', sa.Column('completed', sa.Boolean, default=False))
    query = 'UPDATE project SET completed=false;'
    op.execute(query)
    op.alter_column('project', 'completed', nullable=False)

    update_completed = '''
        WITH completed_tasks AS (
        SELECT project.id, COUNT(task.id) as n_completed_tasks FROM project, task
        WHERE task.state='completed' AND task.project_id=project.id
        GROUP BY project.id
        ), total_tasks AS (
        SELECT project.id, COUNT(task.id) as n_tasks FROM project, task
        WHERE task.project_id=project.id
        GROUP BY project.id
        )
        UPDATE project SET completed=true WHERE project.id IN (
            SELECT total_tasks.id
            FROM completed_tasks INNER JOIN total_tasks ON completed_tasks.id=total_tasks.id
        );
    '''

    op.execute(update_completed)
    # sql = sa.sql.text('''SELECT COUNT(task.id) AS n_completed_tasks FROM task
    #             WHERE task.project_id=:project_id AND task.state=\'completed\';''')
    # sql = sa.sql.text('''SELECT COUNT(task.id) AS n_tasks FROM task
    #               WHERE task.project_id=:project_id''')
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def downgrade():
    op.add_column('project', sa.Column('time_estimate', sa.Integer, default=0))
    op.add_column('project', sa.Column('time_limit', sa.Integer, default=0))
    op.add_column('project', sa.Column('calibration_frac', sa.Float, default=0))
    op.add_column('project', sa.Column('bolt_course_id', sa.Integer, default=0))
    op.add_column('project', sa.Column('long_tasks', sa.Integer, default=0))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def downgrade():
    op.add_column('project', sa.Column('hidden', sa.Integer, default=0))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('user', sa.Column(field, sa.String))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('task_run', sa.Column(field, sa.String))
    op.add_column('project', sa.Column('secret_key', sa.String))
    query = 'update project set secret_key=md5(random()::text);'
    op.execute(query)
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('app', sa.Column('webhook', sa.Text))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('user', sa.Column('pro', sa.Boolean, default=False))
    query = 'UPDATE "user" SET pro=false;'
    op.execute(query)
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('user', sa.Column('twitter_user_id', sa.Integer, unique=True))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('app', sa.Column(field, sa.BOOLEAN, default=True))
    query = 'UPDATE app SET %s = True;' % field
    op.execute(query)
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('task', sa.Column(field, postgresql.ARRAY(sa.Integer)))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('project', sa.Column('published', sa.Boolean, default=False))
    query = 'UPDATE "project" SET published=false;'
    op.execute(query)
    op.alter_column('project', 'published', nullable=False)
    query = """UPDATE "project" SET published=true
               WHERE project.id IN
               (SELECT project.id FROM project, task WHERE
               project.id=task.project_id AND
               (project.info->>'task_presenter') IS NOT NULL AND
               (project.info->>'task_presenter')!=''
               GROUP BY project.id);"""
    op.execute(query)
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('task', sa.Column('n_answers', sa.Integer, default=30))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('user', sa.Column('google_user_id', sa.String, unique=True))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('user', sa.Column('subscribed', sa.Boolean, default=True))
    query = 'UPDATE "user" SET subscribed=true;'
    op.execute(query)
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('user', sa.Column(field, sa.String, default="en"))
    query = 'UPDATE "user" SET %s=\'en\';' % field
    op.execute(query)
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('blogpost', sa.Column(field, sa.String))
    op.add_column('blogpost', sa.Column('info', JSON))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('user', sa.Column('valid_email', sa.Boolean, default=False))
    op.add_column('user', sa.Column('confirmation_email_sent', sa.Boolean, default=False))
    query = 'UPDATE "user" SET valid_email=false;'
    op.execute(query)
    query = 'UPDATE "user" SET confirmation_email_sent=false;'
    op.execute(query)
项目:tuning-box    作者:openstack    | 项目源码 | 文件源码
def upgrade():
    table_prefix = context.config.get_main_option('table_prefix')
    op.add_column(table_prefix + 'resource_values', sa.Column(
        'overrides',
        tuning_box.db.Json(),
        server_default='{}',
        nullable=True,
    ))
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_etl_tables', sa.Column('is_active', sa.Boolean(), nullable=True))
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_facebook_daily_ad_insights_impression_device', sa.Column('cost_per_mobile_app_installs', sa.Numeric(), nullable=True))
    op.add_column('bit_facebook_daily_ad_insights_impression_device', sa.Column('cost_per_mobile_app_purchases', sa.Numeric(), nullable=True))
    op.add_column('bit_facebook_daily_ad_insights_impression_device', sa.Column('mobile_app_installs', sa.Integer(), nullable=True))
    op.add_column('bit_facebook_daily_ad_insights_impression_device', sa.Column('mobile_app_purchases', sa.Integer(), nullable=True))
    op.add_column('bit_performance_report', sa.Column('cost_per_mobile_app_installs', sa.Numeric(), nullable=True))
    op.add_column('bit_performance_report', sa.Column('cost_per_mobile_app_purchases', sa.Numeric(), nullable=True))
    op.add_column('bit_performance_report', sa.Column('mobile_app_installs', sa.Integer(), nullable=True))
    op.add_column('bit_performance_report', sa.Column('mobile_app_purchases', sa.Integer(), nullable=True))
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_appsflyer_connector', sa.Column('id', sa.Integer(), nullable=False))
    op.drop_constraint(u'bit_appsflyer_connector_connector_id_fkey', 'bit_appsflyer_connector', type_='foreignkey')
    op.create_foreign_key(None, 'bit_appsflyer_connector', 'bit_connectors', ['id'], ['id'])
    op.drop_column('bit_appsflyer_connector', 'connector_id')
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_appsflyer_connector', sa.Column('connector_id', sa.INTEGER(), autoincrement=False, nullable=False))
    op.drop_constraint(None, 'bit_appsflyer_connector', type_='foreignkey')
    op.create_foreign_key(u'bit_appsflyer_connector_connector_id_fkey', 'bit_appsflyer_connector', 'bit_connectors', ['connector_id'], ['id'])
    op.drop_column('bit_appsflyer_connector', 'id')
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_etl_tables', sa.Column('save_in_prt', sa.Boolean(), nullable=True))
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('table_columns', sa.Column('is_index', sa.Boolean(), nullable=True))
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_etl_tables', sa.Column('datasource', sa.String(length=250), nullable=True))
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_facebook_daily_ad_insights_impression_device', sa.Column('cost', sa.Numeric(), nullable=True))
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_connectors_appsflyer', sa.Column('connector_id', sa.Integer(), nullable=False))
    op.create_foreign_key(None, 'bit_connectors_appsflyer', 'bit_connectors', ['connector_id'], ['id'])
    op.drop_column('bit_connectors_appsflyer', 'id')
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_connectors_appsflyer', sa.Column('id', sa.INTEGER(), nullable=False))
    op.drop_constraint(None, 'bit_connectors_appsflyer', type_='foreignkey')
    op.drop_column('bit_connectors_appsflyer', 'connector_id')
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_facebook_daily_ad_insights', sa.Column('campaign_id', sa.VARCHAR(length=255), autoincrement=False, nullable=True))
    op.add_column('bit_facebook_daily_ad_insights', sa.Column('native_id', sa.VARCHAR(length=255), autoincrement=False, nullable=True))
    op.create_index('ix_bit_facebook_daily_ad_insights_native_id', 'bit_facebook_daily_ad_insights', ['native_id'], unique=True)
    op.drop_column('bit_facebook_daily_ad_insights', 'date_start')
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_etl_tables', sa.Column('sync_last_time', sa.DateTime(), nullable=True))
    op.add_column('bit_etl_tables', sa.Column('sync_next_time', sa.DateTime(), nullable=True))
    # ### end Alembic commands ###