python类create_foreign_key()的实例源码

95b81f5e2452_.py 文件源码 项目:podigger 作者: perna 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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 ###
8ce18fd9945a_.py 文件源码 项目:podigger 作者: perna 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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 ###
4ded025d2f29_add_node_id_to_persistent_disk.py 文件源码 项目:kuberdock-platform 作者: cloudlinux 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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 ###
30ad174aa45a_add_relation_between_node_and_ippool.py 文件源码 项目:kuberdock-platform 作者: cloudlinux 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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 ###
241a7b04a9ff_add_menurole_rm_pages.py 文件源码 项目:kuberdock-platform 作者: cloudlinux 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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 ###
0cfce1799c57_.py 文件源码 项目:CodeGra.de 作者: CodeGra-de 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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 ###
0cfce1799c57_.py 文件源码 项目:CodeGra.de 作者: CodeGra-de 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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 ###
4d3531723478_.py 文件源码 项目:CodeGra.de 作者: CodeGra-de 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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 ###
4d3531723478_.py 文件源码 项目:CodeGra.de 作者: CodeGra-de 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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 ###
3b8c7d61ece8_.py 文件源码 项目:CodeGra.de 作者: CodeGra-de 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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 ###
6f6b843e2b8f_.py 文件源码 项目:conditional 作者: ComputerScienceHouse 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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 ###
5615d58892a1_.py 文件源码 项目:conditional 作者: ComputerScienceHouse 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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 ###
5615d58892a1_.py 文件源码 项目:conditional 作者: ComputerScienceHouse 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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 ###
1b0f4aa57e92_add_table_category.py 文件源码 项目:chihu 作者: yelongyu 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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 ###
469154bafe22_.py 文件源码 项目:seedbox 作者: nailgun 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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 ###
3b467be51e43_composite_primary_key_port_ip_.py 文件源码 项目:quark 作者: openstack 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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])
356d6c0623c8_add_transaction_id_to_quark_mac_.py 文件源码 项目:quark 作者: openstack 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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'])
5632aa202d89_added_transactions_table.py 文件源码 项目:quark 作者: openstack 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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'])
5446559aecf7_txnreconcile_txn_id_not_null.py 文件源码 项目:biweeklybudget 作者: jantman 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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;')
fc7ea2a7e386_analytics_tables.py 文件源码 项目:fabric8-analytics-server 作者: fabric8-analytics 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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 ###


问题


面经


文章

微信
公众号

扫码关注公众号