本文整理汇总了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)'
)
示例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)
示例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)"
)
示例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")
示例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)'
)
示例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 = '')")
示例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_]+$'")
示例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)
示例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,
)
示例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)"
)
示例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)"
)
示例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)"
)
示例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)"
)
示例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"
)