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

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

项目: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')))
项目:GenomicsSampleAPIs    作者:Intel-HLS    | 项目源码 | 文件源码
def downgrade():
    # Drop trigger
    op.execute(
        'DROP TRIGGER increment_num_rows_in_db_array ON callset_to_db_array_association CASCADE')
    op.drop_column(u'db_array', 'num_rows')
    op.create_table(
        'db_row',
        sa.Column('id', sa.BIGINT(), nullable=False),
        sa.Column('db_array_id', sa.BIGINT(), autoincrement=False, nullable=False),
        sa.Column('tile_row_id', sa.BIGINT(), autoincrement=False, nullable=False),
        sa.ForeignKeyConstraint(['db_array_id'],[u'db_array.id'], name=u'db_row_db_array_id_fkey'),
        sa.PrimaryKeyConstraint('id', name=u'db_row_pkey'))
    op.add_column(
        u'callset',
        sa.Column('individual_id', sa.BIGINT(), autoincrement=False, nullable=False))
    op.add_column(u'callset', sa.Column('dbrow_id', sa.BIGINT(), autoincrement=False, nullable=False))
    op.drop_constraint('callset_source_sample_id_fkey','callset', type_='foreignkey')
    op.drop_constraint('callset_target_sample_id_fkey','callset', type_='foreignkey')
    op.create_foreign_key(u'callset_individual_id_fkey','callset', 'individual', ['individual_id'], ['id'])
    op.create_foreign_key(u'callset_dbrow_id_fkey','callset', 'db_row', ['dbrow_id'], ['id'])
    op.drop_column(u'callset', 'target_sample_id')
    op.drop_column(u'callset', 'source_sample_id')
    op.drop_index('db_array_id_tile_row_id_idx',table_name='callset_to_db_array_association')
    op.drop_table('callset_to_db_array_association')
    op.drop_table('sample')
项目:Callandtext    作者:iaora    | 项目源码 | 文件源码
def create_foreign_key(
            self, name, referent, local_cols, remote_cols, **kw):
        """Issue a "create foreign key" instruction using the
        current batch migration context.

        The batch form of this call omits the ``source`` and ``source_schema``
        arguments from the call.

        e.g.::

            with batch_alter_table("address") as batch_op:
                batch_op.create_foreign_key(
                            "fk_user_address",
                            "user", ["user_id"], ["id"])

        .. seealso::

            :meth:`.Operations.create_foreign_key`

        """
        return super(BatchOperations, self).create_foreign_key(
            name, self.impl.table_name, referent, local_cols, remote_cols,
            source_schema=self.impl.schema, **kw)
项目:biweeklybudget    作者:jantman    | 项目源码 | 文件源码
def upgrade():
    # When making changes to a column that has a foreign key, we need to drop
    # and then re-add the constraint
    op.execute('DELETE FROM txn_reconciles WHERE txn_id IS NULL;')
    op.execute('LOCK TABLES txn_reconciles WRITE, transactions WRITE;')
    op.drop_constraint('fk_txn_reconciles_txn_id_transactions',
                       'txn_reconciles', type_='foreignkey')
    op.alter_column(
        'txn_reconciles',
        'txn_id',
        existing_type=mysql.INTEGER(display_width=11),
        nullable=False
    )
    op.create_foreign_key('fk_txn_reconciles_txn_id_transactions',
                          'txn_reconciles', 'transactions', ['txn_id'], ['id'])
    op.execute('UNLOCK TABLES;')
项目:mini    作者:JJWSSS    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('comments', sa.Column('goodsID', sa.Integer(), nullable=True))
    op.alter_column('comments', 'commentatorID',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=True)
    op.drop_constraint('comments_ibfk_2', 'comments', type_='foreignkey')
    op.create_foreign_key(None, 'comments', 'goods', ['goodsID'], ['goodID'])
    op.drop_column('comments', 'goodID')
    op.add_column('goods', sa.Column('address', sa.String(length=128), nullable=False))
    op.add_column('goods', sa.Column('poster', sa.String(length=128), nullable=False))
    op.add_column('goods', sa.Column('times', sa.Integer(), nullable=True))
    op.alter_column('orders', 'createDate',
               existing_type=mysql.DATETIME(),
               nullable=False)
    ### end Alembic commands ###
项目:mini    作者:JJWSSS    | 项目源码 | 文件源码
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('orders', 'createDate',
               existing_type=mysql.DATETIME(),
               nullable=True)
    op.drop_column('goods', 'times')
    op.drop_column('goods', 'poster')
    op.drop_column('goods', 'address')
    op.add_column('comments', sa.Column('goodID', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False))
    op.drop_constraint(None, 'comments', type_='foreignkey')
    op.create_foreign_key('comments_ibfk_2', 'comments', 'goods', ['goodID'], ['goodID'])
    op.alter_column('comments', 'commentatorID',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=False)
    op.drop_column('comments', 'goodsID')
    ### end Alembic commands ###
项目:zeus    作者:getsentry    | 项目源码 | 文件源码
def upgrade():
    # we dont retain historical data as we simply dont care yet
    op.execute('truncate table filecoverage')
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('filecoverage', sa.Column(
        'build_id', zeus.db.types.guid.GUID(), nullable=False))
    op.create_index(op.f('ix_filecoverage_build_id'),
                    'filecoverage', ['build_id'], unique=False)
    op.create_unique_constraint('unq_coverage_filname', 'filecoverage', [
                                'build_id', 'filename'])
    op.drop_constraint('unq_job_filname', 'filecoverage', type_='unique')
    op.drop_constraint('filecoverage_job_id_fkey',
                       'filecoverage', type_='foreignkey')
    op.create_foreign_key(None, 'filecoverage', 'build', [
                          'build_id'], ['id'], ondelete='CASCADE')
    op.drop_column('filecoverage', 'job_id')
    # ### end Alembic commands ###
项目:reahl    作者:reahl    | 项目源码 | 文件源码
def change_inheriting_table(self, table_name, old_id_column_name, parent_table_name):
        """Tables of classes that inherit from other classes (using joint table inheritance) named their
           primary key columns xxx_id (assuming the parent is called xxx here). These were also foreign
           keys to the primary key of the parent table. In our Declarative implementation we just always use
           the name `id` for a primary key regardless of the situation.

           This method renames such primary key columns, and deal with the knock-on effect of this change 
           to related primary and foreign key as well.

           :arg table_name: The name of the table underlying the child/inheriting class.
           :arg old_id_column_name: The old name of the primary key column of the child/inheriting class.
           :arg parent_table_name: The name of the table underlying the parent class.
        """
        self.schedule('drop_fk', op.drop_constraint, '%s_%s_fkey' % (table_name, old_id_column_name), table_name)
        self.rename_pk_column(table_name, old_id_column_name, 'id', ['id'])
        self.schedule('create_fk', op.create_foreign_key, fk_name(table_name, 'id', parent_table_name), table_name, 
                      parent_table_name, ['id'], ['id'], ondelete='CASCADE')
项目:reahl    作者:reahl    | 项目源码 | 文件源码
def rename_link_table(self):
        old_table_name = 'requirement_deferred_actions__deferredaction_requirements'
        new_table_name = 'deferredaction_requirement'

        # Rename table itself
        self.schedule('alter', op.rename_table, old_table_name, new_table_name)

        # Rename of foreign key names
        for old_name, other_table_name in [
                ('deferredaction_requirements_fk', 'deferredaction'),
                ('requirement_deferred_actions_fk', 'requirement') ]:
            column_name = '%s_id' % other_table_name
            new_name = fk_name(new_table_name, column_name, other_table_name)
            self.schedule('drop_fk', op.drop_constraint, old_name, old_table_name)
            self.schedule('create_fk', op.create_foreign_key, new_name, new_table_name, other_table_name, [column_name], ['id'])

        # Primary keys are renamed according to new naming convention - in this case the table too
        self.rename_pk(new_table_name, ['deferredaction_id', 'requirement_id'], old_table_name=old_table_name)
项目:cci-demo-flask    作者:circleci    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'last_name')
    op.drop_column('users', 'first_name')
    ### end Alembic commands ###
    with op.batch_alter_table("notes") as batch_op:
        batch_op.drop_constraint(
            "notes_author_id_fkey", type_="foreignkey")
    with op.batch_alter_table("notebooks") as batch_op:
        batch_op.drop_constraint(
            "notebooks_author_id_fkey", type_="foreignkey")
    op.create_foreign_key(
        "notes_author_id_fkey", "notes", "users", 
        ["author_id"], ["id"], ondelete="CASCADE")
    op.create_foreign_key(
        "notebooks_author_id_fkey", "notebooks", "users", 
        ["author_id"], ["id"], ondelete="CASCADE")
项目:gnocchi    作者:gnocchixyz    | 项目源码 | 文件源码
def upgrade():
    conn = op.get_bind()

    insp = inspect(conn)
    fk_names = [fk['name'] for fk in insp.get_foreign_keys('host')]
    if ("fk_hypervisor_id_resource_id" not in fk_names and
            "fk_host_id_resource_id" in fk_names):
        # NOTE(sileht): we are already good, the BD have been created from
        # scratch after "a54c57ada3f5"
        return

    op.drop_constraint("fk_hypervisor_id_resource_id", "host",
                       type_="foreignkey")
    op.drop_constraint("fk_hypervisor_history_resource_history_revision",
                       "host_history", type_="foreignkey")
    op.create_foreign_key("fk_host_id_resource_id", "host", "resource",
                          ["id"], ["id"], ondelete="CASCADE")
    op.create_foreign_key("fk_host_history_resource_history_revision",
                          "host_history", "resource_history",
                          ["revision"], ["revision"], ondelete="CASCADE")
项目:gnocchi    作者:gnocchixyz    | 项目源码 | 文件源码
def upgrade():
    bind = op.get_bind()
    # NOTE(sileht): mysql can't delete an index on a foreign key
    # even this one is not the index used by the foreign key itself...
    # In our case we have two indexes fk_resource_history_id_resource_id and
    # and ix_resource_history_id, we want to delete only the second, but mysql
    # can't do that with a simple DROP INDEX ix_resource_history_id...
    # so we have to remove the constraint and put it back...
    if bind.engine.name == "mysql":
        op.drop_constraint("fk_resource_history_id_resource_id",
                           type_="foreignkey", table_name="resource_history")

    for table, colname in resource_tables + history_tables + other_tables:
        op.drop_index("ix_%s_%s" % (table, colname), table_name=table)

    if bind.engine.name == "mysql":
        op.create_foreign_key("fk_resource_history_id_resource_id",
                              "resource_history", "resource", ["id"], ["id"],
                              ondelete="CASCADE")
项目:hreftoday    作者:soasme    | 项目源码 | 文件源码
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('issue',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('topic_id', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('serial', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('published_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.Column('title', sa.VARCHAR(length=128), server_default=sa.text(u"''::character varying"), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['topic_id'], [u'topic.id'], name=u'fk_issue_topic'),
    sa.ForeignKeyConstraint(['user_id'], [u'user.id'], name=u'fk_issue_user'),
    sa.PrimaryKeyConstraint('id', name=u'issue_pkey'),
    sa.UniqueConstraint('topic_id', 'serial', name=u'ux_issue_topic_serial')
    )
    op.add_column('link', sa.Column('issue_id', sa.INTEGER(), autoincrement=False, nullable=True))
    op.drop_constraint('fk_link_topic', 'link', type_='foreignkey')
    op.create_foreign_key(u'fk_link_issue', 'link', 'issue', ['issue_id'], ['id'])
    op.create_index('ix_issue', 'link', ['issue_id'], unique=False)
    op.drop_column('link', 'topic_id')
    ### end Alembic commands ###
项目:fabric8-analytics-worker    作者:fabric8-analytics    | 项目源码 | 文件源码
def upgrade():
    """Upgrade the database to a newer revision."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('stacks',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('is_ref_stack', sa.Boolean(), nullable=False),
                    sa.Column('stack_json', postgresql.JSONB(), nullable=False),
                    sa.PrimaryKeyConstraint('id'))
    op.add_column('similar_stacks', sa.Column('analysis', postgresql.JSONB()))
    op.add_column('similar_stacks', sa.Column('similar_stack_id', sa.Integer(), nullable=False))
    op.add_column('similar_stacks', sa.Column('similarity_value', sa.Float(), nullable=False))
    op.add_column('similar_stacks', sa.Column('stack_id', sa.Integer(), nullable=False))
    op.create_unique_constraint('sim_unique', 'similar_stacks', ['stack_id', 'similar_stack_id'])
    op.drop_constraint('similar_stacks_appstack_id_fkey', 'similar_stacks', type_='foreignkey')
    op.create_foreign_key(None, 'similar_stacks', 'stacks', ['stack_id'], ['id'])
    op.create_foreign_key(None, 'similar_stacks', 'stacks', ['similar_stack_id'], ['id'])
    op.drop_column('similar_stacks', 'dependency_list')
    op.drop_column('similar_stacks', 'appstack_id')
    op.drop_table('reference_stacks')
    op.drop_table('app_stacks')
    # ### end Alembic commands ###
项目:tasking-manager    作者:hotosm    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('licenses',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(), nullable=True),
    sa.Column('description', sa.String(), nullable=True),
    sa.Column('plain_text', sa.String(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('users_licenses',
    sa.Column('user', sa.BigInteger(), nullable=True),
    sa.Column('license', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['license'], ['licenses.id'], ),
    sa.ForeignKeyConstraint(['user'], ['users.id'], )
    )
    op.drop_index('idx_areas_of_interest_centroid', table_name='areas_of_interest')
    op.drop_index('idx_areas_of_interest_geometry', table_name='areas_of_interest')
    op.add_column('projects', sa.Column('license_id', sa.Integer(), nullable=True))
    op.create_foreign_key('fk_licenses', 'projects', 'licenses', ['license_id'], ['id'])
    op.drop_index('idx_tasks_geometry', table_name='tasks')
    # ### end Alembic commands ###

    # Custom index, not created with reflection
    op.create_index('idx_username_lower', 'users', [text('lower(username)')])
项目:vilfredo-core    作者:fairdemocracy    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    voting_types = op.create_table('voting_types',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=25), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    ### Populate with question types
    op.bulk_insert(voting_types,
        [
            {'name':'triangle'},
            {'name':'linear'}
        ]
    )
    op.add_column(u'question', sa.Column('voting_type_id', sa.Integer(), nullable=False, server_default="1"))
    op.create_foreign_key('fk_quesion_voting_types', 'question', 'voting_types', ['voting_type_id'], ['id'])
    ### end Alembic commands ###
项目:vilfredo-core    作者:fairdemocracy    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    question_types = op.create_table('question_types',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=25), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    ### Populate with question types
    op.bulk_insert(question_types,
        [
            {'name':'standard'},
            {'name':'image'}
        ]
    )
    op.add_column(u'question', sa.Column('question_type_id', sa.Integer(), nullable=False, server_default="1"))
    op.create_foreign_key('fk_quesion_question_types', 'question', 'question_types', ['question_type_id'], ['id'])
    ### end Alembic commands ###
项目:research-eGrader    作者:openstax    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user_exercise_notes',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('exercise_id', sa.Integer(), nullable=True),
    sa.Column('text', sa.Text(), nullable=True),
    sa.ForeignKeyConstraint(['exercise_id'], ['exercises.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('user_grading_sessions',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('started_on', sa.DateTime(), nullable=True),
    sa.Column('ended_on', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column(u'response_grade', sa.Column('session_id', sa.Integer(), nullable=True))
    op.add_column(u'response_grade', sa.Column('submitted_on', sa.DateTime(), nullable=True))
    op.create_foreign_key('response_grade_session_id_fkey', 'response_grade', 'user_grading_sessions', ['session_id'], ['id'])
    ### end Alembic commands ###
项目:radar    作者:renalreg    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('patient_demographics', sa.Column('ethnicity_id', sa.Integer(), nullable=True))
    op.add_column('patient_demographics', sa.Column('nationality_id', sa.Integer(), nullable=True))
    op.execute('update patient_demographics set ethnicity_id = (select id from ethnicities where code = ethnicity)')
    op.create_foreign_key(
        'patient_demographics_ethnicity_id_fkey',
        'patient_demographics',
        'ethnicities',
        ['ethnicity_id'],
        ['id']
    )
    op.create_foreign_key(
        'patient_demographics_nationality_id_fkey',
        'patient_demographics',
        'nationalities',
        ['nationality_id'],
        ['id']
    )
    op.drop_column('patient_demographics', 'ethnicity')
    # ### end Alembic commands ###
项目:idealoom    作者:conversence    | 项目源码 | 文件源码
def upgrade(pyramid_env):
    with context.begin_transaction():
        op.execute("""INSERT INTO idea_content_positive_link (id)
            SELECT id FROM idea_content_widget_link""")
    with context.begin_transaction():
        try:
            op.drop_constraint(
                "idea_content_widget_link_idea_content_link_id_id",
                "idea_content_widget_link")
        except:
            pass
    with context.begin_transaction():
        op.create_foreign_key(
            "idea_content_widget_link_idea_content_positive_link_id_id",
            "idea_content_widget_link", "idea_content_positive_link",
            ["id"], ["id"])
项目: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_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_facebook_connector', sa.Column('connector_id', sa.INTEGER(), autoincrement=False, nullable=False))
    op.drop_constraint(None, 'bit_facebook_connector', type_='foreignkey')
    op.create_foreign_key(u'bit_facebook_connector_connector_id_fkey', 'bit_facebook_connector', 'bit_connectors', ['connector_id'], ['id'])
    op.drop_column('bit_facebook_connector', 'id')
    op.drop_constraint(None, 'bit_facebook_ad_account', type_='foreignkey')
    op.create_foreign_key(u'bit_facebook_ad_account_connector_id_fkey', 'bit_facebook_ad_account', 'bit_facebook_connector', ['connector_id'], ['connector_id'])
    op.drop_constraint(None, 'bit_adwords_google_drive_storage', type_='foreignkey')
    op.create_foreign_key(u'bit_adwords_google_drive_storage_connector_id_fkey', 'bit_adwords_google_drive_storage', 'bit_adwords_connector', ['connector_id'], ['connector_id'])
    op.add_column('bit_adwords_connector', sa.Column('connector_id', sa.INTEGER(), autoincrement=False, nullable=False))
    op.drop_constraint(None, 'bit_adwords_connector', type_='foreignkey')
    op.create_foreign_key(u'bit_adwords_connector_connector_id_fkey', 'bit_adwords_connector', 'bit_connectors', ['connector_id'], ['id'])
    op.drop_column('bit_adwords_connector', 'id')
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_facebook_ad_campaigns', sa.Column('account_id', sa.INTEGER(), autoincrement=False, nullable=True))
    op.create_foreign_key(u'bit_facebook_ad_campaigns_account_id_fkey', 'bit_facebook_ad_campaigns', 'bit_facebook_ad_account', ['account_id'], ['id'])
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bit_adwords_google_drive_storage', sa.Column('connector_id', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'bit_adwords_google_drive_storage', 'bit_adwords_connector', ['connector_id'], ['connector_id'])
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('bit_facebook_ad',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('ad_set_id', sa.Integer(), nullable=True),
    sa.Column('native_id', sa.String(length=255), nullable=True),
    sa.Column('account_id', sa.String(length=255), nullable=True),
    sa.Column('campaign_id', sa.String(length=255), nullable=True),
    sa.Column('adset_id', sa.String(length=255), nullable=True),
    sa.Column('name', sa.String(length=255), nullable=True),
    sa.Column('bid_amount', sa.Integer(), nullable=True),
    sa.Column('bid_info', sa.String(length=255), nullable=True),
    sa.Column('bid_type', sa.String(length=255), nullable=True),
    sa.Column('configured_status', sa.String(length=255), nullable=True),
    sa.Column('effective_status', sa.String(length=255), nullable=True),
    sa.Column('status', sa.String(length=255), nullable=True),
    sa.Column('created_time', sa.DateTime(), nullable=True),
    sa.Column('updated_time', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['ad_set_id'], ['bit_facebook_ad_sets.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_bit_facebook_ad_native_id'), 'bit_facebook_ad', ['native_id'], unique=True)
    op.add_column(u'bit_facebook_ad_campaigns', sa.Column('ad_account_id', sa.Integer(), nullable=True))
    op.drop_index('ix_bit_facebook_ad_campaigns_account_id', table_name='bit_facebook_ad_campaigns')
    op.create_foreign_key(None, 'bit_facebook_ad_campaigns', 'bit_facebook_ad_account', ['ad_account_id'], ['id'])
    op.add_column(u'bit_facebook_ad_sets', sa.Column('ad_campaign_id', sa.Integer(), nullable=True))
    op.drop_index('ix_bit_facebook_ad_sets_account_id', table_name='bit_facebook_ad_sets')
    op.drop_index('ix_bit_facebook_ad_sets_campaign_id', table_name='bit_facebook_ad_sets')
    op.create_foreign_key(None, 'bit_facebook_ad_sets', 'bit_facebook_ad_campaigns', ['ad_campaign_id'], ['id'])
    # ### end Alembic commands ###
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_foreign_key(None, 'bit_chiter_connector', 'bit_connectors', ['id'], ['id'])
    # ### end Alembic commands ###
项目:occrp-timeline-tool    作者:datamade    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('location',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('location', sa.String(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('location')
    )
    op.add_column('event', sa.Column('location_id', sa.Integer(), nullable=True))
    op.drop_constraint('event_title_key', 'event', type_='unique')
    op.create_foreign_key(None, 'event', 'location', ['location_id'], ['id'])
    op.drop_column('event', 'title')
    # ### end Alembic commands ###
项目:podigger    作者:perna    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('podcast_language',
    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('name', sa.String(length=60), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_podcast_language_id'), 'podcast_language', ['id'], unique=False)
    op.add_column('podcast', sa.Column('language_id', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'podcast', 'podcast_language', ['language_id'], ['id'])
    op.drop_column('podcast', 'language')
    ### end Alembic commands ###
项目:podigger    作者:perna    | 项目源码 | 文件源码
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('topic_suggestion', sa.Column('podcast_id', sa.INTEGER(), autoincrement=False, nullable=True))
    op.create_foreign_key('topic_suggestion_podcast_id_fkey', 'topic_suggestion', 'podcast', ['podcast_id'], ['id'])
    ### end Alembic commands ###
项目:kuberdock-platform    作者:cloudlinux    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('persistent_disk', sa.Column('node_id', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'persistent_disk', 'nodes', ['node_id'], ['id'])
    ### end Alembic commands ###
项目:kuberdock-platform    作者:cloudlinux    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('ippool', sa.Column('node_id', sa.Integer(), nullable=True))
    op.create_foreign_key(u'ippool_node_id_fkey', 'ippool', 'nodes', ['node_id'], ['id'])
    ### end Alembic commands ###
项目:kuberdock-platform    作者:cloudlinux    | 项目源码 | 文件源码
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('pages',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('ts', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.Column('created_by_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('modified', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.Column('modified_by_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('slug', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
    sa.Column('title', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
    sa.Column('content', sa.TEXT(), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['created_by_id'], [u'users.id'], name=u'pages_created_by_id_fkey'),
    sa.ForeignKeyConstraint(['modified_by_id'], [u'users.id'], name=u'pages_modified_by_id_fkey'),
    sa.PrimaryKeyConstraint('id', name=u'pages_pkey')
    )
    op.add_column('menus_items', sa.Column('is_public', sa.BOOLEAN(), autoincrement=False, nullable=True))
    op.add_column('menus_items', sa.Column('roles', sa.VARCHAR(length=255), autoincrement=False, nullable=True))
    op.add_column('menus_items', sa.Column('ts', postgresql.TIMESTAMP(), autoincrement=False, nullable=True))
    op.add_column('menus_items', sa.Column('page_id', sa.INTEGER(), autoincrement=False, nullable=True))
    op.add_column('menus_items', sa.Column('is_group_label', sa.BOOLEAN(), autoincrement=False, nullable=True))
    op.add_column('menus_items', sa.Column('created_by_id', sa.INTEGER(), autoincrement=False, nullable=True))
    op.create_foreign_key(u'menus_items_page_id_fkey', 'menus_items', 'pages', ['page_id'], ['id'])
    op.create_foreign_key(u'menus_items_created_by_id_fkey', 'menus_items', 'users', ['created_by_id'], ['id'])
    op.add_column('menus', sa.Column('ts', postgresql.TIMESTAMP(), autoincrement=False, nullable=True))
    op.add_column('menus', sa.Column('created_by_id', sa.INTEGER(), autoincrement=False, nullable=True))
    op.create_foreign_key(u'menus_created_by_id_fkey', 'menus', 'users', ['created_by_id'], ['id'])
    op.drop_table('menuitem_roles')
    ### end Alembic commands ###
项目:CodeGra.de    作者:CodeGra-de    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('Comment_File_id_fkey', 'Comment', type_='foreignkey')
    op.drop_constraint('Comment_User_id_fkey', 'Comment', type_='foreignkey')
    op.create_foreign_key('Comment_User_id_fkey', 'Comment', 'User', ['User_id'], ['id'], ondelete='CASCADE')
    op.create_foreign_key('Comment_File_id_fkey', 'Comment', 'File', ['File_id'], ['id'], ondelete='CASCADE')

    op.drop_index('ix_LinterComment_File_id', table_name='LinterComment')
    op.drop_constraint('LinterComment_File_id_fkey', 'LinterComment', type_='foreignkey')
    op.create_index(op.f('ix_LinterComment_File_id'), 'LinterComment', ['File_id'], unique=False)
    op.create_foreign_key('LinterComment_File_id_fkey', 'LinterComment', 'File', ['File_id'], ['id'], ondelete='CASCADE')

    op.drop_constraint('LinterInstance_Work_id_fkey', 'LinterInstance', type_='foreignkey')
    op.create_foreign_key('LinterInstance_Work_id_fkey', 'LinterInstance', 'Work', ['Work_id'], ['id'], ondelete='CASCADE')
    # ### end Alembic commands ###
项目:CodeGra.de    作者:CodeGra-de    | 项目源码 | 文件源码
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_LinterComment_File_id'), table_name='LinterComment')
    op.drop_constraint('LinterComment_File_id_fkey', 'LinterComment', type_='foreignkey')
    op.create_foreign_key('LinterComment_File_id_fkey', 'LinterComment', 'File', ['File_id'], ['id'])
    op.create_index('ix_LinterComment_File_id', 'LinterComment', ['File_id'], unique=False)

    op.drop_constraint('Comment_File_id_fkey', 'Comment', type_='foreignkey')
    op.drop_constraint('Comment_User_id_fkey', 'Comment', type_='foreignkey')
    op.create_foreign_key('Comment_User_id_fkey', 'Comment', 'User', ['User_id'], ['id'])
    op.create_foreign_key('Comment_File_id_fkey', 'Comment', 'File', ['File_id'], ['id'])

    op.drop_constraint('LinterInstance_Work_id_fkey', 'LinterInstance', type_='foreignkey')
    op.create_foreign_key('LinterInstance_Work_id_fkey', 'LinterInstance', 'Work', ['Work_id'], ['id'])
    # ### end Alembic commands ###
项目:CodeGra.de    作者:CodeGra-de    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('File_Work_id_fkey', 'File', type_='foreignkey')
    op.create_foreign_key('File_Work_id_fkey', 'File', 'Work', ['Work_id'], ['id'], ondelete='CASCADE')
    # ### end Alembic commands ###
项目:CodeGra.de    作者:CodeGra-de    | 项目源码 | 文件源码
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('File_Work_id_fkey', 'File', type_='foreignkey')
    op.create_foreign_key('File_Work_id_fkey', 'File', 'Work', ['Work_id'], ['id'])
    # ### end Alembic commands ###
项目:CodeGra.de    作者:CodeGra-de    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('GradeHistory_Work_id_fkey', 'GradeHistory', type_='foreignkey')
    op.create_foreign_key('GradeHistory_Work_id_fkey', 'GradeHistory', 'Work', ['Work_id'], ['id'], ondelete='CASCADE')
    # ### end Alembic commands ###
项目:conditional    作者:ComputerScienceHouse    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('conditional', sa.Column('evaluation', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'conditional', 'spring_evals', ['evaluation'], ['id'])
    ### end Alembic commands ###
项目:conditional    作者:ComputerScienceHouse    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('conditional', sa.Column('i_evaluation', sa.Integer(), nullable=True))
    op.add_column('conditional', sa.Column('s_evaluation', sa.Integer(), nullable=True))
    op.drop_constraint('conditional_evaluation_fkey', 'conditional', type_='foreignkey')
    op.create_foreign_key(None, 'conditional', 'spring_evals', ['s_evaluation'], ['id'])
    op.create_foreign_key(None, 'conditional', 'freshman_eval_data', ['i_evaluation'], ['id'])
    op.drop_column('conditional', 'evaluation')
    ### end Alembic commands ###
项目:conditional    作者:ComputerScienceHouse    | 项目源码 | 文件源码
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('conditional', sa.Column('evaluation', sa.INTEGER(), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'conditional', type_='foreignkey')
    op.drop_constraint(None, 'conditional', type_='foreignkey')
    op.create_foreign_key('conditional_evaluation_fkey', 'conditional', 'spring_evals', ['evaluation'], ['id'])
    op.drop_column('conditional', 's_evaluation')
    op.drop_column('conditional', 'i_evaluation')
    ### end Alembic commands ###
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('category',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.add_column(u'posts', sa.Column('category_id', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'posts', 'category', ['category_id'], ['id'])
    ### end Alembic commands ###
项目:seedbox    作者:nailgun    | 项目源码 | 文件源码
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('cluster', sa.Column('service_account_keypair_id', sa.INTEGER(), autoincrement=False, nullable=False))
    op.create_foreign_key('cluster_service_account_keypair_id_fkey', 'cluster', 'credentials_data', ['service_account_keypair_id'], ['id'])
    op.drop_column('cluster', 'k8s_service_account_public_key')
    op.drop_column('cluster', 'k8s_service_account_private_key')
    # ### end Alembic commands ###
项目:quark    作者:openstack    | 项目源码 | 文件源码
def _create_foreign_key(op, table, fk):
    ref_tbl_name = fk.column.table.name
    ref_tbl_col = fk.column.name
    op.create_foreign_key(fk.name, table.name, ref_tbl_name,
                          [fk.parent.name], [ref_tbl_col])
项目:quark    作者:openstack    | 项目源码 | 文件源码
def upgrade():
    op.add_column('quark_mac_addresses',
                  sa.Column('transaction_id', sa.Integer(), nullable=True))
    op.create_foreign_key(
        'fk_quark_macs_transaction_id',
        'quark_mac_addresses', 'quark_transactions',
        ['transaction_id'], ['id'])
项目:quark    作者:openstack    | 项目源码 | 文件源码
def upgrade():
    op.create_table('quark_transactions',
                    sa.Column('created_at', sa.DateTime(), nullable=True),
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_engine='InnoDB')
    op.add_column(u'quark_ip_addresses',
                  sa.Column('transaction_id', sa.Integer(), nullable=True))
    op.create_foreign_key('fk_quark_ips_transaction_id',
                          'quark_ip_addresses',
                          'quark_transactions',
                          ['transaction_id'],
                          ['id'])
项目:biweeklybudget    作者:jantman    | 项目源码 | 文件源码
def downgrade():
    # When making changes to a column that has a foreign key, we need to drop
    # and then re-add the constraint
    op.execute('LOCK TABLES txn_reconciles WRITE, transactions WRITE;')
    op.drop_constraint('fk_txn_reconciles_txn_id_transactions',
                       'txn_reconciles', type_='foreignkey')
    op.alter_column(
        'txn_reconciles',
        'txn_id',
        existing_type=mysql.INTEGER(display_width=11),
        nullable=True
    )
    op.create_foreign_key('fk_txn_reconciles_txn_id_transactions',
                          'txn_reconciles', 'transactions', ['txn_id'], ['id'])
    op.execute('UNLOCK TABLES;')
项目:fabric8-analytics-server    作者:fabric8-analytics    | 项目源码 | 文件源码
def upgrade():
    """Upgrade the database to a newer revision."""
    # commands auto generated by Alembic - please adjust! ###
    op.create_table('stacks',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('is_ref_stack', sa.Boolean(), nullable=False),
                    sa.Column('stack_json', postgresql.JSONB(), nullable=False),
                    sa.PrimaryKeyConstraint('id'))
    op.add_column('similar_stacks', sa.Column('analysis', postgresql.JSONB()))
    op.add_column('similar_stacks', sa.Column('similar_stack_id', sa.Integer(), nullable=False))
    op.add_column('similar_stacks', sa.Column('similarity_value', sa.Float(), nullable=False))
    op.add_column('similar_stacks', sa.Column('stack_id', sa.Integer(), nullable=False))
    op.create_unique_constraint('sim_unique', 'similar_stacks', ['stack_id', 'similar_stack_id'])
    op.drop_constraint('similar_stacks_appstack_id_fkey', 'similar_stacks', type_='foreignkey')
    op.create_foreign_key(None, 'similar_stacks', 'stacks', ['stack_id'], ['id'])
    op.create_foreign_key(None, 'similar_stacks', 'stacks', ['similar_stack_id'], ['id'])
    op.drop_column('similar_stacks', 'dependency_list')
    op.drop_column('similar_stacks', 'appstack_id')
    op.drop_table('reference_stacks')
    op.drop_table('app_stacks')
    # end Alembic commands ###