Python sqlalchemy 模块,JSON 实例源码
我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用sqlalchemy.JSON。
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('billing', sa.Column('cost_by_analysis', sa.JSON(), nullable=True))
op.alter_column('billing', 'compute_cost',
existing_type=sa.NUMERIC(),
nullable=False)
op.alter_column('billing', 'storage_cost',
nullable=False)
### end Alembic commands ###
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('publisher',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('name', sa.TEXT(),
sa.Column('title', sa.Text(),
sa.Column('private', sa.BOOLEAN(),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_publisher_name'), 'publisher', ['name'], unique=True)
op.create_table('user',
sa.Column('email',
sa.Column('secret',
sa.Column('full_name',
sa.Column('auth0_id',
sa.Column('sysadmin',
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_user_auth0_id'), 'user', ['auth0_id'], unique=False)
op.create_index(op.f('ix_user_email'), ['email'], unique=False)
op.create_index(op.f('ix_user_name'), unique=True)
op.create_table('package',
sa.Column('descriptor',
sa.Column('status',
sa.Column('readme',
sa.Column('publisher_id',
sa.ForeignKeyConstraint(['publisher_id'], [u'publisher.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name', 'publisher_id')
)
op.create_index(op.f('ix_package_name'), 'package', unique=False)
op.create_index(op.f('ix_package_status'), ['status'], unique=False)
op.create_table('publisher_user',
sa.Column('user_id',
sa.Column('role',
sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
sa.PrimaryKeyConstraint('id', 'user_id', 'publisher_id')
)
### end Alembic commands ###