code
stringlengths 26
870k
| docstring
stringlengths 1
65.6k
| func_name
stringlengths 1
194
| language
stringclasses 1
value | repo
stringlengths 8
68
| path
stringlengths 5
194
| url
stringlengths 46
254
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
async def test_edgeql_ddl_extending_04(self):
# Check that descendants are recomputed properly on rebase.
await self.con.execute(r"""
CREATE TYPE ExtA4 {
CREATE PROPERTY a -> int64;
};
CREATE ABSTRACT INHERITABLE ANNOTATION a_anno;
CREATE TYPE ExtB4 {
CREATE PROPERTY a -> int64 {
CREATE ANNOTATION a_anno := 'anno';
};
CREATE PROPERTY b -> str;
};
CREATE TYPE Ext4Child EXTENDING ExtA4;
CREATE TYPE Ext4GrandChild EXTENDING Ext4Child;
CREATE TYPE Ext4GrandGrandChild
EXTENDING Ext4GrandChild;
""")
await self.assert_query_result(
r"""
SELECT (
SELECT schema::ObjectType
FILTER .name = 'default::Ext4Child'
).properties.name;
""",
{'id', 'a'}
)
await self.con.execute(r"""
ALTER TYPE Ext4Child EXTENDING ExtB4;
""")
for name in {'Ext4Child', 'Ext4GrandChild', 'Ext4GrandGrandChild'}:
await self.assert_query_result(
f"""
SELECT (
SELECT schema::ObjectType
FILTER .name = 'default::{name}'
).properties.name;
""",
{'id', 'a', 'b'}
)
await self.assert_query_result(
r"""
WITH
ggc := (
SELECT schema::ObjectType
FILTER .name = 'default::Ext4GrandGrandChild'
)
SELECT
(SELECT ggc.properties FILTER .name = 'a')
.annotations@value;
""",
{'anno'}
)
await self.con.execute(r"""
ALTER TYPE Ext4Child DROP EXTENDING ExtB4;
""")
for name in {'Ext4Child', 'Ext4GrandChild', 'Ext4GrandGrandChild'}:
await self.assert_query_result(
f"""
SELECT (
SELECT schema::ObjectType
FILTER .name = 'default::{name}'
).properties.name;
""",
{'id', 'a'}
)
await self.assert_query_result(
r"""
WITH
ggc := (
SELECT schema::ObjectType
FILTER .name = 'default::Ext4GrandGrandChild'
)
SELECT
(SELECT ggc.properties FILTER .name = 'a')
.annotations@value;
""",
[]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_extending_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_extending_05(self):
# Check that field alters are propagated.
await self.con.execute(r"""
CREATE TYPE ExtA5 {
CREATE PROPERTY a -> int64 {
SET default := 1;
};
};
CREATE TYPE ExtB5 {
CREATE PROPERTY a -> int64 {
SET default := 2;
};
};
CREATE TYPE ExtC5 EXTENDING ExtB5;
""")
await self.assert_query_result(
r"""
WITH
C5 := (
SELECT schema::ObjectType
FILTER .name = 'default::ExtC5'
)
SELECT
(SELECT C5.properties FILTER .name = 'a')
.default;
""",
{'2'}
)
await self.con.execute(r"""
ALTER TYPE ExtC5 EXTENDING ExtA5 FIRST;
""")
await self.assert_query_result(
r"""
WITH
C5 := (
SELECT schema::ObjectType
FILTER .name = 'default::ExtC5'
)
SELECT
(SELECT C5.properties FILTER .name = 'a')
.default;
""",
{'1'}
)
await self.con.execute(r"""
ALTER TYPE ExtC5 DROP EXTENDING ExtA5;
""")
await self.assert_query_result(
r"""
WITH
C5 := (
SELECT schema::ObjectType
FILTER .name = 'default::ExtC5'
)
SELECT
(SELECT C5.properties FILTER .name = 'a')
.default;
""",
{'2'}
)
await self.con.execute(r"""
ALTER TYPE ExtC5 ALTER PROPERTY a SET REQUIRED;
ALTER TYPE ExtC5 DROP EXTENDING ExtB5;
""")
await self.assert_query_result(
r"""
WITH
C5 := (
SELECT schema::ObjectType
FILTER .name = 'default::ExtC5'
)
SELECT
(SELECT C5.properties FILTER .name = 'a')
.default;
""",
[]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_extending_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_extending_06(self):
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"'std::FreeObject' cannot be a parent type",
):
await self.con.execute("""
CREATE TYPE SomeObject6 EXTENDING FreeObject;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"'std::FreeObject' cannot be a parent type",
):
await self.con.execute("""
CREATE TYPE SomeObject6;
ALTER TYPE SomeObject6 EXTENDING FreeObject;
""") | )
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"'std::FreeObject' cannot be a parent type",
):
await self.con.execute( | test_edgeql_ddl_extending_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_extending_07(self):
await self.con.execute(r"""
create type A;
create type B extending A;
""")
with self.assertRaisesRegex(
edgedb.SchemaError,
r"could not find consistent ancestor order"):
await self.con.execute(r"""
create type C extending A, B;
""") | )
with self.assertRaisesRegex(
edgedb.SchemaError,
r"could not find consistent ancestor order"):
await self.con.execute(r | test_edgeql_ddl_extending_07 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_modules_01(self):
try:
await self.con.execute(r"""
CREATE MODULE test_other;
CREATE TYPE ModuleTest01 {
CREATE PROPERTY clash -> str;
};
CREATE TYPE test_other::Target;
CREATE TYPE test_other::ModuleTest01 {
CREATE LINK clash -> test_other::Target;
};
""")
await self.con.execute("""
DROP TYPE test_other::ModuleTest01;
DROP TYPE test_other::Target;
""")
finally:
await self.con.execute("""
DROP MODULE test_other;
""") | )
await self.con.execute( | test_edgeql_ddl_modules_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_modules_02(self):
await self.con.execute(r"""
CREATE MODULE test_other;
CREATE ABSTRACT TYPE test_other::Named {
CREATE REQUIRED PROPERTY name -> str;
};
CREATE ABSTRACT TYPE test_other::UniquelyNamed
EXTENDING test_other::Named
{
ALTER PROPERTY name {
CREATE DELEGATED CONSTRAINT exclusive;
}
};
CREATE TYPE Priority EXTENDING test_other::Named;
CREATE TYPE Status
EXTENDING test_other::UniquelyNamed;
INSERT Priority {name := 'one'};
INSERT Priority {name := 'two'};
INSERT Status {name := 'open'};
INSERT Status {name := 'closed'};
""")
await self.assert_query_result(
r"""
WITH MODULE test_other
SELECT Named.name;
""",
{
'one', 'two', 'open', 'closed',
}
)
await self.assert_query_result(
r"""
WITH MODULE test_other
SELECT UniquelyNamed.name;
""",
{
'open', 'closed',
}
)
await self.con.execute("""
DROP TYPE Status;
DROP TYPE Priority;
DROP TYPE test_other::UniquelyNamed;
DROP TYPE test_other::Named;
DROP MODULE test_other;
""") | )
await self.assert_query_result(
r | test_edgeql_ddl_modules_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_modules_03(self):
await self.con.execute(r"""
CREATE MODULE test_other;
CREATE ABSTRACT TYPE test_other::Named {
CREATE REQUIRED PROPERTY name -> str;
};
CREATE ABSTRACT TYPE test_other::UniquelyNamed
EXTENDING test_other::Named
{
ALTER PROPERTY name {
CREATE DELEGATED CONSTRAINT exclusive;
}
};
""")
try:
async with self.con.transaction():
await self.con.execute(r"""
START MIGRATION TO {
type Status extending test_other::UniquelyNamed;
};
POPULATE MIGRATION;
COMMIT MIGRATION;
""")
await self.con.execute("""
DROP TYPE Status;
""")
finally:
await self.con.execute("""
DROP TYPE test_other::UniquelyNamed;
DROP TYPE test_other::Named;
DROP MODULE test_other;
""") | )
try:
async with self.con.transaction():
await self.con.execute(r | test_edgeql_ddl_modules_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_modules_04(self):
await self.con.execute(r"""
CREATE MODULE test_other;
CREATE ABSTRACT TYPE test_other::Named {
CREATE REQUIRED PROPERTY name -> str;
};
CREATE ABSTRACT TYPE test_other::UniquelyNamed
EXTENDING test_other::Named
{
ALTER PROPERTY name {
CREATE DELEGATED CONSTRAINT exclusive;
}
};
CREATE ABSTRACT ANNOTATION whatever;
CREATE TYPE test_other::Foo;
CREATE TYPE test_other::Bar {
CREATE LINK foo -> test_other::Foo;
CREATE ANNOTATION whatever := "huh";
};
ALTER TYPE test_other::Foo {
CREATE LINK bar -> test_other::Bar;
};
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
"cannot drop module 'test_other' because it is not empty",
):
await self.con.execute(r"""
DROP MODULE test_other;
""") | )
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
"cannot drop module 'test_other' because it is not empty",
):
await self.con.execute(r | test_edgeql_ddl_modules_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_modules_05(self):
await self.con.execute(r"""
CREATE MODULE foo;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
"renaming modules is not supported",
):
await self.con.execute(r"""
ALTER MODULE foo RENAME TO bar;
""") | )
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
"renaming modules is not supported",
):
await self.con.execute(r | test_edgeql_ddl_modules_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_extension_package_01(self):
await self.con.execute(r"""
CREATE EXTENSION PACKAGE foo_01 VERSION '1.0' {
CREATE MODULE foo_ext;;
};
""")
await self.assert_query_result(
r"""
SELECT sys::ExtensionPackage {
name,
script,
ver := (.version.major, .version.minor),
}
FILTER .name LIKE 'foo_%'
ORDER BY .name
""",
[{
'name': 'foo_01',
'script': (
"CREATE MODULE foo_ext;;"
),
'ver': [1, 0],
}]
)
await self.con.execute(r"""
CREATE EXTENSION PACKAGE foo_01 VERSION '2.0-beta.1' {
SELECT 1/0;
};
""")
await self.assert_query_result(
r"""
SELECT sys::ExtensionPackage {
name,
script,
ver := (.version.major, .version.minor, .version.stage),
}
FILTER .name LIKE 'foo_%'
ORDER BY .name THEN .version
""",
[{
'name': 'foo_01',
'script': (
"CREATE MODULE foo_ext;;"
),
'ver': [1, 0, 'final'],
}, {
'name': 'foo_01',
'script': (
"SELECT 1/0;"
),
'ver': [2, 0, 'beta'],
}]
)
await self.con.execute(r"""
DROP EXTENSION PACKAGE foo_01 VERSION '1.0';
""")
await self.assert_query_result(
r"""
SELECT sys::ExtensionPackage {
name,
script,
}
FILTER .name LIKE 'foo_%'
ORDER BY .name
""",
[{
'name': 'foo_01',
'script': (
"SELECT 1/0;"
),
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_extension_package_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_extension_01(self):
await self.con.execute(r"""
CREATE EXTENSION PACKAGE MyExtension VERSION '1.0';
CREATE EXTENSION PACKAGE MyExtension VERSION '1.1';
CREATE EXTENSION PACKAGE MyExtension VERSION '2.0';
""")
await self.con.execute(r"""
CREATE EXTENSION MyExtension;
""")
await self.assert_query_result(
r"""
SELECT schema::Extension {
name,
package: {
ver := (.version.major, .version.minor)
}
}
FILTER .name = 'MyExtension'
""",
[{
'name': 'MyExtension',
'package': {
'ver': [2, 0],
}
}]
)
await self.con.execute(r"""
DROP EXTENSION MyExtension;
""")
await self.assert_query_result(
r"""
SELECT schema::Extension {
name,
package: {
ver := (.version.major, .version.minor)
}
}
FILTER .name = 'MyExtension'
""",
[],
)
await self.con.execute(r"""
CREATE EXTENSION MyExtension VERSION '1.0';
""")
await self.assert_query_result(
r"""
SELECT schema::Extension {
name,
package: {
ver := (.version.major, .version.minor)
}
}
FILTER .name = 'MyExtension'
""",
[{
'name': 'MyExtension',
'package': {
'ver': [1, 0],
}
}]
)
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
"version 1.0 is already installed",
):
await self.con.execute(r"""
CREATE EXTENSION MyExtension VERSION '2.0';
""")
await self.con.execute(r"""
DROP EXTENSION MyExtension;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
"cannot create extension 'MyExtension': extension"
" package 'MyExtension' version '3.0' does not exist",
):
await self.con.execute(r"""
CREATE EXTENSION MyExtension VERSION '3.0';
""") | )
await self.con.execute(r | test_edgeql_ddl_extension_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_extension_02(self):
await self.con.execute(r"""
CREATE EXTENSION PACKAGE TestAuthExtension VERSION '1.0' {
set ext_module := "ext::auth";
create module ext::auth;
create type ext::auth::Identity extending std::BaseObject {
create required property provider: std::str;
};
create type ext::auth::Email extending std::BaseObject {
create required property primary: std::bool;
create required link identity: ext::auth::Identity;
create constraint exclusive on ((.identity, .primary));
};
create scalar type ext::auth::JWTAlgo extending enum<RS256>;
create function ext::auth::_jwt_check_signature(
algo: ext::auth::JWTAlgo = ext::auth::JWTAlgo.RS256,
) -> bool
{
set volatility := 'Immutable';
using (
algo = ext::auth::JWTAlgo.RS256
);
};
create type ext::auth::Config extending std::BaseObject {
create property supported_algos:
array<ext::auth::JWTAlgo>;
create multi property algo_config:
tuple<algo: ext::auth::JWTAlgo, cfg: str>;
};
}
""")
await self.con.execute(r"""
CREATE EXTENSION TestAuthExtension;
""")
await self.con.execute(r"""
DROP EXTENSION TestAuthExtension;
""") | )
await self.con.execute(r | test_edgeql_ddl_extension_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_role_01(self):
if not self.has_create_role:
self.skipTest("create role is not supported by the backend")
await self.con.execute(r"""
CREATE ROLE foo_01;
""")
await self.assert_query_result(
r"""
SELECT sys::Role {
name,
superuser,
password,
} FILTER .name = 'foo_01'
""",
[{
'name': 'foo_01',
'superuser': False,
'password': None,
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_role_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_role_02(self):
if not self.has_create_role:
self.skipTest("create role is not supported by the backend")
await self.con.execute(r"""
CREATE SUPERUSER ROLE foo2 {
SET password := 'secret';
};
""")
await self.assert_query_result(
r"""
SELECT sys::Role {
name,
superuser,
} FILTER .name = 'foo2'
""",
[{
'name': 'foo2',
'superuser': True,
}]
)
role = await self.con.query_single('''
SELECT sys::Role { password }
FILTER .name = 'foo2'
''')
self.assertIsNotNone(role.password)
await self.con.execute(r"""
ALTER ROLE foo2 {
SET password := {}
};
""")
role = await self.con.query_single('''
SELECT sys::Role { password }
FILTER .name = 'foo2'
''')
self.assertIsNone(role.password) | )
await self.assert_query_result(
r | test_edgeql_ddl_role_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_role_03(self):
if not self.has_create_role:
self.skipTest("create role is not supported by the backend")
await self.con.execute(r"""
CREATE SUPERUSER ROLE foo3 {
SET password := 'secret';
};
""")
await self.con.execute(r"""
CREATE ROLE foo4 EXTENDING foo3;
""")
await self.assert_query_result(
r"""
SELECT sys::Role {
name,
superuser,
password,
member_of: {
name
},
} FILTER .name = 'foo4'
""",
[{
'name': 'foo4',
'superuser': False,
'password': None,
'member_of': [{
'name': 'foo3'
}]
}]
)
await self.con.execute(r"""
ALTER ROLE foo4 DROP EXTENDING foo3;
""")
await self.assert_query_result(
r"""
SELECT sys::Role {
name,
member_of: {
name
},
} FILTER .name = 'foo4'
""",
[{
'name': 'foo4',
'member_of': [],
}]
)
await self.con.execute(r"""
ALTER ROLE foo4 EXTENDING foo3;
""")
await self.assert_query_result(
r"""
SELECT sys::Role {
name,
member_of: {
name
},
} FILTER .name = 'foo4'
""",
[{
'name': 'foo4',
'member_of': [{
'name': 'foo3',
}],
}]
) | )
await self.con.execute(r | test_edgeql_ddl_role_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_role_04(self):
if not self.has_create_role:
self.skipTest("create role is not supported by the backend")
await self.con.execute(r"""
CREATE SUPERUSER ROLE foo5 IF NOT EXISTS {
SET password := 'secret';
};
CREATE SUPERUSER ROLE foo5 IF NOT EXISTS {
SET password := 'secret';
};
CREATE SUPERUSER ROLE foo5 IF NOT EXISTS {
SET password := 'secret';
};
CREATE ROLE foo6 EXTENDING foo5 IF NOT EXISTS;
CREATE ROLE foo6 EXTENDING foo5 IF NOT EXISTS;
CREATE ROLE foo6 EXTENDING foo5 IF NOT EXISTS;
""")
await self.assert_query_result(
r"""
SELECT sys::Role {
name,
superuser,
password,
member_of: {
name
},
} FILTER .name = 'foo6'
""",
[{
'name': 'foo6',
'superuser': False,
'password': None,
'member_of': [{
'name': 'foo5'
}]
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_role_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_role_05(self):
if self.has_create_role:
self.skipTest("create role is supported by the backend")
con = await self.connect()
try:
await con.execute("""
ALTER ROLE edgedb SET password := 'test_role_05'
""")
if self.has_create_database:
await con.execute("""CREATE DATABASE test_role_05""")
finally:
await con.aclose()
args = {'password': "test_role_05"}
if self.has_create_database:
args['database'] = "test_role_05"
con = await self.connect(**args)
try:
await con.execute("""
ALTER ROLE edgedb SET password := 'test'
""")
finally:
await con.aclose()
con = await self.connect()
try:
if self.has_create_database:
await tb.drop_db(con, 'test_role_05')
finally:
await con.aclose() | )
if self.has_create_database:
await con.execute("""CREATE DATABASE test_role_05""")
finally:
await con.aclose()
args = {'password': "test_role_05"}
if self.has_create_database:
args['database'] = "test_role_05"
con = await self.connect(**args)
try:
await con.execute( | test_edgeql_ddl_role_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_describe_schema(self):
# This is ensuring that describing std does not cause errors.
# The test validates only a small sample of entries, though.
result = await self.con.query_single("""
DESCRIBE MODULE std
""")
# This is essentially a syntax test from this point on.
re_filter = re.compile(r'[\s]+|(#.*?(\n|$))|(,(?=\s*[})]))')
result_stripped = re_filter.sub('', result).lower()
for expected in [
'''
CREATE SCALAR TYPE std::float32 EXTENDING std::anyfloat;
''',
'''
CREATE FUNCTION
std::str_lower(s: std::str) -> std::str
{
SET volatility := 'Immutable';
CREATE ANNOTATION std::description :=
'Return a lowercase copy of the input *string*.';
USING SQL FUNCTION 'lower';
};
''',
'''
CREATE INFIX OPERATOR
std::`AND`(a: std::bool, b: std::bool) -> std::bool {
SET volatility := 'Immutable';
CREATE ANNOTATION std::description :=
'Logical conjunction.';
USING SQL EXPRESSION;
};
''',
'''
CREATE ABSTRACT INFIX OPERATOR
std::`>=`(l: anytype, r: anytype) -> std::bool;
''',
'''
CREATE CAST FROM std::str TO std::bool {
SET volatility := 'Immutable';
USING SQL FUNCTION 'edgedb.str_to_bool';
};
''',
'''
CREATE CAST FROM std::int64 TO std::int16 {
SET volatility := 'Immutable';
USING SQL CAST;
ALLOW ASSIGNMENT;
};
''']:
expected_stripped = re_filter.sub('', expected).lower()
self.assertTrue(
expected_stripped in result_stripped,
f'`DESCRIBE MODULE std` is missing the following: "{expected}"'
) | )
# This is essentially a syntax test from this point on.
re_filter = re.compile(r'[\s]+|(#.*?(\n|$))|(,(?=\s*[})]))')
result_stripped = re_filter.sub('', result).lower()
for expected in [ | test_edgeql_ddl_describe_schema | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_rename_01(self):
await self.con.execute(r"""
CREATE TYPE RenameObj01 {
CREATE PROPERTY name -> str;
};
INSERT RenameObj01 {name := 'rename 01'};
ALTER TYPE RenameObj01 {
RENAME TO NewNameObj01;
};
""")
await self.assert_query_result(
r'''
SELECT NewNameObj01.name;
''',
['rename 01']
) | )
await self.assert_query_result(
r | test_edgeql_ddl_rename_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_rename_02(self):
await self.con.execute(r"""
CREATE TYPE RenameObj02 {
CREATE PROPERTY name -> str;
};
INSERT RenameObj02 {name := 'rename 02'};
ALTER TYPE RenameObj02 {
ALTER PROPERTY name {
RENAME TO new_name_02;
};
};
""")
await self.assert_query_result(
r'''
SELECT RenameObj02.new_name_02;
''',
['rename 02']
) | )
await self.assert_query_result(
r | test_edgeql_ddl_rename_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_rename_03(self):
await self.con.execute(r"""
CREATE TYPE RenameObj03 {
CREATE PROPERTY name -> str;
};
INSERT RenameObj03 {name := 'rename 03'};
ALTER TYPE RenameObj03 {
ALTER PROPERTY name {
RENAME TO new_name_03;
};
};
RESET MODULE;
""")
await self.assert_query_result(
r'''
SELECT RenameObj03.new_name_03;
''',
['rename 03']
) | )
await self.assert_query_result(
r | test_edgeql_ddl_rename_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_rename_04(self):
await self.con.execute("""
CREATE ABSTRACT LINK rename_link_04 {
CREATE PROPERTY rename_prop_04 -> std::int64;
};
CREATE TYPE LinkedObj04;
CREATE TYPE RenameObj04 {
CREATE MULTI LINK rename_link_04 EXTENDING rename_link_04
-> LinkedObj04;
};
INSERT LinkedObj04;
INSERT RenameObj04 {
rename_link_04 := LinkedObj04 {@rename_prop_04 := 123}
};
ALTER ABSTRACT LINK rename_link_04 {
ALTER PROPERTY rename_prop_04 {
RENAME TO new_prop_04;
};
};
""")
await self.assert_query_result(
r'''
SELECT RenameObj04.rename_link_04@new_prop_04;
''',
[123]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_rename_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_rename_05(self):
await self.con.execute("""
CREATE TYPE GrandParent01 {
CREATE PROPERTY foo -> int64;
};
CREATE TYPE Parent01 EXTENDING GrandParent01;
CREATE TYPE Parent02 EXTENDING GrandParent01;
CREATE TYPE Child EXTENDING Parent01, Parent02;
ALTER TYPE GrandParent01 {
ALTER PROPERTY foo RENAME TO renamed;
};
""")
await self.assert_query_result(
r'''
SELECT Child.renamed;
''',
[]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_rename_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_rename_abs_ptr_01(self):
await self.con.execute("""
CREATE ABSTRACT LINK abs_link {
CREATE PROPERTY prop -> std::int64;
};
CREATE TYPE LinkedObj;
CREATE TYPE RenameObj {
CREATE MULTI LINK link EXTENDING abs_link
-> LinkedObj;
};
INSERT LinkedObj;
INSERT RenameObj {
link := LinkedObj {@prop := 123}
};
""")
await self.con.execute("""
ALTER ABSTRACT LINK abs_link
RENAME TO new_abs_link;
""")
await self.assert_query_result(
r'''
SELECT RenameObj.link@prop;
''',
[123]
)
# Check we can create a new type that uses it
await self.con.execute("""
CREATE TYPE RenameObj2 {
CREATE MULTI LINK link EXTENDING new_abs_link
-> LinkedObj;
};
""")
# Check we can create a new link with the same name
await self.con.execute("""
CREATE ABSTRACT LINK abs_link {
CREATE PROPERTY prop -> std::int64;
};
""")
await self.con.execute("""
CREATE MODULE foo;
ALTER ABSTRACT LINK new_abs_link
RENAME TO foo::new_abs_link2;
""")
await self.con.execute("""
ALTER TYPE RenameObj DROP LINK link;
ALTER TYPE RenameObj2 DROP LINK link;
DROP ABSTRACT LINK foo::new_abs_link2;
""") | )
await self.con.execute( | test_edgeql_ddl_rename_abs_ptr_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_rename_abs_ptr_02(self):
await self.con.execute("""
CREATE ABSTRACT PROPERTY abs_prop {
CREATE ANNOTATION title := "lol";
};
CREATE TYPE RenameObj {
CREATE PROPERTY prop EXTENDING abs_prop -> str;
};
""")
await self.con.execute("""
ALTER ABSTRACT PROPERTY abs_prop
RENAME TO new_abs_prop;
""")
# Check we can create a new type that uses it
await self.con.execute("""
CREATE TYPE RenameObj2 {
CREATE PROPERTY prop EXTENDING new_abs_prop -> str;
};
""")
# Check we can create a new prop with the same name
await self.con.execute("""
CREATE ABSTRACT PROPERTY abs_prop {
CREATE ANNOTATION title := "lol";
};
""")
await self.con.execute("""
CREATE MODULE foo;
ALTER ABSTRACT PROPERTY new_abs_prop
RENAME TO foo::new_abs_prop2;
""")
await self.con.execute("""
ALTER TYPE RenameObj DROP PROPERTY prop;
ALTER TYPE RenameObj2 DROP PROPERTY prop;
DROP ABSTRACT PROPERTY foo::new_abs_prop2;
""") | )
await self.con.execute( | test_edgeql_ddl_rename_abs_ptr_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_rename_annotated_01(self):
await self.con.execute("""
CREATE TYPE RenameObj {
CREATE PROPERTY prop -> str {
CREATE ANNOTATION title := "lol";
}
};
""")
await self.con.execute("""
ALTER TYPE RenameObj {
ALTER PROPERTY prop RENAME TO prop2;
};
""") | )
await self.con.execute( | test_edgeql_ddl_rename_annotated_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_delete_abs_link_01(self):
# test deleting a trivial abstract link
await self.con.execute("""
CREATE ABSTRACT LINK abs_link;
""")
await self.con.execute("""
DROP ABSTRACT LINK abs_link;
""") | )
await self.con.execute( | test_edgeql_ddl_delete_abs_link_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_alias_01(self):
# Issue #1184
await self.con.execute(r"""
CREATE TYPE User {
CREATE REQUIRED PROPERTY name -> str;
};
CREATE TYPE Award {
CREATE LINK user -> User;
};
CREATE ALIAS Alias1 := Award {
user2 := (SELECT .user {name2 := .name ++ '!'})
};
CREATE ALIAS Alias2 := Alias1;
INSERT Award { user := (INSERT User { name := 'Corvo' }) };
""")
await self.assert_query_result(
r'''
SELECT Alias1 {
user2: {
name2
}
}
''',
[{
'user2': {
'name2': 'Corvo!',
},
}],
)
await self.assert_query_result(
r'''
SELECT Alias2 {
user2: {
name2
}
}
''',
[{
'user2': {
'name2': 'Corvo!',
},
}],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_alias_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_alias_02(self):
# Issue #1184
await self.con.execute(r"""
CREATE TYPE User {
CREATE REQUIRED PROPERTY name -> str;
};
CREATE TYPE Award {
CREATE REQUIRED PROPERTY name -> str;
};
CREATE ALIAS Alias1 := Award {
a_user := (SELECT User { name } LIMIT 1)
};
CREATE ALIAS Alias2 := Alias1;
INSERT User { name := 'Corvo' };
INSERT Award { name := 'Rune' };
""")
await self.assert_query_result(
r'''
SELECT Alias1 {
a_user: {
name
}
}
''',
[{
'a_user': {
'name': 'Corvo',
},
}],
)
await self.assert_query_result(
r'''
SELECT Alias2 {
a_user: {
name
}
}
''',
[{
'a_user': {
'name': 'Corvo',
},
}],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_alias_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_alias_03(self):
await self.con.execute(r"""
CREATE ALIAS RenameAlias03 := (
SELECT BaseObject {
alias_computable := 'rename alias 03'
}
);
ALTER ALIAS RenameAlias03 {
RENAME TO NewAlias03;
};
""")
await self.assert_query_result(
r'''
SELECT NewAlias03.alias_computable LIMIT 1;
''',
['rename alias 03']
)
await self.con.execute(r"""
CREATE MODULE foo;
ALTER ALIAS NewAlias03 {
RENAME TO foo::NewAlias03;
};
""")
await self.assert_query_result(
r'''
SELECT foo::NewAlias03.alias_computable LIMIT 1;
''',
['rename alias 03']
)
await self.con.execute(r"""
DROP ALIAS foo::NewAlias03;
""") | )
await self.assert_query_result(
r | test_edgeql_ddl_alias_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_alias_04(self):
await self.con.execute(r"""
CREATE ALIAS DupAlias04_1 := BaseObject {
foo := 'hello world 04'
};
# create an identical alias with a different name
CREATE ALIAS DupAlias04_2 := BaseObject {
foo := 'hello world 04'
};
""")
await self.assert_query_result(
r'''
SELECT DupAlias04_1.foo LIMIT 1;
''',
['hello world 04']
)
await self.assert_query_result(
r'''
SELECT DupAlias04_2.foo LIMIT 1;
''',
['hello world 04']
) | )
await self.assert_query_result(
r | test_edgeql_ddl_alias_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_alias_05(self):
await self.con.execute(r"""
CREATE TYPE BaseType05 {
CREATE PROPERTY name -> str;
};
CREATE ALIAS BT05Alias1 := BaseType05 {
a := .name ++ '_more'
};
# alias of an alias
CREATE ALIAS BT05Alias2 := BT05Alias1 {
b := .a ++ '_stuff'
};
INSERT BaseType05 {name := 'bt05'};
""")
await self.assert_query_result(
r'''
SELECT BT05Alias1 {name, a};
''',
[{
'name': 'bt05',
'a': 'bt05_more',
}]
)
await self.assert_query_result(
r'''
SELECT BT05Alias2 {name, a, b};
''',
[{
'name': 'bt05',
'a': 'bt05_more',
'b': 'bt05_more_stuff',
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_alias_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_alias_06(self):
# Issue #1184
await self.con.execute(r"""
CREATE TYPE BaseType06 {
CREATE PROPERTY name -> str;
};
INSERT BaseType06 {
name := 'bt06',
};
INSERT BaseType06 {
name := 'bt06_1',
};
CREATE ALIAS BT06Alias1 := BaseType06 {
a := .name ++ '_a'
};
CREATE ALIAS BT06Alias2 := BT06Alias1 {
b := .a ++ '_b'
};
CREATE ALIAS BT06Alias3 := BaseType06 {
b := BT06Alias1
};
""")
await self.assert_query_result(
r'''
SELECT BT06Alias1 {name, a} FILTER .name = 'bt06';
''',
[{
'name': 'bt06',
'a': 'bt06_a',
}],
)
await self.assert_query_result(
r'''
SELECT BT06Alias2 {name, a, b} FILTER .name = 'bt06';
''',
[{
'name': 'bt06',
'a': 'bt06_a',
'b': 'bt06_a_b',
}],
)
await self.assert_query_result(
r'''
SELECT BT06Alias3 {
name,
b: {name, a} ORDER BY .name
}
FILTER .name = 'bt06';
''',
[{
'name': 'bt06',
'b': [{
'name': 'bt06',
'a': 'bt06_a',
}, {
'name': 'bt06_1',
'a': 'bt06_1_a',
}],
}],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_alias_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_alias_08(self):
# Issue #1184
await self.con.execute(r"""
CREATE TYPE BaseType08 {
CREATE PROPERTY name -> str;
};
INSERT BaseType08 {
name := 'bt08',
};
CREATE ALIAS BT08Alias1 := BaseType08 {
a := .name ++ '_a'
};
CREATE ALIAS BT08Alias2 := BT08Alias1 {
b := .a ++ '_b'
};
# drop the freshly created alias
DROP ALIAS BT08Alias2;
# re-create the alias that was just dropped
CREATE ALIAS BT08Alias2 := BT08Alias1 {
b := .a ++ '_bb'
};
""")
await self.assert_query_result(
r'''
SELECT BT08Alias1 {name, a} FILTER .name = 'bt08';
''',
[{
'name': 'bt08',
'a': 'bt08_a',
}],
)
await self.assert_query_result(
r'''
SELECT BT08Alias2 {name, a, b} FILTER .name = 'bt08';
''',
[{
'name': 'bt08',
'a': 'bt08_a',
'b': 'bt08_a_bb',
}],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_alias_08 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_alias_09(self):
await self.con.execute(r"""
CREATE ALIAS CreateAlias09 := (
SELECT BaseObject {
alias_computable := 'rename alias 03'
}
);
""")
async with self.assertRaisesRegexTx(
edgedb.InvalidLinkTargetError,
"invalid link type: 'default::CreateAlias09' is an"
" expression alias, not a proper object type",
):
await self.con.execute(r"""
CREATE TYPE AliasType09 {
CREATE OPTIONAL SINGLE LINK a -> CreateAlias09;
}
""") | )
async with self.assertRaisesRegexTx(
edgedb.InvalidLinkTargetError,
"invalid link type: 'default::CreateAlias09' is an"
" expression alias, not a proper object type",
):
await self.con.execute(r | test_edgeql_ddl_alias_09 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_alias_11(self):
await self.con.execute(r"""
create type X;
create alias Z := (with lol := X, select count(lol));
""")
await self.con.execute(r"""
drop alias Z
""")
await self.con.execute(r"""
create alias Z := (with lol := X, select count(lol));
""") | )
await self.con.execute(r | test_edgeql_ddl_alias_11 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_alias_12(self):
await self.con.execute(
r"""
create alias X := 1;
create type Y;
create global Z -> int64;
"""
)
async with self.assertRaisesRegexTx(
edgedb.SchemaError, "scalar type 'default::X' already exists"
):
# this should ideally say "alias X", but this is better than ISE
await self.con.execute(
r"""
create alias X := 2;
"""
)
async with self.assertRaisesRegexTx(
edgedb.SchemaError, "type 'default::Y' already exists"
):
await self.con.execute(
r"""
create alias Y := 2;
"""
)
async with self.assertRaisesRegexTx(
edgedb.SchemaError, "global 'default::Z' already exists"
):
await self.con.execute(
r"""
create alias Z := 2;
"""
) | )
async with self.assertRaisesRegexTx(
edgedb.SchemaError, "scalar type 'default::X' already exists"
):
# this should ideally say "alias X", but this is better than ISE
await self.con.execute(
r | test_edgeql_ddl_alias_12 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_alias_13(self):
'''
Creating an alias of an array of valid scalars should be possible.
(Related to #6456.)
'''
await self.con.execute(r"""
create alias ArrAlias := [range(0, 1)];
""")
await self.assert_query_result(
r'''
select ArrAlias = [range(0, 1)];
''',
[True]
) | Creating an alias of an array of valid scalars should be possible.
(Related to #6456.) | test_edgeql_ddl_alias_13 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_alias_14(self):
# Issue #8003
await self.con.execute(r"""
create global One := 1;
create alias MyAlias := global One;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError, "index expressions must be immutable"
):
await self.con.execute(
r"""
create type Foo { create index on (MyAlias) };
"""
) | )
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError, "index expressions must be immutable"
):
await self.con.execute(
r | test_edgeql_ddl_alias_14 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_alias_15(self):
# Issue #8003
await self.con.execute(
r"""
create global One := 1;
create alias MyAlias := 1;
create type Foo { create index on (MyAlias) };
"""
)
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
"cannot alter alias 'default::MyAlias' because this affects "
"expression of index of object type 'default::Foo'"
):
await self.con.execute(
r"""
alter alias MyAlias {using (global One)};
"""
) | )
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
"cannot alter alias 'default::MyAlias' because this affects "
"expression of index of object type 'default::Foo'"
):
await self.con.execute(
r | test_edgeql_ddl_alias_15 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_inheritance_alter_01(self):
await self.con.execute(r"""
CREATE TYPE InhTest01 {
CREATE PROPERTY testp -> int64;
};
CREATE TYPE InhTest01_child EXTENDING InhTest01;
""")
await self.con.execute("""
ALTER TYPE InhTest01 {
DROP PROPERTY testp;
}
""") | )
await self.con.execute( | test_edgeql_ddl_inheritance_alter_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_inheritance_alter_02(self):
await self.con.execute(r"""
CREATE TYPE InhTest01 {
CREATE PROPERTY testp -> int64;
};
CREATE TYPE InhTest01_child EXTENDING InhTest01;
""")
with self.assertRaisesRegex(
edgedb.SchemaError,
"cannot drop inherited property 'testp'"):
await self.con.execute("""
ALTER TYPE InhTest01_child {
DROP PROPERTY testp;
}
""") | )
with self.assertRaisesRegex(
edgedb.SchemaError,
"cannot drop inherited property 'testp'"):
await self.con.execute( | test_edgeql_ddl_inheritance_alter_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_inheritance_alter_03(self):
await self.con.execute(r"""
CREATE TYPE Owner;
CREATE TYPE Stuff1 {
# same link name, but NOT related via explicit inheritance
CREATE LINK owner -> Owner
};
CREATE TYPE Stuff2 {
# same link name, but NOT related via explicit inheritance
CREATE LINK owner -> Owner
};
""")
await self.assert_query_result("""
SELECT Owner.<owner;
""", []) | )
await self.assert_query_result( | test_edgeql_ddl_inheritance_alter_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_inheritance_alter_04(self):
await self.con.execute(r"""
CREATE TYPE InhTest04 {
CREATE PROPERTY testp -> int64;
};
CREATE TYPE InhTest04_child EXTENDING InhTest04;
""")
await self.con.execute(r"""
ALTER TYPE InhTest04_child {
ALTER PROPERTY testp {
SET default := 42;
};
};
""")
await self.assert_query_result(
r"""
SELECT schema::ObjectType {
properties: {
name,
default,
}
FILTER .name = 'testp',
}
FILTER .name = 'default::InhTest04_child';
""",
[{
'properties': [{
'name': 'testp',
'default': '42',
}],
}],
) | )
await self.con.execute(r | test_edgeql_ddl_inheritance_alter_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_01(self):
# Test that the inherited constraint doesn't end up with some
# bad name like 'default::std::exclusive'.
await self.con.execute(r"""
CREATE ABSTRACT TYPE BaseTypeCon01;
CREATE TYPE TypeCon01 EXTENDING BaseTypeCon01;
ALTER TYPE BaseTypeCon01
CREATE SINGLE PROPERTY name -> std::str;
# make sure that we can create a constraint in the base
# type now
ALTER TYPE BaseTypeCon01
ALTER PROPERTY name
CREATE DELEGATED CONSTRAINT exclusive;
""")
await self.assert_query_result("""
WITH MODULE schema
SELECT ObjectType {
name,
properties: {
name,
constraints: {
name,
delegated,
}
} FILTER .name = 'name'
}
FILTER .name LIKE 'default::%TypeCon01'
ORDER BY .name;
""", [
{
'name': 'default::BaseTypeCon01',
'properties': [{
'name': 'name',
'constraints': [{
'name': 'std::exclusive',
'delegated': True,
}],
}]
},
{
'name': 'default::TypeCon01',
'properties': [{
'name': 'name',
'constraints': [{
'name': 'std::exclusive',
'delegated': False,
}],
}]
}
]) | )
await self.assert_query_result( | test_edgeql_ddl_constraint_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_03(self):
# Test for #1727. Usage of EXISTS in constraints.
await self.con.execute(r"""
CREATE TYPE TypeCon03 {
CREATE PROPERTY name -> str {
# emulating "required"
CREATE CONSTRAINT expression ON (EXISTS __subject__)
}
};
""")
await self.con.execute("""
INSERT TypeCon03 {name := 'OK'};
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r'invalid name'):
async with self.con.transaction():
await self.con.execute("""
INSERT TypeCon03;
""") | )
await self.con.execute( | test_edgeql_ddl_constraint_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_04(self):
# Test for #1727. Usage of EXISTS in constraints.
await self.con.execute(r"""
CREATE TYPE TypeCon04 {
CREATE MULTI PROPERTY name -> str {
# emulating "required"
CREATE CONSTRAINT expression ON (EXISTS __subject__)
}
};
""")
await self.con.execute("""
INSERT TypeCon04 {name := 'OK'};
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r'invalid name'):
async with self.con.transaction():
await self.con.execute("""
INSERT TypeCon04 {name := {}};
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r'invalid name'):
async with self.con.transaction():
await self.con.execute("""
INSERT TypeCon04;
""") | )
await self.con.execute( | test_edgeql_ddl_constraint_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_05(self):
# Test for #1727. Usage of EXISTS in constraints.
await self.con.execute(r"""
CREATE TYPE Child05;
CREATE TYPE TypeCon05 {
CREATE LINK child -> Child05 {
# emulating "required"
CREATE CONSTRAINT expression ON (EXISTS __subject__)
}
};
""")
await self.con.execute("""
INSERT Child05;
INSERT TypeCon05 {child := (SELECT Child05 LIMIT 1)};
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r'invalid child'):
async with self.con.transaction():
await self.con.execute("""
INSERT TypeCon05;
""") | )
await self.con.execute( | test_edgeql_ddl_constraint_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_06(self):
# Test for #1727. Usage of EXISTS in constraints.
await self.con.execute(r"""
CREATE TYPE Child06;
CREATE TYPE TypeCon06 {
CREATE MULTI LINK children -> Child06 {
# emulating "required"
CREATE CONSTRAINT expression ON (EXISTS __subject__)
}
};
""")
await self.con.execute("""
INSERT Child06;
INSERT TypeCon06 {children := Child06};
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r'invalid children'):
async with self.con.transaction():
await self.con.execute("""
INSERT TypeCon06;
""") | )
await self.con.execute( | test_edgeql_ddl_constraint_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_07(self):
# Test for #1727. Usage of EXISTS in constraints.
await self.con.execute(r"""
CREATE TYPE Child07;
CREATE TYPE TypeCon07 {
CREATE LINK child -> Child07 {
CREATE PROPERTY index -> int64;
# emulating "required"
CREATE CONSTRAINT expression ON (EXISTS __subject__@index)
}
};
""")
await self.con.execute("""
INSERT Child07;
INSERT TypeCon07 {
child := (SELECT Child07 LIMIT 1){@index := 0}
};
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r'invalid child'):
async with self.con.transaction():
await self.con.execute("""
INSERT TypeCon07 {
child := (SELECT Child07 LIMIT 1)
};
""") | )
await self.con.execute( | test_edgeql_ddl_constraint_07 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_08(self):
# Test non-delegated object constraints on abstract types
await self.con.execute(r"""
CREATE TYPE Base {
CREATE PROPERTY x -> str {
CREATE CONSTRAINT exclusive;
}
};
CREATE TYPE Foo EXTENDING Base;
CREATE TYPE Bar EXTENDING Base;
INSERT Foo { x := "a" };
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute(r"""
INSERT Foo { x := "a" };
""") | )
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute(r | test_edgeql_ddl_constraint_08 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_09(self):
await self.con.execute(r"""
CREATE ABSTRACT TYPE Text {
CREATE REQUIRED SINGLE PROPERTY body -> str {
CREATE CONSTRAINT max_len_value(10000);
};
};
CREATE TYPE Comment EXTENDING Text;
""")
await self.assert_query_result(
"""
select schema::Constraint {
name, params: {name, @index} order by @index
}
filter .name = 'std::max_len_value'
and .subject.name = 'body'
and .subject[is schema::Pointer].source.name ='default::Text';
""",
[
{
"name": "std::max_len_value",
"params": [
{"name": "__subject__", "@index": 0},
{"name": "max", "@index": 1}
]
}
],
)
await self.con.execute("""
ALTER TYPE Text
ALTER PROPERTY body
DROP CONSTRAINT max_len_value(10000);
""") | )
await self.assert_query_result( | test_edgeql_ddl_constraint_09 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_10(self):
await self.con.execute(r"""
CREATE ABSTRACT TYPE Text {
CREATE REQUIRED SINGLE PROPERTY body -> str {
CREATE CONSTRAINT max_len_value(10000);
};
};
CREATE TYPE Comment EXTENDING Text;
""")
await self.con.execute("""
ALTER TYPE Text
DROP PROPERTY body;
""") | )
await self.con.execute( | test_edgeql_ddl_constraint_10 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_11(self):
await self.con.execute(r"""
CREATE ABSTRACT TYPE Text {
CREATE REQUIRED SINGLE PROPERTY body -> str {
CREATE CONSTRAINT max_value(10000)
ON (len(__subject__));
};
};
CREATE TYPE Comment EXTENDING Text;
CREATE TYPE Troll EXTENDING Comment;
""")
await self.con.execute("""
ALTER TYPE Text
ALTER PROPERTY body
DROP CONSTRAINT max_value(10000)
ON (len(__subject__));
""") | )
await self.con.execute( | test_edgeql_ddl_constraint_11 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_13(self):
await self.con.execute(r"""
CREATE ABSTRACT CONSTRAINT Lol {
USING ((__subject__ < 10));
};
CREATE TYPE Foo {
CREATE PROPERTY x -> int64 {
CREATE CONSTRAINT Lol;
};
};
CREATE TYPE Bar EXTENDING Foo;
""")
await self.con.execute(r"""
ALTER ABSTRACT CONSTRAINT Lol RENAME TO Lolol;
""")
await self.con.execute(r"""
ALTER TYPE Foo DROP PROPERTY x;
""") | )
await self.con.execute(r | test_edgeql_ddl_constraint_13 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_14(self):
# Test for #1727. Usage of EXISTS in constraints.
await self.con.execute(r"""
CREATE TYPE Foo;
CREATE TYPE Bar {
CREATE MULTI LINK children -> Foo {
CREATE PROPERTY lprop -> str {
CREATE CONSTRAINT expression ON (EXISTS __subject__)
}
}
};
""")
await self.con.execute("""
INSERT Foo;
INSERT Bar {children := (SELECT Foo {@lprop := "test"})};
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r'invalid lprop'):
async with self.con.transaction():
await self.con.execute("""
INSERT Bar { children := Foo };
""") | )
await self.con.execute( | test_edgeql_ddl_constraint_14 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_15(self):
# Test for #1727. Usage of ?!= in constraints.
await self.con.execute(r"""
CREATE TYPE Foo;
CREATE TYPE Bar {
CREATE MULTI LINK children -> Foo {
CREATE PROPERTY lprop -> str {
CREATE CONSTRAINT expression ON (
__subject__ ?!= <str>{})
}
}
};
""")
await self.con.execute("""
INSERT Foo;
INSERT Bar {children := (SELECT Foo {@lprop := "test"})};
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r'invalid lprop'):
async with self.con.transaction():
await self.con.execute("""
INSERT Bar { children := Foo };
""") | )
await self.con.execute( | test_edgeql_ddl_constraint_15 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_16(self):
await self.con.execute(r"""
create type Foo {
create property x -> tuple<x: str, y: str> {
create constraint exclusive;
}
};
""")
await self.con.execute("""
INSERT Foo { x := ('1', '2') };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'x violates exclusivity constraint'):
await self.con.execute("""
INSERT Foo { x := ('1', '2') };
""") | )
await self.con.execute( | test_edgeql_ddl_constraint_16 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_17(self):
await self.con.execute(r"""
create type Post {
create link original -> Post;
create constraint expression ON ((.original != __subject__));
};
""")
await self.con.execute("""
insert Post;
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'invalid Post'):
await self.con.execute("""
update Post set { original := Post };
""") | )
await self.con.execute( | test_edgeql_ddl_constraint_17 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_18(self):
await self.con.execute(r"""
create type Foo {
create property flag -> bool;
create property except -> bool;
create constraint expression on (.flag) except (.except);
};
""")
# Check all combinations of expression outcome and except value
for flag in [True, False, None]:
for ex in [True, False, None]:
op = self.con.query(
"""
INSERT Foo {
flag := <optional bool>$flag,
except := <optional bool>$ex,
}
""",
flag=flag,
ex=ex,
)
# The constraint fails if it is specifically false
# (not empty) and except is not true.
fail = flag is False and ex is not True
if fail:
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'invalid Foo'):
await op
else:
await op | )
# Check all combinations of expression outcome and except value
for flag in [True, False, None]:
for ex in [True, False, None]:
op = self.con.query( | test_edgeql_ddl_constraint_18 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_19(self):
# Make sure we distinguish between on and except in name creation;
await self.con.execute(r"""
create abstract constraint always_fail extending constraint {
using (false)
};
create type Foo;
create type OnTest {
create link l -> Foo {
create property flag -> bool;
create constraint always_fail on (@flag);
};
};
create type ExceptTest {
create link l -> Foo {
create property flag -> bool;
create constraint always_fail except (@flag);
};
};
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'invalid l'):
await self.con.execute("""
insert OnTest { l := (insert Foo) { @flag := false } }
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'invalid l'):
await self.con.execute("""
insert OnTest { l := (insert Foo) { @flag := true } }
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'invalid l'):
await self.con.execute("""
insert ExceptTest { l := (insert Foo) { @flag := false } }
""")
await self.con.execute("""
insert ExceptTest { l := (insert Foo) { @flag := true } }
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'invalid l'):
await self.con.execute( | test_edgeql_ddl_constraint_19 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_21(self):
# We plan on rejecting this, but for now do the thing closest
# to right.
await self.con.execute(r"""
create type A {
create property x -> str;
create constraint exclusive on (A.x);
};
create type B extending A;
insert A { x := "!" };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute("""
insert B { x := "!" }
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute( | test_edgeql_ddl_constraint_21 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_25(self):
await self.con.execute("""
create scalar type Status extending enum<open, closed>;
create type Order {
create required property status -> Status;
}
""")
# enum casts in constraints
await self.con.execute("""
alter type Order {
create constraint exclusive on ((Status.open = .status));
};
""")
await self.con.execute("""
alter type Order {
create constraint exclusive on ((<Status>'open' = .status));
};
""")
await self.con.execute("""
alter type Order {
create constraint exclusive on (('open' = <str>.status));
};
""")
# enum casts in indexes
await self.con.execute("""
alter type Order {
create index on ((Status.open = .status));
};
""")
await self.con.execute("""
alter type Order {
create index on ((<Status>'open' = .status));
};
""")
await self.con.execute("""
alter type Order {
create index on (('open' = <str>.status));
};
""") | )
# enum casts in constraints
await self.con.execute( | test_edgeql_ddl_constraint_25 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_26(self):
await self.con.execute("""
CREATE TYPE Foo {
CREATE REQUIRED PROPERTY val: tuple<int64, int64> {
CREATE CONSTRAINT exclusive ON (.0);
};
CREATE CONSTRAINT exclusive ON (.val.1);
CREATE PROPERTY x: int64;
CREATE CONSTRAINT exclusive ON (<str>.x);
};
""")
await self.con.execute("""
insert Foo { val := (1, 2), x := 3 };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'val violates exclusivity constraint'):
await self.con.execute("""
insert Foo { val := (1, -1), x := -1 };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'Foo violates exclusivity constraint'):
await self.con.execute("""
insert Foo { val := (-1, 2), x := -1 };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'Foo violates exclusivity constraint'):
await self.con.execute("""
insert Foo { val := (-1, -2), x := 3 };
""") | )
await self.con.execute( | test_edgeql_ddl_constraint_26 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_32(self):
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError, ''
):
await self.con.execute(r"""
create type S {
create constraint expression on (((0, 0)).0 = 0);
};
""")
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError, ''
):
await self.con.execute(r"""
create type S {
create constraint expression on (((true, 0)).0);
};
""") | )
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError, ''
):
await self.con.execute(r | test_edgeql_ddl_constraint_32 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_check_01a(self):
await self.con.execute(r"""
create type Foo {
create property foo -> str;
};
create type Bar extending Foo;
insert Foo { foo := "x" };
insert Bar { foo := "x" };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute("""
alter type Foo alter property foo {
create constraint exclusive
};
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute( | test_edgeql_ddl_constraint_check_01a | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_check_01b(self):
await self.con.execute(r"""
create type Foo {
create property foo -> str {create constraint exclusive;};
};
create type Bar {
create property foo -> str {create constraint exclusive;};
};
insert Foo { foo := "x" };
insert Bar { foo := "x" };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute("""
alter type Bar extending Foo;
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute( | test_edgeql_ddl_constraint_check_01b | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_check_02a(self):
await self.con.execute(r"""
create type Foo {
create property foo -> str;
};
create type Bar extending Foo;
insert Foo { foo := "x" };
insert Bar { foo := "x" };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute("""
alter type Foo {
create constraint exclusive on (.foo);
};
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute( | test_edgeql_ddl_constraint_check_02a | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_check_02b(self):
await self.con.execute(r"""
create type Foo {
create property foo -> str;
create constraint exclusive on (.foo);
};
create type Bar {
CREATE PROPERTY foo -> str;
create constraint exclusive on (.foo);
};
insert Foo { foo := "x" };
insert Bar { foo := "x" };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute("""
alter type Bar extending Foo;
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute( | test_edgeql_ddl_constraint_check_02b | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_check_03a(self):
await self.con.execute(r"""
create type Foo {
create multi property foo -> str;
};
create type Bar extending Foo;
insert Foo { foo := "x" };
insert Bar { foo := "x" };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute("""
alter type Foo alter property foo {
create constraint exclusive
};
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute( | test_edgeql_ddl_constraint_check_03a | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_check_03b(self):
await self.con.execute(r"""
create type Foo {
create multi property foo -> str {create constraint exclusive;}
};
create type Bar {
create multi property foo -> str {create constraint exclusive;}
};
insert Foo { foo := "x" };
insert Bar { foo := "x" };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute("""
alter type Bar extending Foo;
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute( | test_edgeql_ddl_constraint_check_03b | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_check_04(self):
await self.con.execute(r"""
create type Tgt;
create type Foo {
create link foo -> Tgt
};
create type Bar extending Foo;
insert Tgt;
insert Foo { foo := assert_single(Tgt) };
insert Bar { foo := assert_single(Tgt) };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute("""
alter type Foo alter link foo {
create constraint exclusive
};
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute( | test_edgeql_ddl_constraint_check_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_check_05(self):
await self.con.execute(r"""
create type Tgt;
create type Foo {
create multi link foo -> Tgt { create property x -> str; }
};
create type Bar extending Foo;
insert Tgt;
insert Foo { foo := assert_single(Tgt) };
insert Bar { foo := assert_single(Tgt) };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute("""
alter type Foo alter link foo {
create constraint exclusive
};
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute( | test_edgeql_ddl_constraint_check_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_check_06(self):
await self.con.execute(r"""
create type Tgt;
create type Foo {
create link foo -> Tgt { create property x -> str; }
};
create type Bar extending Foo;
insert Tgt;
insert Foo { foo := assert_single(Tgt { @x := "foo" }) };
insert Bar { foo := assert_single(Tgt { @x := "foo" }) };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'x violates exclusivity constraint'):
await self.con.execute("""
alter type Foo alter link foo alter property x {
create constraint exclusive
};
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'x violates exclusivity constraint'):
await self.con.execute( | test_edgeql_ddl_constraint_check_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_check_07(self):
await self.con.execute(r"""
create type Tgt;
create type Foo {
create link foo -> Tgt { create property x -> str; }
};
create type Bar extending Foo;
insert Tgt;
insert Foo { foo := assert_single(Tgt { @x := "foo" }) };
insert Bar { foo := assert_single(Tgt { @x := "foo" }) };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute("""
alter type Foo alter link foo {
create constraint exclusive on (__subject__@x)
};
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'foo violates exclusivity constraint'):
await self.con.execute( | test_edgeql_ddl_constraint_check_07 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_check_08(self):
await self.con.execute(r"""
create type Tgt;
create abstract link Lnk { create property x -> str; };
create type Foo {
create link foo extending Lnk -> Tgt;
};
create type Bar extending Foo;
insert Tgt;
insert Foo { foo := assert_single(Tgt { @x := "foo" }) };
insert Bar { foo := assert_single(Tgt { @x := "foo" }) };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'x violates exclusivity constraint'):
await self.con.execute("""
alter abstract link Lnk alter property x {
create constraint exclusive
};
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'x violates exclusivity constraint'):
await self.con.execute( | test_edgeql_ddl_constraint_check_08 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_check_09(self):
# Test a diamond pattern with a delegated constraint
await self.con.execute(r"""
CREATE ABSTRACT TYPE R {
CREATE REQUIRED PROPERTY name -> std::str {
CREATE DELEGATED CONSTRAINT std::exclusive;
};
};
CREATE TYPE S EXTENDING R;
CREATE TYPE T EXTENDING R;
CREATE TYPE V EXTENDING S, T;
INSERT S { name := "S" };
INSERT T { name := "T" };
INSERT V { name := "V" };
""")
for t1, t2 in ["SV", "TV", "VT", "VS"]:
with self.annotate(tables=(t1, t2)):
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute(f"""
insert {t1} {{ name := "{t2}" }}
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute(f"""
select {{
(insert {t1} {{ name := "!" }}),
(insert {t2} {{ name := "!" }}),
}}
""")
await self.con.execute(r"""
ALTER TYPE default::R {
DROP PROPERTY name;
};
""") | )
for t1, t2 in ["SV", "TV", "VT", "VS"]:
with self.annotate(tables=(t1, t2)):
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute(f | test_edgeql_ddl_constraint_check_09 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_check_10(self):
# Test a half-delegated twice inherited constraint pattern
await self.con.execute(r"""
CREATE ABSTRACT TYPE R {
CREATE REQUIRED PROPERTY name -> std::str {
CREATE DELEGATED CONSTRAINT std::exclusive;
};
};
CREATE TYPE S EXTENDING R;
CREATE TYPE T {
CREATE REQUIRED PROPERTY name -> std::str {
CREATE CONSTRAINT std::exclusive;
};
};
CREATE TYPE V EXTENDING S, T;
INSERT S { name := "S" };
INSERT T { name := "T" };
INSERT V { name := "V" };
""")
for t1, t2 in ["SV", "TV", "VT", "VS"]:
with self.annotate(tables=(t1, t2)):
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute(f"""
insert {t1} {{ name := "{t2}" }}
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute(f"""
select {{
(insert {t1} {{ name := "!" }}),
(insert {t2} {{ name := "!" }}),
}}
""") | )
for t1, t2 in ["SV", "TV", "VT", "VS"]:
with self.annotate(tables=(t1, t2)):
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r'violates exclusivity constraint'):
await self.con.execute(f | test_edgeql_ddl_constraint_check_10 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_alter_01(self):
await self.con.execute(r"""
CREATE TYPE ConTest01 {
CREATE PROPERTY con_test -> int64;
};
ALTER TYPE ConTest01
ALTER PROPERTY con_test
CREATE CONSTRAINT min_value(0);
""")
await self.con.execute("""
ALTER TYPE ConTest01
ALTER PROPERTY con_test
DROP CONSTRAINT min_value(0);
""")
await self.assert_query_result("""
WITH MODULE schema
SELECT ObjectType {
name,
properties: {
name,
constraints: { name }
} FILTER .name = 'con_test'
}
FILTER .name = 'default::ConTest01';
""", [
{
'name': 'default::ConTest01',
'properties': [{
'name': 'con_test',
'constraints': [],
}]
}
]) | )
await self.con.execute( | test_edgeql_ddl_constraint_alter_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_alter_02(self):
# Create constraint, then add and drop annotation for it. This
# is similar to `test_edgeql_ddl_annotation_06`.
await self.con.execute(r'''
CREATE SCALAR TYPE contest2_t EXTENDING int64 {
CREATE CONSTRAINT expression ON (__subject__ > 0);
};
''')
await self.con.execute(r'''
ALTER SCALAR TYPE contest2_t {
ALTER CONSTRAINT expression ON (__subject__ > 0) {
CREATE ANNOTATION title := 'my constraint 2'
}
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ScalarType {
constraints: {
subjectexpr,
annotations: {
name,
@value,
}
}
}
FILTER
.name = 'default::contest2_t';
''',
[{
"constraints": [{
"subjectexpr": "(__subject__ > 0)",
"annotations": [{
"name": "std::title",
"@value": "my constraint 2",
}]
}]
}]
)
await self.con.execute(r'''
ALTER SCALAR TYPE contest2_t {
ALTER CONSTRAINT expression ON (__subject__ > 0) {
DROP ANNOTATION title;
}
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ScalarType {
constraints: {
subjectexpr,
annotations: {
name,
@value,
}
}
}
FILTER
.name = 'default::contest2_t';
''',
[{
"constraints": [{
"subjectexpr": "(__subject__ > 0)",
"annotations": []
}]
}]
) | )
await self.con.execute(r | test_edgeql_ddl_constraint_alter_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_alter_03(self):
# Create constraint annotation using DDL, then drop annotation
# using SDL. This is similar to `test_edgeql_ddl_annotation_07`.
await self.con.execute(r'''
CREATE SCALAR TYPE contest3_t EXTENDING int64 {
CREATE CONSTRAINT expression ON (__subject__ > 0) {
CREATE ANNOTATION title := 'my constraint 3';
}
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ScalarType {
constraints: {
subjectexpr,
annotations: {
name,
@value,
}
}
}
FILTER
.name = 'default::contest3_t';
''',
[{
"constraints": [{
"subjectexpr": "(__subject__ > 0)",
"annotations": [{
"name": "std::title",
"@value": "my constraint 3",
}]
}]
}]
)
await self.migrate(r'''
scalar type contest3_t extending int64 {
constraint expression on (__subject__ > 0);
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ScalarType {
constraints: {
subjectexpr,
annotations: {
name,
@value,
}
}
}
FILTER
.name = 'default::contest3_t';
''',
[{
"constraints": [{
"subjectexpr": "(__subject__ > 0)",
"annotations": []
}]
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_constraint_alter_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_alter_04(self):
# Create constraints using DDL, then add annotation to it
# using SDL. This tests how "on expr" is handled. This is
# similar to `test_edgeql_ddl_annotation_08`.
await self.con.execute(r'''
CREATE SCALAR TYPE contest4_t EXTENDING int64 {
CREATE CONSTRAINT expression ON (__subject__ > 0);
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ScalarType {
constraints: {
subjectexpr,
annotations: {
name,
@value,
}
}
}
FILTER
.name = 'default::contest4_t';
''',
[{
"constraints": [{
"subjectexpr": "(__subject__ > 0)",
"annotations": []
}]
}]
)
await self.migrate(r'''
scalar type contest4_t extending int64 {
constraint expression on (__subject__ > 0) {
annotation title := 'my constraint 5';
}
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ScalarType {
constraints: {
subjectexpr,
annotations: {
name,
@value,
}
}
}
FILTER
.name = 'default::contest4_t';
''',
[{
"constraints": [{
"subjectexpr": "(__subject__ > 0)",
"annotations": [{
"name": "std::title",
"@value": "my constraint 5",
}]
}]
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_constraint_alter_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_alter_05(self):
await self.con.execute(r"""
CREATE TYPE Base {
CREATE PROPERTY firstname -> str {
CREATE CONSTRAINT max_len_value(10);
}
}
""")
with self.assertRaisesRegex(
edgedb.errors.SchemaError,
r"constraint 'std::max_len_value' of property 'firstname' "
r"of object type 'default::Base' already exists"):
await self.con.execute(r"""
ALTER TYPE Base {
ALTER PROPERTY firstname {
CREATE CONSTRAINT max_len_value(10);
}
}
""") | )
with self.assertRaisesRegex(
edgedb.errors.SchemaError,
r"constraint 'std::max_len_value' of property 'firstname' "
r"of object type 'default::Base' already exists"):
await self.con.execute(r | test_edgeql_ddl_constraint_alter_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_alter_06(self):
await self.con.execute(r"""
create type Foo {
create property foo -> str {create constraint exclusive;};
};
create type Bar extending Foo;
""")
async with self.assertRaisesRegexTx(
edgedb.errors.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute(r"""
insert Bar { foo := "x" }; insert Foo { foo := "x" };
""")
async with self.assertRaisesRegexTx(
edgedb.errors.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute(r"""
insert Foo { foo := "x" }; insert Bar { foo := "x" };
""") | )
async with self.assertRaisesRegexTx(
edgedb.errors.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute(r | test_edgeql_ddl_constraint_alter_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_alter_07(self):
await self.con.execute(r"""
create type Foo {
create property foo -> str;
};
create type Bar extending Foo;
alter type Foo alter property foo {
create constraint exclusive
};
""")
async with self.assertRaisesRegexTx(
edgedb.errors.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute(r"""
insert Bar { foo := "x" }; insert Foo { foo := "x" };
""")
async with self.assertRaisesRegexTx(
edgedb.errors.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute(r"""
insert Foo { foo := "x" }; insert Bar { foo := "x" };
""") | )
async with self.assertRaisesRegexTx(
edgedb.errors.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute(r | test_edgeql_ddl_constraint_alter_07 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_constraint_alter_08(self):
await self.con.execute(r"""
create type Foo {
create property foo -> str {create constraint exclusive;};
};
create type Bar {
create property foo -> str {create constraint exclusive;};
};
alter type Bar extending Foo;
""")
async with self.assertRaisesRegexTx(
edgedb.errors.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute(r"""
insert Bar { foo := "x" }; insert Foo { foo := "x" };
""")
async with self.assertRaisesRegexTx(
edgedb.errors.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute(r"""
insert Foo { foo := "x" }; insert Bar { foo := "x" };
""") | )
async with self.assertRaisesRegexTx(
edgedb.errors.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute(r | test_edgeql_ddl_constraint_alter_08 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_drop_inherited_link(self):
await self.con.execute(r"""
CREATE TYPE Target;
CREATE TYPE Parent {
CREATE LINK dil_foo -> Target;
};
CREATE TYPE Child EXTENDING Parent;
CREATE TYPE GrandChild EXTENDING Child;
""")
await self.con.execute("""
ALTER TYPE Parent DROP LINK dil_foo;
""") | )
await self.con.execute( | test_edgeql_ddl_drop_inherited_link | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_drop_01(self):
# Check that constraints defined on scalars being dropped are
# dropped.
await self.con.execute("""
CREATE SCALAR TYPE a1 EXTENDING std::str;
ALTER SCALAR TYPE a1 {
CREATE CONSTRAINT std::one_of('a', 'b') {
CREATE ANNOTATION description :=
'test_delta_drop_01_constraint';
};
};
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT Constraint {name}
FILTER any(
.annotations.name = 'std::description'
AND .annotations@value = 'test_delta_drop_01_constraint'
)
""",
[
{
'name': 'std::one_of',
}
],
)
await self.con.execute("""
DROP SCALAR TYPE a1;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT Constraint {name}
FILTER any(
.annotations.name = 'std::description'
AND .annotations@value = 'test_delta_drop_01_constraint'
)
""",
[]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_drop_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_drop_02(self):
# Check that links defined on types being dropped are
# dropped.
await self.con.execute("""
CREATE TYPE C1 {
CREATE PROPERTY l1 -> std::str {
CREATE ANNOTATION description := 'test_delta_drop_02_link';
};
};
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT Property {name}
FILTER any(
.annotations.name = 'std::description'
AND .annotations@value = 'test_delta_drop_02_link'
)
""",
[
{
'name': 'l1',
}
],
)
await self.con.execute("""
DROP TYPE C1;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT Property {name}
FILTER any(
.annotations.name = 'std::description'
AND .annotations@value = 'test_delta_drop_02_link'
)
""",
[]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_drop_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_drop_03(self):
await self.con.execute("""
CREATE TYPE Foo {
CREATE REQUIRED SINGLE PROPERTY name -> std::str;
};
""")
await self.con.execute("""
CREATE TYPE Bar {
CREATE OPTIONAL SINGLE LINK lol -> Foo {
CREATE PROPERTY note -> str;
};
};
""")
await self.con.execute("""
DROP TYPE Bar;
""") | )
await self.con.execute( | test_edgeql_ddl_drop_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_drop_refuse_02(self):
await self.con.execute(
'''
create type Player;
create global current_player_id: uuid;
create global current_player := (
select Player filter .id = global current_player_id
);
create type Clan;
alter type Player {
create link clan: Clan;
};
alter type Clan {
create access policy allow_select_players
allow select using (
global current_player.clan.id ?= .id
);
};
'''
)
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"cannot drop .+ because this affects expression of access"):
await self.con.execute('drop type Player;') | create type Player;
create global current_player_id: uuid;
create global current_player := (
select Player filter .id = global current_player_id
);
create type Clan;
alter type Player {
create link clan: Clan;
};
alter type Clan {
create access policy allow_select_players
allow select using (
global current_player.clan.id ?= .id
);
}; | test_edgeql_ddl_drop_refuse_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_unicode_01(self):
await self.con.execute(r"""
# setup delta
START MIGRATION TO {
module default {
type Пример {
required property номер -> int16;
};
};
};
POPULATE MIGRATION;
COMMIT MIGRATION;
INSERT Пример {
номер := 987
};
INSERT Пример {
номер := 456
};
""")
await self.assert_query_result(
r"""
SELECT
Пример {
номер
}
ORDER BY
Пример.номер;
""",
[{'номер': 456}, {'номер': 987}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_unicode_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_tuple_properties(self):
await self.con.execute(r"""
CREATE TYPE TupProp01 {
CREATE PROPERTY p1 -> tuple<int64, str>;
CREATE PROPERTY p2 -> tuple<foo: int64, bar: str>;
CREATE PROPERTY p3 -> tuple<foo: int64,
bar: tuple<json, json>>;
};
CREATE TYPE TupProp02 {
CREATE PROPERTY p1 -> tuple<int64, str>;
CREATE PROPERTY p2 -> tuple<json, json>;
};
""")
# Drop identical p1 properties from both objects,
# to check positive refcount.
await self.con.execute(r"""
ALTER TYPE TupProp01 {
DROP PROPERTY p1;
};
""")
await self.con.execute(r"""
ALTER TYPE TupProp02 {
DROP PROPERTY p1;
};
""")
# Re-create the property to check that the associated
# composite type was actually removed.
await self.con.execute(r"""
ALTER TYPE TupProp02 {
CREATE PROPERTY p1 -> tuple<int64, str>;
};
""")
# Now, drop the property that has a nested tuple that
# is referred to directly by another property.
await self.con.execute(r"""
ALTER TYPE TupProp01 {
DROP PROPERTY p3;
};
""")
# Drop the last user.
await self.con.execute(r"""
ALTER TYPE TupProp02 {
DROP PROPERTY p2;
};
""")
# Re-create to assure cleanup.
await self.con.execute(r"""
ALTER TYPE TupProp02 {
CREATE PROPERTY p3 -> tuple<json, json>;
CREATE PROPERTY p4 -> tuple<a: json, b: json>;
};
""")
await self.con.execute(r"""
ALTER TYPE TupProp02 {
CREATE PROPERTY p5 -> array<tuple<int64>>;
};
""")
await self.con.query('DECLARE SAVEPOINT t0')
with self.assertRaisesRegex(
edgedb.InvalidPropertyTargetError,
'expected a scalar type, or a scalar collection'):
await self.con.execute(r"""
ALTER TYPE TupProp02 {
CREATE PROPERTY p6 -> tuple<TupProp02>;
};
""")
# Recover.
await self.con.query('ROLLBACK TO SAVEPOINT t0;') | )
# Drop identical p1 properties from both objects,
# to check positive refcount.
await self.con.execute(r | test_edgeql_ddl_tuple_properties | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_enum_01(self):
await self.con.execute('''
CREATE SCALAR TYPE my_enum EXTENDING enum<'foo', 'bar'>;
''')
await self.assert_query_result(
r"""
SELECT schema::ScalarType {
enum_values,
}
FILTER .name = 'default::my_enum';
""",
[{
'enum_values': ['foo', 'bar'],
}],
)
await self.con.execute('''
CREATE TYPE EnumHost {
CREATE PROPERTY foo -> my_enum;
}
''')
await self.con.query('DECLARE SAVEPOINT t0')
with self.assertRaisesRegex(
edgedb.SchemaError,
'enumeration must be the only supertype specified'):
await self.con.execute('''
CREATE SCALAR TYPE my_enum_2
EXTENDING enum<'foo', 'bar'>,
std::int32;
''')
await self.con.query('ROLLBACK TO SAVEPOINT t0;')
await self.con.execute('''
CREATE SCALAR TYPE my_enum_2
EXTENDING enum<'foo', 'bar'>;
''')
await self.con.query('DECLARE SAVEPOINT t1')
with self.assertRaisesRegex(
edgedb.UnsupportedFeatureError,
'constraints cannot be defined on enumerated type.*'):
await self.con.execute('''
CREATE SCALAR TYPE my_enum_3
EXTENDING enum<'foo', 'bar', 'baz'> {
CREATE CONSTRAINT expression ON (EXISTS(__subject__))
};
''')
# Recover.
await self.con.query('ROLLBACK TO SAVEPOINT t1;')
await self.con.execute('''
ALTER SCALAR TYPE my_enum_2
RENAME TO my_enum_3;
''')
await self.con.execute('''
CREATE MODULE foo;
ALTER SCALAR TYPE my_enum_3
RENAME TO foo::my_enum_4;
''')
await self.con.execute('''
DROP SCALAR TYPE foo::my_enum_4;
''') | )
await self.assert_query_result(
r | test_edgeql_ddl_enum_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_enum_02(self):
await self.con.execute('''
CREATE SCALAR TYPE my_enum EXTENDING enum<'foo', 'bar'>;
''')
await self.con.execute('''
CREATE TYPE Obj {
CREATE PROPERTY e -> my_enum {
SET default := <my_enum>'foo';
}
}
''')
await self.con.execute('''
CREATE MODULE foo;
ALTER SCALAR TYPE my_enum
RENAME TO foo::my_enum_2;
''')
await self.con.execute('''
DROP TYPE Obj;
DROP SCALAR TYPE foo::my_enum_2;
''') | )
await self.con.execute( | test_edgeql_ddl_enum_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_enum_05(self):
await self.con.execute('''
CREATE SCALAR TYPE Color
EXTENDING enum<Red, Green, Blue>;
CREATE FUNCTION asdf(x: Color) -> str USING (
<str>(x));
CREATE FUNCTION asdf2() -> str USING (
asdf(<Color>'Red'));
CREATE FUNCTION asdf3(x: tuple<Color>) -> str USING (
<str>(x.0));
CREATE TYPE Entry {
CREATE PROPERTY num -> int64;
CREATE PROPERTY color -> Color;
CREATE PROPERTY colors -> array<Color>;
CREATE PROPERTY colorst -> array<tuple<Color>>;
CREATE CONSTRAINT expression ON (
<str>.num != asdf2()
);
CREATE INDEX ON (asdf(.color));
CREATE PROPERTY lol -> str {
SET default := asdf2();
}
};
INSERT Entry { num := 1, color := "Red" };
INSERT Entry {
num := 2, color := "Green", colors := ["Red", "Green"],
colorst := [("Red",), ("Green",)]
};
''')
await self.con.execute('''
ALTER SCALAR TYPE Color
EXTENDING enum<Red, Green>;
''')
await self.con.execute('''
ALTER SCALAR TYPE Color
EXTENDING enum<Green, Red>;
''')
await self.assert_query_result(
r"""
SELECT Entry { num, color, colorst } ORDER BY .color;
""",
[
{
'num': 2,
'color': 'Green',
'colorst': [("Red",), ("Green",)],
},
{'num': 1, 'color': 'Red'},
],
)
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
'invalid input value for enum'):
await self.con.execute('''
ALTER SCALAR TYPE Color
EXTENDING enum<Green>;
''') | )
await self.con.execute( | test_edgeql_ddl_enum_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_explicit_id(self):
await self.con.execute('''
CREATE TYPE ExID {
SET id := <uuid>'00000000-0000-0000-0000-0000feedbeef'
};
''')
await self.assert_query_result(
r"""
SELECT schema::ObjectType {
id
}
FILTER .name = 'default::ExID';
""",
[{
'id': '00000000-0000-0000-0000-0000feedbeef',
}],
)
with self.assertRaisesRegex(
edgedb.SchemaDefinitionError,
'cannot alter object id'):
await self.con.execute('''
ALTER TYPE ExID {
SET id := <uuid>'00000000-0000-0000-0000-0000feedbeef'
}
''') | )
await self.assert_query_result(
r | test_edgeql_ddl_explicit_id | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_quoting_01(self):
await self.con.execute("""
CREATE TYPE `U S``E R` {
CREATE PROPERTY `n ame` -> str;
};
""")
await self.con.execute("""
INSERT `U S``E R` {
`n ame` := 'quoting_01'
};
""")
await self.assert_query_result(
r"""
SELECT `U S``E R` {
__type__: {
name
},
`n ame`
};
""",
[{
'__type__': {'name': 'default::U S`E R'},
'n ame': 'quoting_01'
}],
)
await self.con.execute("""
DROP TYPE `U S``E R`;
""") | )
await self.con.execute( | test_edgeql_ddl_quoting_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_prop_overload_05(self):
await self.con.execute("""
CREATE TYPE UniqueName {
CREATE PROPERTY val -> str;
};
CREATE TYPE UniqueName_2 {
CREATE PROPERTY val -> str;
};
CREATE TYPE UniqueName_3 EXTENDING UniqueName, UniqueName_2;
""")
with self.assertRaisesRegex(
edgedb.SchemaDefinitionError,
"it is illegal for the property 'val' of object "
"type 'default::UniqueName_3' to extend both a computed "
"and a non-computed property"):
await self.con.execute("""
ALTER TYPE UniqueName {
ALTER PROPERTY val {
USING ('bad');
};
};
""") | )
with self.assertRaisesRegex(
edgedb.SchemaDefinitionError,
"it is illegal for the property 'val' of object "
"type 'default::UniqueName_3' to extend both a computed "
"and a non-computed property"):
await self.con.execute( | test_edgeql_ddl_prop_overload_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_prop_overload_06(self):
await self.con.execute("""
CREATE TYPE UniqueName {
CREATE PROPERTY val -> str;
};
CREATE TYPE UniqueName_2 {
CREATE PROPERTY val -> str;
};
CREATE TYPE UniqueName_3 {
CREATE PROPERTY val := 'ok';
};
CREATE TYPE UniqueName_4 EXTENDING UniqueName, UniqueName_2;
""")
with self.assertRaisesRegex(
edgedb.SchemaDefinitionError,
"it is illegal for the property 'val' of object "
"type 'default::UniqueName_4' to extend both a computed "
"and a non-computed property"):
await self.con.execute("""
ALTER TYPE UniqueName_4 EXTENDING UniqueName_3;
""") | )
with self.assertRaisesRegex(
edgedb.SchemaDefinitionError,
"it is illegal for the property 'val' of object "
"type 'default::UniqueName_4' to extend both a computed "
"and a non-computed property"):
await self.con.execute( | test_edgeql_ddl_prop_overload_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.