当前位置: 首页>>代码示例>>Python>>正文


Python postgresql.ENUM属性代码示例

本文整理汇总了Python中sqlalchemy.dialects.postgresql.ENUM属性的典型用法代码示例。如果您正苦于以下问题:Python postgresql.ENUM属性的具体用法?Python postgresql.ENUM怎么用?Python postgresql.ENUM使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在sqlalchemy.dialects.postgresql的用法示例。


在下文中一共展示了postgresql.ENUM属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upgrade

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def upgrade():
    blockchain_status = postgresql.ENUM('PENDING', 'SUCCESS', 'FAILED', name='blockchainstatus')
    blockchain_status.create(op.get_bind())

    op.create_table('worker_messages',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('authorising_user_id', sa.Integer(), nullable=True),
    sa.Column('created', sa.DateTime(), nullable=True),
    sa.Column('updated', sa.DateTime(), nullable=True),
    sa.Column('message', sa.String(), nullable=True),
    sa.Column('error', sa.String(), nullable=True),
    sa.Column('worker_timestamp', sa.DateTime(), nullable=True),
    sa.Column('blockchain_task_uuid', sa.String(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('credit_transfer', sa.Column('blockchain_hash', sa.String(), nullable=True))
    op.add_column('credit_transfer', sa.Column('blockchain_status', sa.Enum('PENDING', 'SUCCESS', 'FAILED', name='blockchainstatus'), nullable=True))
    op.add_column('credit_transfer', sa.Column('last_worker_update', sa.DateTime(), nullable=True))
    op.add_column('exchange', sa.Column('blockchain_hash', sa.String(), nullable=True))
    op.add_column('exchange', sa.Column('blockchain_status', sa.Enum('PENDING', 'SUCCESS', 'FAILED', name='blockchainstatus'), nullable=True))
    op.add_column('exchange', sa.Column('last_worker_update', sa.DateTime(), nullable=True))
    op.create_index(op.f('ix_worker_messages_table_blockchain_task_uuid'), 'worker_messages', ['blockchain_task_uuid'], unique=False) 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:24,代码来源:d7b89a614ae9_.py

示例2: _inline_enum_script

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def _inline_enum_script(self):
        write_script(
            self.script,
            self.rid,
            """
revision = '%s'
down_revision = None

from alembic import op
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import Column


def upgrade():
    op.create_table("sometable",
        Column("data", ENUM("one", "two", "three", name="pgenum"))
    )


def downgrade():
    op.drop_table("sometable")
"""
            % self.rid,
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:26,代码来源:test_postgresql.py

示例3: upgrade

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def upgrade():

    op.create_table('monthly_billing',
                    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
                    sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
                    sa.Column('month', sa.String(), nullable=False),
                    sa.Column('year', sa.Float(), nullable=False),
                    sa.Column('notification_type',
                              postgresql.ENUM('email', 'sms', 'letter', name='notification_type', create_type=False),
                              nullable=False),
                    sa.Column('monthly_totals', postgresql.JSON(), nullable=False),
                    sa.Column('updated_at', sa.DateTime, nullable=False),
                    sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_monthly_billing_service_id'), 'monthly_billing', ['service_id'], unique=False)
    op.create_index(op.f('uix_monthly_billing'), 'monthly_billing', ['service_id', 'month', 'year', 'notification_type'], unique=True) 
开发者ID:alphagov,项目名称:notifications-api,代码行数:19,代码来源:0110_monthly_billing.py

示例4: upgrade

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def upgrade():
    notification_types = postgresql.ENUM('email', 'sms', 'letter', name='notification_type', create_type=False)
    op.create_table('rates',
    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('valid_from', sa.DateTime(), nullable=False),
    sa.Column('rate', sa.Numeric(), nullable=False),
    sa.Column('notification_type', notification_types, nullable=False),
    sa.PrimaryKeyConstraint('id')
    )

    op.create_index(op.f('ix_rates_notification_type'), 'rates', ['notification_type'], unique=False)

    op.get_bind()
    op.execute("INSERT INTO rates(id, valid_from, rate, notification_type) "
               "VALUES('{}', '2016-05-18 00:00:00', 1.65, 'sms')".format(uuid.uuid4()))
    op.execute("INSERT INTO rates(id, valid_from, rate, notification_type) "
               "VALUES('{}', '2017-04-01 00:00:00', 1.58, 'sms')".format(uuid.uuid4())) 
开发者ID:alphagov,项目名称:notifications-api,代码行数:19,代码来源:0075_create_rates_table.py

示例5: upgrade

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def upgrade():
    op.create_table(
        'service_contact_list',
        sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('original_file_name', sa.String(), nullable=False),
        sa.Column('row_count', sa.Integer(), nullable=False),
        sa.Column('template_type', postgresql.ENUM(name='template_type', create_type=False), nullable=False),
        sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True),
        sa.Column('created_at', sa.DateTime(), nullable=False),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(['created_by_id'], ['users.id'], ),
        sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_service_contact_list_created_by_id'), 'service_contact_list', ['created_by_id'], unique=False)
    op.create_index(op.f('ix_service_contact_list_service_id'), 'service_contact_list', ['service_id'], unique=False)
    op.add_column('jobs', sa.Column('contact_list_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.create_foreign_key('jobs_contact_list_id_fkey', 'jobs', 'service_contact_list', ['contact_list_id'], ['id']) 
开发者ID:alphagov,项目名称:notifications-api,代码行数:21,代码来源:0318_service_contact_list.py

示例6: downgrade

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('monthly_billing',
    sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
    sa.Column('service_id', postgresql.UUID(), autoincrement=False, nullable=False),
    sa.Column('notification_type', postgresql.ENUM('email', 'sms', 'letter', name='notification_type'), autoincrement=False, nullable=False),
    sa.Column('monthly_totals', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.Column('start_date', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.Column('end_date', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['service_id'], ['services.id'], name='monthly_billing_service_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='monthly_billing_pkey'),
    sa.UniqueConstraint('service_id', 'start_date', 'notification_type', name='uix_monthly_billing')
    )
    op.create_index('ix_monthly_billing_service_id', 'monthly_billing', ['service_id'], unique=False)
    # ### end Alembic commands ### 
开发者ID:alphagov,项目名称:notifications-api,代码行数:18,代码来源:0210_remove_monthly_billing.py

示例7: upgrade

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def upgrade():
    op.alter_column(
        'notification_history',
        'status',
        existing_type=postgresql.ENUM(
            'created', 'sending', 'delivered', 'pending', 'failed', 'technical-failure',
            'temporary-failure', 'permanent-failure', 'sent', name='notify_status_type'
        ),
        nullable=True
    )
    op.alter_column(
        'notifications',
        'status',
        existing_type=postgresql.ENUM(
            'created', 'sending', 'delivered', 'pending', 'failed', 'technical-failure',
            'temporary-failure', 'permanent-failure', 'sent', name='notify_status_type'
        ),
        nullable=True
    ) 
开发者ID:alphagov,项目名称:notifications-api,代码行数:21,代码来源:0106_null_noti_status.py

示例8: downgrade

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def downgrade():
    op.alter_column(
        'notifications',
        'status',
        existing_type=postgresql.ENUM(
            'created', 'sending', 'delivered', 'pending', 'failed', 'technical-failure',
            'temporary-failure', 'permanent-failure', 'sent', name='notify_status_type'
        ),
        nullable=False
    )
    op.alter_column(
        'notification_history',
        'status',
        existing_type=postgresql.ENUM(
            'created', 'sending', 'delivered', 'pending', 'failed', 'technical-failure',
            'temporary-failure', 'permanent-failure', 'sent', name='notify_status_type'
        ),
        nullable=False
    ) 
开发者ID:alphagov,项目名称:notifications-api,代码行数:21,代码来源:0106_null_noti_status.py

示例9: downgrade

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def downgrade():
    op.add_column(
        'notifications',
        sa.Column(
            'status',
            postgresql.ENUM(
                'created', 'sending', 'delivered', 'pending', 'failed', 'technical-failure',
                'temporary-failure', 'permanent-failure', 'sent', name='notify_status_type'
            ),
            autoincrement=False,
            nullable=True
        )
    )
    op.add_column(
        'notification_history',
        sa.Column(
            'status',
            postgresql.ENUM(
                'created', 'sending', 'delivered', 'pending', 'failed', 'technical-failure',
                'temporary-failure', 'permanent-failure', 'sent', name='notify_status_type'
            ),
            autoincrement=False,
            nullable=True
        )
    ) 
开发者ID:alphagov,项目名称:notifications-api,代码行数:27,代码来源:0109_rem_old_noti_status.py

示例10: upgrade

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def upgrade():
    # Change the name and the type of the column resource_availability
    # to visibility
    visibility_enum = postgresql.ENUM(*visibility_states,
                                      name='visibility_states')
    visibility_enum.create(op.get_bind())
    for table_name in resource_tables:
        op.alter_column(table_name,
                        'resource_availability',
                        new_column_name='visibility',
                        type_=visibility_enum,
                        postgresql_using='resource_availability::text::'
                                         'visibility_states')

    # Remove the enum resource_availability from postgres
    op.execute("DROP TYPE resource_availability;") 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager,代码行数:18,代码来源:3483e421713d_rename_availability_to_visibility.py

示例11: downgrade

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def downgrade():
    # Change the name and the type of the column visibility back
    # to resource_availability
    resource_availability = postgresql.ENUM(*visibility_states,
                                            name='resource_availability')
    resource_availability.create(op.get_bind())
    for table_name in resource_tables:
        op.alter_column(table_name,
                        'visibility',
                        new_column_name='resource_availability',
                        type_=resource_availability,
                        postgresql_using='visibility::text::'
                                         'resource_availability')

    # Remove the enum visibility_states from postgres
    op.execute("DROP TYPE visibility_states;") 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager,代码行数:18,代码来源:3483e421713d_rename_availability_to_visibility.py

示例12: fix_postgres_array_of_enum

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def fix_postgres_array_of_enum(connection, tbl):
    "Change type of ENUM[] columns to a custom type"

    for col in tbl.c:
        col_str = str(col.type)
        if col_str.endswith('[]'):  # this is an array
            enum_name = col_str[:-2]
            try:  # test if 'enum_name' is an enum
                enum_ranges = connection.execute('''
                        SELECT enum_range(NULL::%s);
                    ''' % enum_name).fetchone()
                enum_values = sql_enum_to_list(enum_ranges[0])
                enum = ENUM(*enum_values, name=enum_name)
                tbl.c[col.name].type = ArrayOfEnum(enum)
            except sa.exc.ProgrammingError as enum_excep:
                if 'does not exist' in str(enum_excep):
                    pass  # Must not have been an enum
                else:
                    raise 
开发者ID:18F,项目名称:rdbms-subsetter,代码行数:21,代码来源:postgres.py

示例13: test_generate_multiple_on_metadata

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def test_generate_multiple_on_metadata(self):
        metadata = self.metadata

        e1 = Enum("one", "two", "three", name="myenum", metadata=metadata)

        t1 = Table("e1", metadata, Column("c1", e1))

        t2 = Table("e2", metadata, Column("c1", e1))

        metadata.create_all(checkfirst=False)
        assert "myenum" in [e["name"] for e in inspect(testing.db).get_enums()]
        metadata.drop_all(checkfirst=False)
        assert "myenum" not in [
            e["name"] for e in inspect(testing.db).get_enums()
        ]

        e1.create()  # creates ENUM
        t1.create()  # does not create ENUM
        t2.create()  # does not create ENUM 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_types.py

示例14: test_array_plus_native_enum_create

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def test_array_plus_native_enum_create(self):
        m = MetaData()
        t = Table(
            "t",
            m,
            Column(
                "data_1",
                self.ARRAY(postgresql.ENUM("a", "b", "c", name="my_enum_1")),
            ),
            Column(
                "data_2",
                self.ARRAY(types.Enum("a", "b", "c", name="my_enum_2")),
            ),
        )

        t.create(testing.db)
        eq_(
            set(e["name"] for e in inspect(testing.db).get_enums()),
            set(["my_enum_1", "my_enum_2"]),
        )
        t.drop(testing.db)
        eq_(inspect(testing.db).get_enums(), []) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_types.py

示例15: test_create_drop_enum

# 需要导入模块: from sqlalchemy.dialects import postgresql [as 别名]
# 或者: from sqlalchemy.dialects.postgresql import ENUM [as 别名]
def test_create_drop_enum(self):
        # test escaping and unicode within CREATE TYPE for ENUM
        typ = postgresql.ENUM(
            "val1", "val2", "val's 3", u("méil"), name="myname"
        )
        self.assert_compile(
            postgresql.CreateEnumType(typ),
            u(
                "CREATE TYPE myname AS "
                "ENUM ('val1', 'val2', 'val''s 3', 'méil')"
            ),
        )

        typ = postgresql.ENUM("val1", "val2", "val's 3", name="PleaseQuoteMe")
        self.assert_compile(
            postgresql.CreateEnumType(typ),
            'CREATE TYPE "PleaseQuoteMe" AS ENUM '
            "('val1', 'val2', 'val''s 3')",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_compiler.py


注:本文中的sqlalchemy.dialects.postgresql.ENUM属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。