我们从Python开源项目中,提取了以下46个代码示例,用于说明如何使用sqlalchemy.dialects.postgresql.ENUM。
def upgrade(): """Upgrade the database to a newer revision.""" # commands auto generated by Alembic - please adjust! ### op.create_table('component_gh_usage', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=255), nullable=False), sa.Column('version', sa.String(length=255), nullable=False), sa.Column('count', sa.Integer(), nullable=False), sa.Column('ecosystem_backend', postgresql.ENUM('none', 'npm', 'maven', 'pypi', 'rubygems', 'scm', 'crates', name='ecosystem_backend_enum', create_type=False), nullable=True), sa.Column('timestamp', sa.DateTime(), server_default=sa.text('LOCALTIMESTAMP'), nullable=False), sa.PrimaryKeyConstraint('id')) # end Alembic commands ###
def upgrade(): """Upgrade the database to a newer revision.""" # ### commands auto generated by Alembic - please adjust! ### op.create_table('component_gh_usage', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=255), nullable=False), sa.Column('version', sa.String(length=255), nullable=False), sa.Column('count', sa.Integer(), nullable=False), sa.Column('ecosystem_backend', postgresql.ENUM('none', 'npm', 'maven', 'pypi', 'rubygems', 'scm', 'crates', name='ecosystem_backend_enum', create_type=False), nullable=True), sa.Column('timestamp', sa.DateTime(), server_default=sa.text('LOCALTIMESTAMP'), nullable=False), sa.PrimaryKeyConstraint('id')) # ### end Alembic commands ###
def create(op, name, *values): enum = ENUM(*values, name=name, create_type=False) enum.create(op.get_bind(), checkfirst=True) return enum
def existing(name): return ENUM(name=name, create_type=False)
def upgrade(): ### commands auto generated by Alembic - please adjust! ### semester = postgresql.ENUM('Fall', 'Spring', 'Neither', name='co_op_enum') semester.create(op.get_bind()) op.add_column('current_coops', sa.Column('semester', sa.Enum('Fall', 'Spring', 'Neither', name='co_op_enum'), server_default='Neither', nullable=False)) op.drop_column('current_coops', 'active') ### end Alembic commands ###
def upgrade(): classification_type_enum = postgresql.ENUM('binary', 'multi-label', 'multi-class', name='classification_type_enum') classification_type_enum.create(op.get_bind()) # ### commands auto generated by Alembic - please adjust! ### op.add_column('problem', sa.Column('classification_type', sa.Enum('binary', 'multi-label', 'multi-class', name='classification_type_enum'), server_default='binary', nullable=True)) op.execute(''' UPDATE "problem" SET classification_type = 'multi-class' WHERE (SELECT COUNT(*) FROM "problem_label" WHERE problem_id = problem.id) >= 2 ''') # ### end Alembic commands ###
def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_column('problem', 'classification_type') classification_type_enum = postgresql.ENUM('binary', 'multi-label', 'multi-class', name='classification_type_enum') classification_type_enum.drop(op.get_bind()) # ### end Alembic commands ###
def downgrade(): ### commands auto generated by Alembic - please adjust! ### op.add_column('rule', sa.Column('config', postgresql.JSONB(), autoincrement=False, nullable=True)) op.add_column('rule', sa.Column('type', sa.VARCHAR(), autoincrement=False, nullable=False)) op.add_column('rule', sa.Column('action', postgresql.ENUM(u'added', u'removed', u'both', name='rule_actions'), autoincrement=False, nullable=False)) op.drop_column('rule', 'description') op.drop_column('rule', 'conditions') ### end Alembic commands ###
def downgrade(): ### commands auto generated by Alembic - please adjust! ### op.drop_table('rule') ### end Alembic commands ### postgresql.ENUM(name='rule_actions').drop(op.get_bind(), checkfirst=False)
def downgrade(): """Downgrade the database to an older revision.""" # ### commands auto generated by Alembic - please adjust! ### conn = op.get_bind() conn.execute("DELETE FROM ecosystems WHERE name = 'nuget'") # There's no 'ALTER TYPE enum REMOVE VALUE' op.alter_column('package_gh_usage', 'ecosystem_backend', existing_type=postgresql.ENUM('none', 'npm', 'maven', 'pypi', 'rubygems', 'scm', 'crates', 'nuget', name='ecosystem_backend_enum'), type_=postgresql.ENUM('none', 'npm', 'maven', 'pypi', 'rubygems', 'scm', 'crates', name='ecosystem_backend_enum'), existing_nullable=True) op.alter_column('ecosystems', '_backend', existing_type=sa.Enum('none', 'npm', 'maven', 'pypi', 'rubygems', 'scm', 'crates', 'nuget', name='ecosystem_backend_enum'), type_=sa.Enum('none', 'npm', 'maven', 'pypi', 'rubygems', 'scm', 'crates', name='ecosystem_backend_enum'), existing_nullable=True) op.alter_column('component_gh_usage', 'ecosystem_backend', existing_type=postgresql.ENUM('none', 'npm', 'maven', 'pypi', 'rubygems', 'scm', 'crates', 'nuget', name='ecosystem_backend_enum'), type_=postgresql.ENUM('none', 'npm', 'maven', 'pypi', 'rubygems', 'scm', 'crates', name='ecosystem_backend_enum'), existing_nullable=True) # ### end Alembic commands ###
def upgrade(): # ### commands auto generated by Alembic - please adjust! ### consent_type_type = postgresql.ENUM('FORM', 'INFORMATION_SHEET', name='consent_type_type') consent_type_type.create(op.get_bind()) op.add_column('consents', sa.Column('consent_type', sa.Enum('FORM', 'INFORMATION_SHEET', name="consent_type_type"), nullable=True)) consent_type = sa.table('consents', sa.column('consent_type')) op.execute(consent_type.update().values(consent_type='FORM')) op.alter_column('consents', 'consent_type', nullable=False) op.add_column('consents', sa.Column('weight', sa.Integer(), nullable=True)) # ### end Alembic commands ###
def enum_column(enum_cls, name, metadata): class EnumColumn(_BaseEnumColumn): pass EnumColumn.enum_cls = enum_cls # Just as tables do, enum columns require metadata to bind to. EnumColumn.impl = ENUM(*(e.value for e in enum_cls), name=name, metadata=metadata) EnumColumn.reverse_enum_values = {e.value: e for e in enum_cls} EnumColumn.__name__ = str('EnumColumn_' + name) return EnumColumn()
def _prep_testing_database(options, file_config): from sqlalchemy.testing import config, util from sqlalchemy.testing.exclusions import against from sqlalchemy import schema, inspect if options.dropfirst: for cfg in config.Config.all_configs(): e = cfg.db inspector = inspect(e) try: view_names = inspector.get_view_names() except NotImplementedError: pass else: for vname in view_names: e.execute(schema._DropView( schema.Table(vname, schema.MetaData()) )) if config.requirements.schemas.enabled_for_config(cfg): try: view_names = inspector.get_view_names( schema="test_schema") except NotImplementedError: pass else: for vname in view_names: e.execute(schema._DropView( schema.Table(vname, schema.MetaData(), schema="test_schema") )) util.drop_all_tables(e, inspector) if config.requirements.schemas.enabled_for_config(cfg): util.drop_all_tables(e, inspector, schema=cfg.test_schema) if against(cfg, "postgresql"): from sqlalchemy.dialects import postgresql for enum in inspector.get_enums("*"): e.execute(postgresql.DropEnumType( postgresql.ENUM( name=enum['name'], schema=enum['schema'])))
def _prep_testing_database(options, file_config): from alembic.testing import config from alembic.testing.exclusions import against from sqlalchemy import schema from alembic import util if util.sqla_08: from sqlalchemy import inspect else: from sqlalchemy.engine.reflection import Inspector inspect = Inspector.from_engine if options.dropfirst: for cfg in config.Config.all_configs(): e = cfg.db inspector = inspect(e) try: view_names = inspector.get_view_names() except NotImplementedError: pass else: for vname in view_names: e.execute(schema._DropView( schema.Table(vname, schema.MetaData()) )) if config.requirements.schemas.enabled_for_config(cfg): try: view_names = inspector.get_view_names( schema="test_schema") except NotImplementedError: pass else: for vname in view_names: e.execute(schema._DropView( schema.Table(vname, schema.MetaData(), schema="test_schema") )) for tname in reversed(inspector.get_table_names( order_by="foreign_key")): e.execute(schema.DropTable( schema.Table(tname, schema.MetaData()) )) if config.requirements.schemas.enabled_for_config(cfg): for tname in reversed(inspector.get_table_names( order_by="foreign_key", schema="test_schema")): e.execute(schema.DropTable( schema.Table(tname, schema.MetaData(), schema="test_schema") )) if against(cfg, "postgresql") and util.sqla_100: from sqlalchemy.dialects import postgresql for enum in inspector.get_enums("*"): e.execute(postgresql.DropEnumType( postgresql.ENUM( name=enum['name'], schema=enum['schema'])))
def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('credential', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('type', postgresql.ENUM('username', 'admin', name='credential_types'), nullable=False), sa.Column('key', sa.String(length=255), nullable=False), sa.Column('value', sa.String(length=255), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text(u'now()'), nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('key') ) op.create_table('photo', sa.Column('id', sa.String(length=36), nullable=False), sa.Column('user_id', sa.Integer(), nullable=True), sa.Column('original_width', sa.Integer(), nullable=True), sa.Column('original_height', sa.Integer(), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('post', sa.Column('id', sa.Integer(), nullable=False), sa.Column('photo_id', sa.String(length=36), nullable=True), sa.Column('message', sa.Text(), nullable=True), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text(u'now()'), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_table('user', sa.Column('id', sa.Integer(), nullable=False), sa.Column('username', sa.String(length=80), nullable=False), sa.Column('photo_id', sa.String(length=36), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text(u'now()'), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_foreign_key( 'credential_user_id_fkey', 'credential', 'user', ['user_id'], ['id'], ) op.create_foreign_key( 'photo_user_id_fkey', 'photo', 'user', ['user_id'], ['id'], ) op.create_foreign_key( 'post_photo_id_fkey', 'post', 'photo', ['photo_id'], ['id'], ) op.create_foreign_key( 'post_user_id_fkey', 'post', 'user', ['user_id'], ['id'], ) op.create_foreign_key( 'user_photo_id_fkey', 'user', 'photo', ['photo_id'], ['id'], ) # ### end Alembic commands ###