微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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),
                  sa.Column('ports',
                            zun.db.sqlalchemy.models.JSONEncodedList(),
                  sa.Column('hostname',
                  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', nullable=True))
    op.add_column('container_states', sa.Column('pod_state_id', 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',
                       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',
                       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', 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,
            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, 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', MysqL.INTEGER(display_width=11), nullable=False))
    op.add_column('likes', nullable=False))
    op.add_column('custom_tag', 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', 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', 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', 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', 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', 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.Column('calibration_frac', sa.Float, sa.Column('bolt_course_id', sa.Column('long_tasks', default=0))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def downgrade():
    op.add_column('project', sa.Column('hidden', 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.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', 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', unique=True))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('app', sa.BOOLEAN, default=True))
    query = 'UPDATE app SET %s = True;' % field
    op.execute(query)
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('task', postgresql.ARRAY(sa.Integer)))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('project', 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', default=30))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('user', sa.Column('google_user_id', unique=True))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('user', sa.Column('subscribed', default=True))
    query = 'UPDATE "user" SET subscribed=true;'
    op.execute(query)
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('user', default="en"))
    query = 'UPDATE "user" SET %s=\'en\';' % field
    op.execute(query)
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('blogpost', sa.String))
    op.add_column('blogpost', sa.Column('info', JSON))
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.add_column('user', sa.Column('valid_email', default=False))
    op.add_column('user', sa.Column('confirmation_email_sent', 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', 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.Column('mobile_app_installs', sa.Column('mobile_app_purchases', nullable=True))
    op.add_column('bit_performance_report', nullable=True))
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_appsflyer_connector', nullable=False))
    op.drop_constraint(u'bit_appsflyer_connector_connector_id_fkey', 'bit_appsflyer_connector', type_='foreignkey')
    op.create_foreign_key(None, '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, type_='foreignkey')
    op.create_foreign_key(u'bit_appsflyer_connector_connector_id_fkey', ['connector_id'], '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', 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', 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', 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', nullable=True))
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_connectors_appsflyer', nullable=False))
    op.create_foreign_key(None, 'bit_connectors_appsflyer', ['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', 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), nullable=True))
    op.add_column('bit_facebook_daily_ad_insights', sa.Column('native_id', 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', nullable=True))
    op.add_column('bit_etl_tables', sa.Column('sync_next_time', nullable=True))
    # ### end Alembic commands ###

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐