當前位置: 首頁>>代碼示例>>Python>>正文


Python op.create_check_constraint方法代碼示例

本文整理匯總了Python中alembic.op.create_check_constraint方法的典型用法代碼示例。如果您正苦於以下問題:Python op.create_check_constraint方法的具體用法?Python op.create_check_constraint怎麽用?Python op.create_check_constraint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在alembic.op的用法示例。


在下文中一共展示了op.create_check_constraint方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: upgrade

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def upgrade():
    ''' Add the column remote_git to the table pull_requests and make the
    project_id_from field nullable.
    '''
    op.add_column(
        'pull_requests',
        sa.Column('remote_git', sa.Text, nullable=True)
    )
    op.alter_column(
        'pull_requests',
        column_name='project_id_from',
        nullable=True,
        existing_nullable=False)
    op.create_check_constraint(
        "ck_lcl_or_remo_pr",
        "pull_requests",
        'NOT(project_id_from IS NULL AND remote_git IS NULL)'
    ) 
開發者ID:Pagure,項目名稱:pagure,代碼行數:20,代碼來源:257a7ce22682_add_the_remote_git_entry.py

示例2: batch_create_check_constraint

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def batch_create_check_constraint(
            cls, operations, constraint_name, condition, **kw):
        """Issue a "create check constraint" instruction using the
        current batch migration context.

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

        .. seealso::

            :meth:`.Operations.create_check_constraint`

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name

        """
        op = cls(
            constraint_name, operations.impl.table_name,
            condition, schema=operations.impl.schema, **kw)
        return operations.invoke(op) 
開發者ID:jpush,項目名稱:jbox,代碼行數:24,代碼來源:ops.py

示例3: upgrade

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def upgrade():
    op.add_column('templates', sa.Column('is_letter_contact_blank', sa.Boolean(), nullable=True))
    op.add_column('templates_history', sa.Column('is_letter_contact_blank', sa.Boolean(), nullable=True))
    op.execute("update templates set is_letter_contact_blank = false")
    op.execute("update templates_history set is_letter_contact_blank = false")
    op.alter_column("templates", "is_letter_contact_blank", nullable=False)
    op.alter_column("templates_history", "is_letter_contact_blank", nullable=False)

    op.create_check_constraint(
        "ck_templates_contact_block_is_blank",
        "templates",
        "Not(is_letter_contact_blank = True and service_letter_contact_id is not Null)"
    )
    op.create_check_constraint(
        "ck_templates_history_contact_block_is_blank",
        "templates_history",
        "Not(is_letter_contact_blank = True and service_letter_contact_id is not Null)"
    ) 
開發者ID:alphagov,項目名稱:notifications-api,代碼行數:20,代碼來源:0153_add_is_letter_contact_blank.py

示例4: downgrade

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('sticker_usage', 'usage_count',
                    existing_type=sa.INTEGER(),
                    nullable=False)
    op.add_column('chat', sa.Column('expecting_sticker_set', sa.BOOLEAN(), autoincrement=False, nullable=False))
    op.drop_constraint("only_one_action_check", "chat")
    op.create_check_constraint("only_one_action_check", "chat", """
        (expecting_sticker_set IS TRUE AND tagging_random_sticker IS FALSE AND fix_single_sticker IS FALSE AND full_sticker_set IS FALSE) OR \
        (tagging_random_sticker IS TRUE AND expecting_sticker_set IS FALSE AND fix_single_sticker IS FALSE AND full_sticker_set IS FALSE) OR \
        (fix_single_sticker IS TRUE AND tagging_random_sticker IS FALSE AND expecting_sticker_set IS FALSE AND full_sticker_set IS FALSE) OR \
        (full_sticker_set IS TRUE AND tagging_random_sticker IS FALSE AND fix_single_sticker IS FALSE AND expecting_sticker_set IS FALSE) OR \
        (full_sticker_set IS FALSE AND tagging_random_sticker IS FALSE AND fix_single_sticker IS FALSE AND expecting_sticker_set IS FALSE)
    """)

    # ### end Alembic commands ### 
開發者ID:Nukesor,項目名稱:sticker-finder,代碼行數:18,代碼來源:2019_04_01_4c9a81798173_remove_expecting_sticker_set.py

示例5: upgrade

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def upgrade():
    op.create_check_constraint("ck_started_before_ended",
                               "resource",
                               "started_at <= ended_at")
    op.create_check_constraint("ck_started_before_ended",
                               "resource_history",
                               "started_at <= ended_at") 
開發者ID:gnocchixyz,項目名稱:gnocchi,代碼行數:9,代碼來源:40c6aae14c3f_ck_started_before_ended.py

示例6: downgrade

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def downgrade():
    """ Bring back the pull_request_check constraint. """
    op.create_check_constraint(
        "pull_requests_check",
        "pull_requests",
        'NOT(project_id_from IS NULL AND remote_git IS NULL)'
    ) 
開發者ID:Pagure,項目名稱:pagure,代碼行數:9,代碼來源:46df6466b8fa_drop_pull_request_check.py

示例7: upgrade

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def upgrade():
	conn = op.get_bind()
	op.create_check_constraint("CK_approval_valid", "package_release", "not approved OR (task_id IS NULL AND NOT url = '')") 
開發者ID:minetest,項目名稱:contentdb,代碼行數:5,代碼來源:306ce331a2a7_.py

示例8: upgrade

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def upgrade():
	conn = op.get_bind()
	sync_trigger(conn, 'package', 'search_vector', ["name", "title", "short_desc", "desc"])
	op.create_check_constraint("name_valid", "package", "name ~* '^[a-z0-9_]+$'") 
開發者ID:minetest,項目名稱:contentdb,代碼行數:6,代碼來源:6dca6eceb04d_.py

示例9: batch_create_check_constraint

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def batch_create_check_constraint(
        cls, operations, constraint_name, condition, **kw
    ):
        """Issue a "create check constraint" instruction using the
        current batch migration context.

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

        .. seealso::

            :meth:`.Operations.create_check_constraint`

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name

        """
        op = cls(
            constraint_name,
            operations.impl.table_name,
            condition,
            schema=operations.impl.schema,
            **kw
        )
        return operations.invoke(op) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:29,代碼來源:ops.py

示例10: test_add_explicit_constraint

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def test_add_explicit_constraint(self):
        op_fixture("sqlite")
        assert_raises_message(
            NotImplementedError,
            "No support for ALTER of constraints in SQLite dialect",
            op.create_check_constraint,
            "foo",
            "sometable",
            column("name") > 5,
        ) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:12,代碼來源:test_sqlite.py

示例11: test_add_check_constraint

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def test_add_check_constraint(self):
        context = op_fixture(
            naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
        )
        op.create_check_constraint(
            "foo", "user_table", func.len(column("name")) > 5
        )
        context.assert_(
            "ALTER TABLE user_table ADD CONSTRAINT ck_user_table_foo "
            "CHECK (len(name) > 5)"
        ) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:13,代碼來源:test_op_naming_convention.py

示例12: test_add_check_constraint_name_is_none

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def test_add_check_constraint_name_is_none(self):
        context = op_fixture(naming_convention={"ck": "ck_%(table_name)s_foo"})
        op.create_check_constraint(
            None, "user_table", func.len(column("name")) > 5
        )
        context.assert_(
            "ALTER TABLE user_table ADD CONSTRAINT ck_user_table_foo "
            "CHECK (len(name) > 5)"
        ) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:11,代碼來源:test_op_naming_convention.py

示例13: test_add_check_constraint

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def test_add_check_constraint(self):
        context = op_fixture()
        op.create_check_constraint(
            "ck_user_name_len", "user_table", func.len(column("name")) > 5
        )
        context.assert_(
            "ALTER TABLE user_table ADD CONSTRAINT ck_user_name_len "
            "CHECK (len(name) > 5)"
        ) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:11,代碼來源:test_op.py

示例14: test_add_check_constraint_schema

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def test_add_check_constraint_schema(self):
        context = op_fixture()
        op.create_check_constraint(
            "ck_user_name_len",
            "user_table",
            func.len(column("name")) > 5,
            schema="foo",
        )
        context.assert_(
            "ALTER TABLE foo.user_table ADD CONSTRAINT ck_user_name_len "
            "CHECK (len(name) > 5)"
        ) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:14,代碼來源:test_op.py

示例15: upgrade

# 需要導入模塊: from alembic import op [as 別名]
# 或者: from alembic.op import create_check_constraint [as 別名]
def upgrade():
    op.alter_column('users', 'mobile_number', nullable=True)

    op.create_check_constraint(
        'ck_users_mobile_or_email_auth',
        'users',
        "auth_type = 'email_auth' or mobile_number is not null"
    ) 
開發者ID:alphagov,項目名稱:notifications-api,代碼行數:10,代碼來源:0136_user_mobile_nullable.py


注:本文中的alembic.op.create_check_constraint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。