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_prop_overload_07(self): await self.con.execute(""" CREATE TYPE UniqueName { CREATE PROPERTY val -> str; }; CREATE TYPE UniqueName_2 { CREATE PROPERTY val := 'ok'; }; CREATE TYPE UniqueName_3; CREATE TYPE UniqueName_4 EXTENDING UniqueName, 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(""" ALTER TYPE UniqueName_3 EXTENDING 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(
test_edgeql_ddl_prop_overload_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_link_overload_01(self): await self.con.execute(""" CREATE TYPE T; CREATE TYPE A { CREATE MULTI LINK t -> T; }; CREATE TYPE B EXTENDING A; INSERT T; INSERT B { t := T }; ALTER TYPE B ALTER LINK t CREATE ANNOTATION title := 'overloaded'; UPDATE B SET { t := T }; """) await self.assert_query_result( r""" SELECT A { ct := count(.t) }; """, [{ 'ct': 1, }] )
) await self.assert_query_result( r
test_edgeql_ddl_link_overload_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_readonly_04(self): # Test that read-only flag must be consistent in the # inheritance hierarchy. await self.con.execute(''' CREATE TYPE Base0 { CREATE PROPERTY foo -> str; }; CREATE TYPE Base1 { CREATE PROPERTY foo -> str; }; CREATE TYPE Derived EXTENDING Base0, Base1; ''') with self.assertRaisesRegex( edgedb.SchemaDefinitionError, "cannot redefine the readonly flag of property 'foo' of " "object type 'default::Derived': it is defined as False in " "property 'foo' of object type 'default::Base0' and as " "True in property 'foo' of object type 'default::Base1'."): await self.con.execute(''' ALTER TYPE Base1 { ALTER PROPERTY foo { SET readonly := True; }; }; ''')
) with self.assertRaisesRegex( edgedb.SchemaDefinitionError, "cannot redefine the readonly flag of property 'foo' of " "object type 'default::Derived': it is defined as False in " "property 'foo' of object type 'default::Base0' and as " "True in property 'foo' of object type 'default::Base1'."): await self.con.execute(
test_edgeql_ddl_readonly_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_readonly_08(self): # Test that read-only flag must be consistent in the # inheritance hierarchy. await self.con.execute(''' CREATE TYPE Base0 { CREATE LINK foo -> Object; }; CREATE TYPE Base1 { CREATE LINK foo -> Object; }; CREATE TYPE Derived EXTENDING Base0, Base1; ''') with self.assertRaisesRegex( edgedb.SchemaDefinitionError, "cannot redefine the readonly flag of link 'foo' of " "object type 'default::Derived': it is defined as False in " "link 'foo' of object type 'default::Base0' and as " "True in link 'foo' of object type 'default::Base1'."): await self.con.execute(''' ALTER TYPE Base1 { ALTER LINK foo { SET readonly := True; }; }; ''')
) with self.assertRaisesRegex( edgedb.SchemaDefinitionError, "cannot redefine the readonly flag of link 'foo' of " "object type 'default::Derived': it is defined as False in " "link 'foo' of object type 'default::Base0' and as " "True in link 'foo' of object type 'default::Base1'."): await self.con.execute(
test_edgeql_ddl_readonly_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_readonly_12(self): # Test that read-only flag must be consistent in the # inheritance hierarchy. await self.con.execute(''' CREATE TYPE Base0 { CREATE LINK foo -> Object { CREATE PROPERTY bar -> str; }; }; CREATE TYPE Base1 { CREATE LINK foo -> Object { CREATE PROPERTY bar -> str; }; }; CREATE TYPE Derived EXTENDING Base0, Base1; ''') with self.assertRaisesRegex( edgedb.SchemaDefinitionError, "cannot redefine the readonly flag of property 'bar' of " "link 'foo' of object type 'default::Derived': it is defined " "as False in property 'bar' of link 'foo' of object type " "'default::Base0' and as True in property 'bar' of link " "'foo' of object type 'default::Base1'."): await self.con.execute(''' ALTER TYPE Base1 { ALTER LINK foo { ALTER PROPERTY bar { SET readonly := True; }; }; }; ''')
) with self.assertRaisesRegex( edgedb.SchemaDefinitionError, "cannot redefine the readonly flag of property 'bar' of " "link 'foo' of object type 'default::Derived': it is defined " "as False in property 'bar' of link 'foo' of object type " "'default::Base0' and as True in property 'bar' of link " "'foo' of object type 'default::Base1'."): await self.con.execute(
test_edgeql_ddl_readonly_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_required_08(self): # Test normal that required qualifier behavior. await self.con.execute(r""" CREATE TYPE Base { CREATE REQUIRED PROPERTY foo -> str; }; CREATE TYPE Derived EXTENDING Base { ALTER PROPERTY foo { # overloading the property to be required # regardless of the ancestors SET REQUIRED; }; }; """) with self.assertRaisesRegex( edgedb.MissingRequiredError, f"missing value for required property" r" 'foo' of object type 'default::Base'", ): async with self.con.transaction(): await self.con.execute(""" INSERT Base; """) with self.assertRaisesRegex( edgedb.MissingRequiredError, f"missing value for required property" r" 'foo' of object type 'default::Derived'", ): async with self.con.transaction(): await self.con.execute(""" INSERT Derived; """) await self.con.execute(""" ALTER TYPE Base { ALTER PROPERTY foo { SET OPTIONAL; }; }; """) await self.con.execute(""" INSERT Base; """) await self.assert_query_result( r''' SELECT count(Base); ''', [1], ) with self.assertRaisesRegex( edgedb.MissingRequiredError, f"missing value for required property" r" 'foo' of object type 'default::Derived'", ): async with self.con.transaction(): await self.con.execute(""" INSERT Derived; """) await self.con.execute(""" ALTER TYPE Derived { ALTER PROPERTY foo { SET OPTIONAL; }; }; """) await self.con.execute(""" INSERT Derived; """) await self.assert_query_result( r''' SELECT count(Derived); ''', [1], )
) with self.assertRaisesRegex( edgedb.MissingRequiredError, f"missing value for required property" r" 'foo' of object type 'default::Base'", ): async with self.con.transaction(): await self.con.execute(
test_edgeql_ddl_required_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_required_09(self): # Test normal that required qualifier behavior. await self.con.execute(r""" CREATE TYPE Base { CREATE OPTIONAL PROPERTY foo -> str; }; CREATE TYPE Derived EXTENDING Base { ALTER PROPERTY foo { # overloading the property to be required # regardless of the ancestors SET REQUIRED; }; }; """) with self.assertRaisesRegex( edgedb.MissingRequiredError, f"missing value for required property" r" 'foo' of object type 'default::Derived'", ): async with self.con.transaction(): await self.con.execute(""" INSERT Derived; """) await self.con.execute(""" INSERT Base; """) await self.assert_query_result( r''' SELECT count(Base); ''', [1], ) with self.assertRaisesRegex( edgedb.MissingRequiredError, f"missing value for required property" r" 'foo' of object type 'default::Derived'", ): async with self.con.transaction(): await self.con.execute(""" INSERT Derived; """) await self.con.execute(""" ALTER TYPE Derived { ALTER PROPERTY foo { SET OPTIONAL; }; }; """) await self.con.execute(""" INSERT Derived; """) await self.assert_query_result( r''' SELECT count(Derived); ''', [1], )
) with self.assertRaisesRegex( edgedb.MissingRequiredError, f"missing value for required property" r" 'foo' of object type 'default::Derived'", ): async with self.con.transaction(): await self.con.execute(
test_edgeql_ddl_required_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_required_10(self): # Test normal that required qualifier behavior. await self.con.execute(r""" CREATE TYPE Base { CREATE REQUIRED MULTI PROPERTY name -> str; }; """) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, r"missing value for required property 'name'" r" of object type 'default::Base'", ): async with self.con.transaction(): await self.con.execute(""" INSERT Base; """) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, r"missing value for required property 'name'" r" of object type 'default::Base'", ): async with self.con.transaction(): await self.con.execute(""" INSERT Base {name := {}}; """) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, r"missing value for required property 'name'" r" of object type 'default::Base'", ): async with self.con.transaction(): await self.con.execute(""" WITH names := {'A', 'B'} INSERT Base { name := (SELECT names FILTER names = 'C'), }; """)
) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, r"missing value for required property 'name'" r" of object type 'default::Base'", ): async with self.con.transaction(): await self.con.execute(
test_edgeql_ddl_required_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_required_11(self): # Test normal that required qualifier behavior. await self.con.execute(r""" CREATE TYPE Child; CREATE TYPE Base { CREATE REQUIRED MULTI LINK children -> Child; }; """) with self.assertRaisesRegex( edgedb.MissingRequiredError, r"missing value for required link 'children'" r" of object type 'default::Base'" ): async with self.con.transaction(): await self.con.execute(""" INSERT Base; """) with self.assertRaisesRegex( edgedb.MissingRequiredError, r"missing value for required link 'children'" r" of object type 'default::Base'" ): async with self.con.transaction(): await self.con.execute(""" INSERT Base {children := {}}; """) with self.assertRaisesRegex( edgedb.MissingRequiredError, r"missing value for required link 'children'" r" of object type 'default::Base'" ): async with self.con.transaction(): await self.con.execute(""" INSERT Base { children := (SELECT Child FILTER false) }; """)
) with self.assertRaisesRegex( edgedb.MissingRequiredError, r"missing value for required link 'children'" r" of object type 'default::Base'" ): async with self.con.transaction(): await self.con.execute(
test_edgeql_ddl_required_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_index_06(self): # Unfortunately we don't really have a way to test that this # actually works, but I looked at the SQL DDL. await self.con.execute(r""" create type Foo { create property name -> str; create property exclude -> bool; create index on (.name) except (.exclude); }; """) # But we can at least make sure it made it into the schema await self.assert_query_result( ''' SELECT schema::ObjectType { indexes: {expr, except_expr} } FILTER .name = 'default::Foo' ''', [{"indexes": [{"except_expr": ".exclude", "expr": ".name"}]}] )
) # But we can at least make sure it made it into the schema await self.assert_query_result(
test_edgeql_ddl_index_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_abstract_index_01(self): for _ in range(2): await self.con.execute(''' create abstract index test( named only lists: int64 ) { set code := ' ((__col__) NULLS FIRST)'; }; ''') await self.con.execute(''' drop abstract index test; ''')
) await self.con.execute(
test_edgeql_ddl_abstract_index_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_deferred_index_06(self): await self.con.execute(''' create abstract index test() { set code := ' ((__col__) NULLS FIRST)'; set deferrability := 'Permitted'; }; create type Foo { create property bar -> str; create deferred index test on (.bar); }; ''') await self.assert_query_result( ''' SELECT schema::ObjectType { name, indexes: { deferred, deferrability, } } FILTER .name = 'default::Foo' ''', [{ 'name': 'default::Foo', 'indexes': [{ 'deferred': True, 'deferrability': 'Permitted', }] }] )
) await self.assert_query_result(
test_edgeql_ddl_deferred_index_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_errors_01(self): await self.con.execute(''' CREATE TYPE Err1 { CREATE REQUIRED PROPERTY foo -> str; }; ALTER TYPE Err1 CREATE REQUIRED LINK bar -> Err1; ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "property 'b' does not exist"): await self.con.execute(''' ALTER TYPE Err1 ALTER PROPERTY b CREATE CONSTRAINT std::regexp(r'b'); ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "property 'b' does not exist"): await self.con.execute(''' ALTER TYPE Err1 DROP PROPERTY b ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "constraint 'default::a' does not exist"): await self.con.execute(''' ALTER TYPE Err1 ALTER PROPERTY foo DROP CONSTRAINT a; ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "constraint 'default::a' does not exist"): await self.con.execute(''' ALTER TYPE Err1 ALTER PROPERTY foo ALTER CONSTRAINT a ON (foo > 0) { CREATE ANNOTATION title := 'test' } ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "annotation 'std::title' does not exist"): await self.con.execute(''' ALTER TYPE Err1 ALTER PROPERTY foo ALTER ANNOTATION title := 'aaa' ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "annotation 'std::title' does not exist"): await self.con.execute(''' ALTER TYPE Err1 ALTER PROPERTY foo DROP ANNOTATION title; ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "annotation 'std::title' does not exist"): await self.con.execute(''' ALTER TYPE Err1 ALTER ANNOTATION title := 'aaa' ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "annotation 'std::title' does not exist"): await self.con.execute(''' ALTER TYPE Err1 DROP ANNOTATION title ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, r"index on \(.foo\) does not exist on" r" object type 'default::Err1'", ): await self.con.execute(''' ALTER TYPE Err1 DROP INDEX ON (.foo) ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, r"index on \(.zz\) does not exist on object type " r"'default::Err1'", ): await self.con.execute(''' ALTER TYPE Err1 DROP INDEX ON (.zz) ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "object type 'default::Err1' has no link or " "property 'zz'"): await self.con.execute(''' ALTER TYPE Err1 CREATE INDEX ON (.zz) ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "object type 'default::Err1' has no link or " "property 'zz'"): await self.con.execute(''' ALTER TYPE Err1 CREATE INDEX ON ((.foo, .zz)) ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "object type 'default::blah' does not exist"): await self.con.execute(''' CREATE TYPE Err1 EXTENDING blah { CREATE PROPERTY foo -> str; }; ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "object type 'default::blah' does not exist"): await self.con.execute(''' CREATE TYPE Err2 EXTENDING blah { CREATE PROPERTY foo -> str; }; ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "link 'b' does not exist"): await self.con.execute(''' ALTER TYPE Err1 ALTER LINK b CREATE CONSTRAINT std::regexp(r'b'); ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "link 'b' does not exist"): await self.con.execute(''' ALTER TYPE Err1 DROP LINK b; ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "annotation 'std::title' does not exist"): await self.con.execute(''' ALTER TYPE Err1 ALTER LINK bar DROP ANNOTATION title; ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "constraint 'std::min_value' does not exist"): await self.con.execute(''' ALTER TYPE Err1 ALTER LINK bar DROP CONSTRAINT min_value(0); ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "property 'spam' does not exist"): await self.con.execute(''' ALTER TYPE Err1 ALTER LINK bar DROP PROPERTY spam; ''')
) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "property 'b' does not exist"): await self.con.execute(
test_edgeql_ddl_errors_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_errors_02(self): await self.con.execute(''' CREATE TYPE Err2 { CREATE REQUIRED PROPERTY foo -> str; }; ALTER TYPE Err2 CREATE REQUIRED LINK bar -> Err2; ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "link 'foo' does not exist"): await self.con.execute(''' ALTER TYPE Err2 ALTER LINK foo DROP PROPERTY spam; ''')
) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "link 'foo' does not exist"): await self.con.execute(
test_edgeql_ddl_errors_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_errors_03(self): async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "function 'default::foo___1' does not exist"): await self.con.execute(''' ALTER FUNCTION foo___1(a: int64) SET volatility := 'Stable'; ''') async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "function 'default::foo___1' does not exist"): await self.con.execute(''' DROP FUNCTION foo___1(a: int64); ''')
) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.errors.InvalidReferenceError, "function 'default::foo___1' does not exist"): await self.con.execute(
test_edgeql_ddl_errors_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_migration_sdl_01(self): await self.con.execute(''' CONFIGURE SESSION SET store_migration_sdl := cfg::StoreMigrationSDL.AlwaysStore; ''') await self.con.execute(''' create type A; create type B { create property n -> int64; }; alter type A { create link b -> B; }; alter type A { alter link b { create property n -> int64 }; }; alter type A { alter link b { drop property n; }; }; alter type B { drop property n; }; ''') await self.con.execute(''' drop type A; ''') migrations = TestEdgeQLDDL.order_migrations( json.loads(await self.con.query_json(''' select schema::Migration { id, parents: { id }, sdl } ''')) ) sdl = [migration['sdl'] for migration in migrations] self.assert_data_shape( sdl, [ ( 'module default {\n' ' type A;\n' '};' ), ( 'module default {\n' ' type A;\n' ' type B {\n' ' property n: std::int64;\n' ' };\n' '};' ), ( 'module default {\n' ' type A {\n' ' link b: default::B;\n' ' };\n' ' type B {\n' ' property n: std::int64;\n' ' };\n' '};' ), ( 'module default {\n' ' type A {\n' ' link b: default::B {\n' ' property n: std::int64;\n' ' };\n' ' };\n' ' type B {\n' ' property n: std::int64;\n' ' };\n' '};' ), ( 'module default {\n' ' type A {\n' ' link b: default::B;\n' ' };\n' ' type B {\n' ' property n: std::int64;\n' ' };\n' '};' ), ( 'module default {\n' ' type A {\n' ' link b: default::B;\n' ' };\n' ' type B;\n' '};' ), ( 'module default {\n' ' type B;\n' '};' ), ] )
) await self.con.execute(
test_edgeql_ddl_migration_sdl_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_create_migration_01(self): await self.con.execute(''' CONFIGURE SESSION SET store_migration_sdl := cfg::StoreMigrationSDL.AlwaysStore; ''') await self.con.execute(f''' CREATE MIGRATION {{ CREATE TYPE Type1 {{ CREATE PROPERTY field1 -> str; }}; }}; ''') await self.assert_query_result( ''' SELECT schema::ObjectType { name } FILTER .name = 'default::Type1' ''', [{ 'name': 'default::Type1', }] ) migrations = TestEdgeQLDDL.order_migrations( json.loads(await self.con.query_json(''' select schema::Migration { id, parents: { id }, script, sdl } ''')) ) self.assert_data_shape( migrations, [ { 'script': ( 'CREATE TYPE Type1 {\n' ' CREATE PROPERTY field1 -> str;\n' '};' ), 'sdl': ( 'module default {\n' ' type Type1 {\n' ' property field1: std::str;\n' ' };' '\n};' ), }, ] )
) await self.con.execute(f
test_edgeql_ddl_create_migration_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_create_migration_02(self): await self.con.execute(''' CONFIGURE SESSION SET store_migration_sdl := cfg::StoreMigrationSDL.AlwaysStore; ''') await self.con.execute(''' CREATE MIGRATION m1kmv2mcizpj2twxlxxerkgngr2fkto7wnjd6uig3aa3x67dykvspq ONTO initial { CREATE GLOBAL default::foo -> std::bool; CREATE TYPE default::Foo { CREATE ACCESS POLICY foo ALLOW ALL USING ((GLOBAL default::foo ?? true)); }; }; ''') await self.con.execute(''' CREATE MIGRATION m14i24uhm6przo3bpl2lqndphuomfrtq3qdjaqdg6fza7h6m7tlbra ONTO m1kmv2mcizpj2twxlxxerkgngr2fkto7wnjd6uig3aa3x67dykvspq { CREATE TYPE default::X; INSERT Foo; }; ''') migrations = TestEdgeQLDDL.order_migrations( json.loads(await self.con.query_json(''' select schema::Migration { id, parents: { id }, script, sdl } ''')) ) self.assert_data_shape( migrations, [ { 'script': ( 'CREATE GLOBAL default::foo -> std::bool;\n' 'CREATE TYPE default::Foo {\n' ' CREATE ACCESS POLICY foo\n' ' ALLOW ALL USING (' '(GLOBAL default::foo ?? true)' ');\n' '};' ), 'sdl': ( 'module default {\n' ' global foo -> std::bool;\n' ' type Foo {\n' ' access policy foo\n' ' allow all using ' '((global default::foo ?? true));\n' ' };\n' '};' ), }, { 'script': ( 'CREATE TYPE default::X;\n' '\n' 'INSERT Foo;' ), 'sdl': ( 'module default {\n' ' global foo -> std::bool;\n' ' type Foo {\n' ' access policy foo\n' ' allow all using ' '((global default::foo ?? true));\n' ' };\n' ' type X;\n' '};' ), }, ] )
) await self.con.execute(
test_edgeql_ddl_create_migration_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_create_migration_03(self): await self.con.execute(''' CONFIGURE SESSION SET store_migration_sdl := cfg::StoreMigrationSDL.AlwaysStore; ''') await self.con.execute(''' CREATE MIGRATION { SET message := "migration2"; SET generated_by := schema::MigrationGeneratedBy.DevMode; CREATE TYPE Type2 { CREATE PROPERTY field2 -> int32; }; }; ''') migrations = TestEdgeQLDDL.order_migrations( json.loads(await self.con.query_json(''' select schema::Migration { id, parents: { id }, message, generated_by, script, sdl, } ''')) ) self.assert_data_shape( migrations, [ { 'generated_by': 'DevMode', 'message': 'migration2', 'script': ( 'SET message := "migration2";\n' 'SET generated_by := ' 'schema::MigrationGeneratedBy.DevMode;\n' 'CREATE TYPE Type2 {\n' ' CREATE PROPERTY field2 -> int32;\n' '};' ), 'sdl': ( 'module default {\n' ' type Type2 {\n' ' property field2: std::int32;\n' ' };\n' '};' ), }, ] ) await self.con.execute(f''' CREATE TYPE Type3 ''') migrations = TestEdgeQLDDL.order_migrations( json.loads(await self.con.query_json(''' select schema::Migration { id, parents: { id }, message, generated_by, script, sdl, } ''')) ) self.assert_data_shape( migrations, [ { 'generated_by': 'DevMode', 'message': 'migration2', 'script': ( 'SET message := "migration2";\n' 'SET generated_by := ' 'schema::MigrationGeneratedBy.DevMode;\n' 'CREATE TYPE Type2 {\n' ' CREATE PROPERTY field2 -> int32;\n' '};' ), 'sdl': ( 'module default {\n' ' type Type2 {\n' ' property field2: std::int32;\n' ' };\n' '};' ), }, { 'generated_by': 'DDLStatement', 'message': None, 'script': ( 'SET generated_by := ' '(schema::MigrationGeneratedBy.DDLStatement);\n' 'CREATE TYPE Type3;' ), 'sdl': ( 'module default {\n' ' type Type2 {\n' ' property field2: std::int32;\n' ' };\n' ' type Type3;\n' '};' ), }, ] )
) await self.con.execute(
test_edgeql_ddl_create_migration_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_create_migration_04(self): await self.con.execute(''' CREATE MIGRATION { create global foo -> str; create type Foo; }; ''') await self.con.execute(''' insert Foo; ''') # Currently, SET GLOBAL is not allowed in migration scripts. # Once we make it allowed, we will need to make it actually # work, and there is a commented bit below to test that. async with self.assertRaisesRegexTx( edgedb.QueryError, "Unexpected keyword 'GLOBAL'"): await self.con.execute(''' CREATE MIGRATION { set global foo := "test"; alter type Foo { create required property name -> str { set default := (global foo); } }; ''')
) await self.con.execute(
test_edgeql_ddl_create_migration_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_create_migration_05(self): await self.con.execute(''' create type X { create property x -> str; }; ''') async with self.assertRaisesRegexTx( edgedb.InvalidReferenceError, "property 'x' does not"): await self.con.execute(''' CREATE MIGRATION { alter type default::X { alter property x rename to y; }; alter type default::X { alter property x create constraint exclusive; }; }; ''')
) async with self.assertRaisesRegexTx( edgedb.InvalidReferenceError, "property 'x' does not"): await self.con.execute(
test_edgeql_ddl_create_migration_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_naked_backlink_in_computable(self): await self.con.execute(''' CREATE TYPE User { CREATE PROPERTY name -> str { CREATE CONSTRAINT exclusive; }; }; CREATE TYPE Post { CREATE LINK author -> User; }; CREATE TYPE Video { CREATE LINK author -> User; }; ALTER TYPE User { CREATE MULTI LINK authored := .<author; }; INSERT User { name := 'Lars' }; INSERT Post { author := (SELECT User FILTER .name = 'Lars') }; INSERT Video { author := (SELECT User FILTER .name = 'Lars') }; ''') await self.assert_query_result( ''' WITH User := (SELECT schema::ObjectType FILTER .name = 'default::User') SELECT User.pointers { target: { name } } FILTER .name = 'authored' ''', [{ 'target': { 'name': 'std::BaseObject', } }] ) await self.assert_query_result( ''' SELECT _ := User.authored.__type__.name ORDER BY _ ''', ['default::Post', 'default::Video'] )
) await self.assert_query_result(
test_edgeql_ddl_naked_backlink_in_computable
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_change_module_04(self): await self.con.execute(""" CREATE MODULE foo; CREATE TYPE Tag; CREATE TYPE Note { CREATE SINGLE LINK tags -> Tag { ON TARGET DELETE DELETE SOURCE; } }; INSERT Note { tags := (INSERT Tag) }; """) await self.con.execute(""" ALTER TYPE Tag RENAME TO foo::Tag; DELETE foo::Tag FILTER true; """) await self.assert_query_result( """SELECT Note;""", [], ) await self.con.execute(""" ALTER TYPE Note RENAME TO foo::Note; DROP TYPE foo::Note; DROP TYPE foo::Tag; """)
) await self.con.execute(
test_edgeql_ddl_change_module_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_rewrite_and_trigger_01(self): await self.con.execute(""" create type Entry { create property x := 0; create property y -> int64 { create rewrite insert, update using (.x); }; }; create type Foo { create trigger log0 after insert for each do (insert Entry); }; create type Bar { create trigger log1 after insert for each do (insert Foo); }; """) await self.con.execute(f""" alter type Entry alter property x using (1) """) await self.con.execute(f""" alter type Entry alter property y drop rewrite insert, update; """) await self.con.execute(f""" alter type Foo drop trigger log0; """)
) await self.con.execute(f
test_edgeql_ddl_rewrite_and_trigger_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 _simple_rename_ref_test( self, ddl, cleanup=None, *, rename_type, rename_prop, rename_module, type_extra=0, prop_extra=0, type_refs=1, prop_refs=1, ): """Driver for simple rename tests for objects with expr references. Supports renaming a type, a property, or both. By default, each is expected to be named once in the referencing object. """ await self.con.execute(f""" CREATE TYPE Note {{ CREATE PROPERTY note -> str; }}; {ddl.lstrip()} """) type_rename = "RENAME TO Remark;" if rename_type else "" prop_rename = ( "ALTER PROPERTY note RENAME TO remark;" if rename_prop else "") await self.con.execute(f""" ALTER TYPE Note {{ {type_rename.lstrip()} {prop_rename.lstrip()} }} """) if rename_module: await self.con.execute(f""" CREATE MODULE foo; ALTER TYPE Note RENAME TO foo::Note; """) else: res = await self.con.query_single(""" DESCRIBE MODULE default """) total_type = 1 + type_refs num_type_orig = 0 if rename_type else total_type self.assertEqual(res.count("Note"), num_type_orig + type_extra) self.assertEqual(res.count("Remark"), total_type - num_type_orig) total_prop = 1 + prop_refs num_prop_orig = 0 if rename_prop else total_prop self.assertEqual(res.count("note"), num_prop_orig + type_extra) self.assertEqual(res.count("remark"), total_prop - num_prop_orig) if cleanup: if rename_prop: cleanup = cleanup.replace("note", "remark") if rename_type: cleanup = cleanup.replace("Note", "Remark") if rename_module: cleanup = cleanup.replace("default", "foo") await self.con.execute(f""" {cleanup.lstrip()} """)
Driver for simple rename tests for objects with expr references. Supports renaming a type, a property, or both. By default, each is expected to be named once in the referencing object.
_simple_rename_ref_test
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 _simple_rename_ref_tests(self, ddl, cleanup=None, **kwargs): """Do the three interesting invocations of _simple_rename_ref_test""" async with self._run_and_rollback(): await self._simple_rename_ref_test( ddl, cleanup, rename_type=False, rename_prop=True, rename_module=False, **kwargs) async with self._run_and_rollback(): await self._simple_rename_ref_test( ddl, cleanup, rename_type=True, rename_prop=False, rename_module=False, **kwargs) async with self._run_and_rollback(): await self._simple_rename_ref_test( ddl, cleanup, rename_type=True, rename_prop=True, rename_module=False, **kwargs) async with self._run_and_rollback(): await self._simple_rename_ref_test( ddl, cleanup, rename_type=False, rename_prop=False, rename_module=True, **kwargs)
Do the three interesting invocations of _simple_rename_ref_test
_simple_rename_ref_tests
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_ref_function_02(self): # Test renaming two types that appear as function arguments at # the same time. await self.con.execute(""" CREATE TYPE Note { CREATE PROPERTY note -> str; }; CREATE TYPE Name { CREATE PROPERTY name -> str; }; CREATE FUNCTION foo(x: Note, y: Name) -> OPTIONAL str { USING (SELECT (x.note ++ " " ++ y.name)) }; """) await self.con.execute(""" INSERT Note { note := "hello" } """) await self.con.execute(""" INSERT Name { name := "world" } """) await self.con.execute(""" CREATE MIGRATION { ALTER TYPE Note RENAME TO Remark; ALTER TYPE Name RENAME TO Handle; } """) res = await self.con.query_single(""" DESCRIBE MODULE default """) self.assertEqual(res.count("Note"), 0) self.assertEqual(res.count("Name"), 0) self.assertEqual(res.count("Remark"), 2) self.assertEqual(res.count("Handle"), 2) await self.assert_query_result( ''' SELECT foo(Remark, Handle); ''', ['hello world'], ) await self.con.execute(""" DROP FUNCTION foo(x: Remark, y: Handle); """)
) await self.con.execute(
test_edgeql_ddl_rename_ref_function_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_ref_constraint_01(self): await self.con.execute(""" CREATE TYPE Note { CREATE PROPERTY name -> str; CREATE PROPERTY note -> str; CREATE CONSTRAINT exclusive ON ( (__subject__.name, __subject__.note)); }; """) await self.con.execute(""" ALTER TYPE Note { ALTER PROPERTY note { RENAME TO remark; }; ALTER PROPERTY name { RENAME TO callsign; }; } """) res = await self.con.query_single(""" DESCRIBE MODULE default """) self.assertEqual(res.count("note"), 0) self.assertEqual(res.count("remark"), 2) self.assertEqual(res.count("name"), 0) self.assertEqual(res.count("callsign"), 2) await self.con.execute(""" ALTER TYPE Note DROP CONSTRAINT exclusive ON (( (__subject__.callsign, __subject__.remark))); """)
) await self.con.execute(
test_edgeql_ddl_rename_ref_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_rename_ref_rewrites_01(self): await self._simple_rename_ref_tests( """ alter type Note create property rtest -> str { create rewrite update using (.note); }; """, """ alter type default::Note drop property rtest; """, type_refs=0, )
alter type Note create property rtest -> str { create rewrite update using (.note); }; """,
test_edgeql_ddl_rename_ref_rewrites_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_ref_triggers_01(self): await self._simple_rename_ref_tests( """ alter type Note { create trigger log_new after insert, update for each do (__new__.note); }; """, """ alter type default::Note drop trigger log_new; """, type_refs=0, )
alter type Note { create trigger log_new after insert, update for each do (__new__.note); }; """,
test_edgeql_ddl_rename_ref_triggers_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_ref_prop_alias_01(self): await self._simple_rename_ref_tests( """ alter type Note { create property lol := (.note); }; """, """ alter type default::Note drop property lol; """, type_refs=0, )
alter type Note { create property lol := (.note); }; """,
test_edgeql_ddl_rename_ref_prop_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_drop_multi_prop_01(self): await self.con.execute(r""" CREATE TYPE Test { CREATE MULTI PROPERTY x -> str; CREATE MULTI PROPERTY y := {1, 2, 3}; }; """) await self.con.execute(r""" ALTER TYPE Test DROP PROPERTY x; """) await self.con.execute(r""" ALTER TYPE Test DROP PROPERTY y; """) await self.con.execute(r""" INSERT Test; DELETE Test; """)
) await self.con.execute(r
test_edgeql_ddl_drop_multi_prop_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_collection_cleanup_01(self): count_query = "SELECT count(schema::Tuple);" orig_count = await self.con.query_single(count_query) await self.con.execute(r""" CREATE SCALAR TYPE a extending str; CREATE SCALAR TYPE b extending str; CREATE SCALAR TYPE c extending str; CREATE TYPE TestTuples { CREATE PROPERTY x -> tuple<a>; CREATE PROPERTY y -> tuple<b>; }; """) self.assertEqual( await self.con.query_single(count_query), orig_count + 2, ) await self.con.execute(r""" ALTER TYPE TestTuples { DROP PROPERTY x; }; """) self.assertEqual( await self.con.query_single(count_query), orig_count + 1, ) await self.con.execute(r""" ALTER TYPE TestTuples { ALTER PROPERTY y { SET TYPE tuple<c> USING ( <tuple<c>><tuple<str>>.y); } }; """) self.assertEqual( await self.con.query_single(count_query), orig_count + 1, ) await self.con.execute(r""" DROP TYPE TestTuples; """) self.assertEqual(await self.con.query_single(count_query), orig_count)
) self.assertEqual( await self.con.query_single(count_query), orig_count + 2, ) await self.con.execute(r
test_edgeql_ddl_collection_cleanup_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_collection_cleanup_01b(self): count_query = "SELECT count(schema::Tuple);" orig_count = await self.con.query_single(count_query) await self.con.execute(r""" CREATE SCALAR TYPE a extending str; CREATE SCALAR TYPE b extending str; CREATE SCALAR TYPE c extending str; CREATE TYPE TestTuples { CREATE PROPERTY x -> tuple<a>; CREATE PROPERTY y -> tuple<b>; CREATE PROPERTY z -> tuple<b>; }; """) self.assertEqual( await self.con.query_single(count_query), orig_count + 2, ) await self.con.execute(r""" ALTER TYPE TestTuples { DROP PROPERTY x; }; """) self.assertEqual( await self.con.query_single(count_query), orig_count + 1, ) await self.con.execute(r""" ALTER TYPE TestTuples { ALTER PROPERTY y { SET TYPE tuple<c> USING ( <tuple<c>><tuple<str>>.y); } }; """) self.assertEqual( await self.con.query_single(count_query), orig_count + 2, ) await self.con.execute(r""" DROP TYPE TestTuples; """) self.assertEqual(await self.con.query_single(count_query), orig_count)
) self.assertEqual( await self.con.query_single(count_query), orig_count + 2, ) await self.con.execute(r
test_edgeql_ddl_collection_cleanup_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_collection_cleanup_02(self): count_query = "SELECT count(schema::CollectionType);" orig_count = await self.con.query_single(count_query) await self.con.execute(r""" CREATE SCALAR TYPE a extending str; CREATE SCALAR TYPE b extending str; CREATE SCALAR TYPE c extending str; CREATE TYPE TestArrays { CREATE PROPERTY x -> array<tuple<a, b>>; }; """) self.assertEqual( await self.con.query_single(count_query), orig_count + 3 + 2, ) await self.con.execute(r""" DROP TYPE TestArrays; """) self.assertEqual( await self.con.query_single(count_query), orig_count + 3, )
) self.assertEqual( await self.con.query_single(count_query), orig_count + 3 + 2, ) await self.con.execute(r
test_edgeql_ddl_collection_cleanup_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_collection_cleanup_03(self): count_query = "SELECT count(schema::CollectionType);" orig_count = await self.con.query_single(count_query) elem_count_query = "SELECT count(schema::TupleElement);" orig_elem_count = await self.con.query_single(elem_count_query) await self.con.execute(r""" CREATE SCALAR TYPE a extending str; CREATE SCALAR TYPE b extending str; CREATE SCALAR TYPE c extending str; CREATE FUNCTION foo(x: array<a>, z: tuple<b, c>, y: array<tuple<b, c>>) -> array<b> USING (SELECT [<b>""]); """) self.assertEqual( await self.con.query_single(count_query), orig_count + 3 + 2, ) await self.con.execute(r""" DROP FUNCTION foo( x: array<a>, z: tuple<b, c>, y: array<tuple<b, c>>); """) self.assertEqual( await self.con.query_single(count_query), orig_count + 3, ) self.assertEqual( await self.con.query_single(elem_count_query), orig_elem_count, )
) self.assertEqual( await self.con.query_single(count_query), orig_count + 3 + 2, ) await self.con.execute(r
test_edgeql_ddl_collection_cleanup_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_collection_cleanup_04(self): count_query = "SELECT count(schema::CollectionType);" orig_count = await self.con.query_single(count_query) await self.con.execute(r""" CREATE SCALAR TYPE a extending str; CREATE SCALAR TYPE b extending str; CREATE SCALAR TYPE c extending str; CREATE TYPE Foo { CREATE PROPERTY a -> a; CREATE PROPERTY b -> b; CREATE PROPERTY c -> c; }; CREATE ALIAS Bar := Foo { thing := (.a, .b) }; """) self.assertEqual( await self.con.query_single(count_query), orig_count + 3 + 1, ) await self.con.execute(r""" ALTER ALIAS Bar USING (Foo { thing := (.a, .b, .c) }); """) self.assertEqual( await self.con.query_single(count_query), orig_count + 3 + 1, ) await self.con.execute(r""" ALTER ALIAS Bar USING (Foo { thing := (.a, (.b, .c)) }); """) self.assertEqual( await self.con.query_single(count_query), orig_count + 3 + 2, ) await self.con.execute(r""" ALTER ALIAS Bar USING (Foo { thing := ((.a, .b), .c) }); """) self.assertEqual( await self.con.query_single(count_query), orig_count + 3 + 2, ) await self.con.execute(r""" ALTER ALIAS Bar USING (Foo { thing := ((.a, .b), .c, "foo") }); """) self.assertEqual( await self.con.query_single(count_query), orig_count + 3 + 2, ) # Make a change that doesn't change the types await self.con.execute(r""" ALTER ALIAS Bar USING (Foo { thing := ((.a, .b), .c, "bar") }); """) self.assertEqual( await self.con.query_single(count_query), orig_count + 3 + 2, ) await self.con.execute(r""" DROP ALIAS Bar; """) self.assertEqual( await self.con.query_single(count_query), orig_count + 3, )
) self.assertEqual( await self.con.query_single(count_query), orig_count + 3 + 1, ) await self.con.execute(r
test_edgeql_ddl_collection_cleanup_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_collection_cleanup_05(self): count_query = "SELECT count(schema::CollectionType);" orig_count = await self.con.query_single(count_query) await self.con.execute(r""" CREATE SCALAR TYPE a extending str; CREATE SCALAR TYPE b extending str; CREATE ALIAS Bar := (<a>"", <b>""); """) self.assertEqual( await self.con.query_single(count_query), orig_count + 2 + 2, # one for tuple<str, str> # one for TupleExprAlias, # two for implicit array<a> and array<b> ) await self.con.execute(r""" ALTER ALIAS Bar USING ((<b>"", <a>"")); """) self.assertEqual( await self.con.query_single(count_query), orig_count + 2 + 2, ) await self.con.execute(r""" DROP ALIAS Bar; """) self.assertEqual( await self.con.query_single(count_query), orig_count + 2, )
) self.assertEqual( await self.con.query_single(count_query), orig_count + 2 + 2, # one for tuple<str, str> # one for TupleExprAlias, # two for implicit array<a> and array<b> ) await self.con.execute(r
test_edgeql_ddl_collection_cleanup_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_drop_field_01(self): await self.con.execute(r""" CREATE FUNCTION foo() -> str USING ("test"); CREATE TYPE Foo { CREATE REQUIRED PROPERTY a -> str { SET default := foo(); } }; """) await self.con.execute(r""" INSERT Foo; """) await self.con.execute(r""" ALTER TYPE Foo { ALTER PROPERTY a { RESET default; } }; """) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, r"missing value for required property" r" 'a' of object type 'default::Foo'", ): await self.con.execute(r""" INSERT Foo; """) await self.con.execute(r""" DROP FUNCTION foo(); """)
) await self.con.execute(r
test_edgeql_ddl_drop_field_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_field_02(self): await self.con.execute(r""" CREATE TYPE Foo { CREATE REQUIRED PROPERTY a -> str { CREATE CONSTRAINT exclusive { SET errmessage := "whoops"; } } }; """) await self.con.execute(r""" INSERT Foo { a := "x" }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'whoops', ): await self.con.execute(r""" INSERT Foo { a := "x" }; """) await self.con.execute(r""" ALTER TYPE Foo { ALTER PROPERTY a { ALTER CONSTRAINT exclusive { RESET errmessage; } } }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'a violates exclusivity constraint', ): await self.con.execute(r""" INSERT Foo { a := "x" }; """)
) await self.con.execute(r
test_edgeql_ddl_drop_field_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_field_03(self): await self.con.execute(r""" CREATE ABSTRACT CONSTRAINT bogus { USING (false); SET errmessage := "never!"; }; CREATE TYPE Foo { CREATE CONSTRAINT bogus on (true); }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'never!', ): await self.con.execute(r""" INSERT Foo; """) await self.con.execute(r""" ALTER ABSTRACT CONSTRAINT bogus RESET errmessage; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'invalid Foo', ): await self.con.execute(r""" INSERT Foo; """)
) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'never!', ): await self.con.execute(r
test_edgeql_ddl_drop_field_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_adjust_computed_01(self): await self.con.execute(r""" CREATE TYPE Foo { CREATE PROPERTY foo := {1, 2, 3}; }; """) await self.con.execute(r""" ALTER TYPE Foo { ALTER PROPERTY foo SET MULTI; }; """) await self.con.execute(r""" ALTER TYPE Foo { ALTER PROPERTY foo RESET CARDINALITY; }; """)
) await self.con.execute(r
test_edgeql_ddl_adjust_computed_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_adjust_computed_02(self): await self.con.execute(r""" CREATE TYPE Foo { CREATE PROPERTY foo := 1; }; """) await self.con.execute(r""" INSERT Foo; """) await self.assert_query_result( "SELECT Foo { foo }", [{"foo": 1}], ) await self.con.execute(r""" ALTER TYPE Foo { ALTER PROPERTY foo SET MULTI; }; """) await self.assert_query_result( "SELECT Foo { foo }", [{"foo": [1]}], ) await self.con.execute(r""" ALTER TYPE Foo { ALTER PROPERTY foo RESET CARDINALITY; }; """) await self.assert_query_result( "SELECT Foo { foo }", [{"foo": 1}], )
) await self.con.execute(r
test_edgeql_ddl_adjust_computed_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_adjust_computed_03(self): await self.con.execute(r""" CREATE TYPE Foo { CREATE PROPERTY foo := 1; }; """) await self.assert_query_result( r""" SELECT schema::Pointer { required, has_required := contains(.computed_fields, "required") } FILTER .name = "foo" """, [{"required": True, "has_required": True}] ) await self.con.execute(r""" ALTER TYPE Foo { ALTER PROPERTY foo SET OPTIONAL; }; """) await self.assert_query_result( r""" SELECT schema::Pointer { required, has_required := contains(.computed_fields, "required") } FILTER .name = "foo" """, [{"required": False, "has_required": False}] ) await self.con.execute(r""" ALTER TYPE Foo { ALTER PROPERTY foo RESET OPTIONALITY; }; """) await self.assert_query_result( r""" SELECT schema::Pointer { required, has_required := contains(.computed_fields, "required") } FILTER .name = "foo" """, [{"required": True, "has_required": True}] ) await self.con.execute(r""" ALTER TYPE Foo { ALTER PROPERTY foo SET REQUIRED; }; """) await self.assert_query_result( r""" SELECT schema::Pointer { required, has_required := contains(.computed_fields, "required") } FILTER .name = "foo" """, [{"required": True, "has_required": False}] )
) await self.assert_query_result( r
test_edgeql_ddl_adjust_computed_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_adjust_computed_04(self): await self.con.execute(r''' CREATE TYPE Foo { CREATE REQUIRED PROPERTY bar -> str; }; ''') await self.con.execute(r''' ALTER TYPE Foo { ALTER PROPERTY bar { USING ("1") } }; ''') # Should work await self.con.execute(r''' INSERT Foo; ''') async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, r"missing value for required property"): # Should fail because there is missing data # TODO: ask for fill_expr? await self.con.execute(r''' ALTER TYPE Foo { ALTER PROPERTY bar RESET EXPRESSION }; ''') # Delete the data, then try await self.con.execute(r''' DELETE Foo; ALTER TYPE Foo { ALTER PROPERTY bar RESET EXPRESSION }; ''') async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, r"missing value for required property"): await self.con.execute(r''' INSERT Foo; ''')
) await self.con.execute(r
test_edgeql_ddl_adjust_computed_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_adjust_computed_05(self): await self.con.execute(r''' CREATE TYPE Tgt; CREATE TYPE Foo { CREATE REQUIRED LINK bar -> Tgt; }; CREATE TYPE Bar EXTENDING Foo; ''') await self.con.execute(r''' ALTER TYPE Foo { ALTER LINK bar { USING (assert_exists((SELECT Tgt LIMIT 1))) } }; ''') # Should work await self.con.execute(r''' INSERT Foo; ''') async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, r"missing value for required link"): # Should fail because there is missing data await self.con.execute(r''' ALTER TYPE Foo { ALTER LINK bar RESET EXPRESSION }; ''') # Delete the data, then try await self.con.execute(r''' DELETE Foo; ALTER TYPE Foo { ALTER LINK bar RESET EXPRESSION }; ''') async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, r"missing value for required link"): await self.con.execute(r''' INSERT Foo; ''')
) await self.con.execute(r
test_edgeql_ddl_adjust_computed_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_adjust_computed_06(self): await self.con.execute(r''' CREATE TYPE Tgt; CREATE TYPE Foo { CREATE REQUIRED MULTI LINK bar -> Tgt; }; CREATE TYPE Bar EXTENDING Foo; ''') await self.con.execute(r''' ALTER TYPE Foo { ALTER LINK bar { USING (assert_exists((SELECT Tgt))) } }; ''') # Should work await self.con.execute(r''' INSERT Foo; ''') async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, r"missing value for required link"): # Should fail because there is missing data await self.con.execute(r''' ALTER TYPE Foo { ALTER LINK bar RESET EXPRESSION }; ''') # Delete the data, then try await self.con.execute(r''' DELETE Foo; ALTER TYPE Foo { ALTER LINK bar RESET EXPRESSION }; ''') async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, r"missing value for required link"): await self.con.execute(r''' INSERT Foo; ''')
) await self.con.execute(r
test_edgeql_ddl_adjust_computed_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_adjust_computed_07(self): # Switching a property to computed and back should lose its data await self.con.execute(r''' CREATE TYPE Foo { CREATE PROPERTY bar -> str; }; CREATE TYPE Bar EXTENDING Foo; INSERT Foo { bar := "hello" }; ALTER TYPE Foo { ALTER PROPERTY bar { USING ("world") } }; ALTER TYPE Foo { ALTER PROPERTY bar RESET expression }; ''') await self.assert_query_result( r""" SELECT Foo { bar } """, [ {'bar': None} ] )
) await self.assert_query_result( r
test_edgeql_ddl_adjust_computed_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_adjust_computed_08(self): # Switching a property to computed and back should lose its data await self.con.execute(r''' CREATE TYPE Foo { CREATE MULTI PROPERTY bar -> str; }; CREATE TYPE Bar EXTENDING Foo; INSERT Foo { bar := {"foo", "bar"} }; ALTER TYPE Foo { ALTER PROPERTY bar { USING ({"a", "b"}) } }; ALTER TYPE Foo { ALTER PROPERTY bar RESET expression }; ''') await self.assert_query_result( r""" SELECT Foo { bar } """, [ {'bar': []} ] )
) await self.assert_query_result( r
test_edgeql_ddl_adjust_computed_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_adjust_computed_09(self): # Switching a link to computed and back should lose its data await self.con.execute(r''' CREATE TYPE Tgt; CREATE TYPE Foo { CREATE MULTI LINK bar -> Tgt; }; CREATE TYPE Bar EXTENDING Foo; INSERT Foo { bar := (INSERT Tgt) }; ALTER TYPE Foo { ALTER LINK bar { USING (Tgt) } }; ALTER TYPE Foo { ALTER LINK bar RESET expression }; ''') await self.assert_query_result( r""" SELECT Foo { bar } """, [ {'bar': []} ] )
) await self.assert_query_result( r
test_edgeql_ddl_adjust_computed_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_adjust_computed_10(self): # Make sure everything gets cleaned up in this transition await self.con.execute(r''' CREATE TYPE Foo { CREATE MULTI PROPERTY bar -> str; }; CREATE TYPE Bar EXTENDING Foo; INSERT Foo { bar := {"foo", "bar"} }; ALTER TYPE Foo { ALTER PROPERTY bar { USING ({"a", "b"}) } }; ''') await self.assert_query_result( r""" DELETE Foo """, [ {} ] )
) await self.assert_query_result( r
test_edgeql_ddl_adjust_computed_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_adjust_computed_11(self): await self.con.execute(r''' CREATE TYPE default::Foo; CREATE TYPE default::Bar { CREATE LINK foos := (default::Foo); }; ''') # it's annoying that we need the using on the RESET CARDINALITY; # maybe we should be able to know it isn't needed await self.con.execute(r''' ALTER TYPE default::Bar { ALTER LINK foos { RESET EXPRESSION; RESET CARDINALITY using (<Foo>{}); RESET OPTIONALITY; SET TYPE default::Foo; }; } ''')
) # it's annoying that we need the using on the RESET CARDINALITY; # maybe we should be able to know it isn't needed await self.con.execute(r
test_edgeql_ddl_adjust_computed_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_adjust_computed_12(self): # GH Issue #6459 await self.con.execute(r''' CREATE TYPE default::Foo { CREATE PROPERTY foo := 'hello'; }; ALTER TYPE default::Foo { ALTER PROPERTY foo { RESET EXPRESSION; RESET OPTIONALITY; SET TYPE std::str; } }; ''') await self.con.execute(r''' START MIGRATION TO { TYPE default::Foo { PROPERTY foo: std::str; }; ALIAS default::FooAlias := default::Foo; }; POPULATE MIGRATION; COMMIT MIGRATION; ''')
) await self.con.execute(r
test_edgeql_ddl_adjust_computed_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_adjust_computed_13(self): await self.con.execute(r''' create type X { create property bar -> int64 { create constraint std::exclusive } }; ''') await self.con.execute(r''' alter type X alter property bar using ('1'); ''')
) await self.con.execute(r
test_edgeql_ddl_adjust_computed_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_adjust_computed_14(self): await self.con.execute(r''' create type X { create property bar -> int64; create constraint std::exclusive on (.bar); }; ''') await self.con.execute(r''' alter type X alter property bar using ('1'); ''')
) await self.con.execute(r
test_edgeql_ddl_adjust_computed_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_adjust_computed_15(self): await self.con.execute(r''' create type Away { create property x -> str; create property y { using (.x ++ "!"); create constraint exclusive; } }; create type Away2 extending Away; ''') await self.con.execute(r''' alter type Away alter property y reset expression; ''') await self.con.execute(""" insert Away { x := '1', y := '1' } """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, '', ): await self.con.execute(""" insert Away { x := '2', y := '1' } """)
) await self.con.execute(r
test_edgeql_ddl_adjust_computed_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_adjust_computed_16(self): # this is caused by the annoying thing where pointers that are # a simple alias like this just inherit from the other point. await self.con.execute(r''' create type Away { create property x -> str; create property y { using (.x); create constraint exclusive; } }; create type Away2 extending Away; ''') await self.con.execute(r''' alter type Away alter property y reset expression; ''') await self.con.execute(""" insert Away { x := '2', y := '1' } """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, '', ): await self.con.execute(""" insert Away { x := '1', y := '1' } """)
) await self.con.execute(r
test_edgeql_ddl_adjust_computed_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_captured_as_migration_01(self): await self.con.execute(r""" CREATE TYPE Foo { CREATE PROPERTY foo := 1; }; """) await self.assert_query_result( r""" WITH MODULE schema, LM := ( SELECT Migration FILTER NOT EXISTS(.<parents[IS Migration]) ) SELECT LM { script } """, [{ 'script': textwrap.dedent( '''\ SET generated_by := (schema::MigrationGeneratedBy.\ DDLStatement); CREATE TYPE Foo { CREATE PROPERTY foo := (1); };''' ) }] )
) await self.assert_query_result( r
test_edgeql_ddl_captured_as_migration_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_link_policy_01(self): await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Foo { CREATE MULTI LINK tgt -> Tgt; }; CREATE TYPE Bar EXTENDING Foo; """) await self.con.execute(r""" INSERT Bar { tgt := (INSERT Tgt) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'prohibited by link target policy', ): await self.con.execute(""" DELETE Tgt; """)
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_02(self): await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Base { CREATE MULTI LINK tgt -> Tgt; }; CREATE TYPE Foo; ALTER TYPE Foo EXTENDING Base; """) await self.con.execute(r""" INSERT Foo { tgt := (INSERT Tgt) }; """) await self.con.execute(r""" DELETE Foo; """) await self.con.execute(r""" DELETE Tgt; """)
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_03(self): await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Base; CREATE TYPE Foo EXTENDING Base { CREATE MULTI LINK tgt -> Tgt; }; ALTER TYPE Base CREATE MULTI LINK foo -> Tgt; """) await self.con.execute(r""" INSERT Foo { tgt := (INSERT Tgt) }; """) async with self._run_and_rollback(): await self.con.execute(""" WITH D := Foo, SELECT {(DELETE D.tgt), (DELETE D)}; """) await self.con.execute(r""" WITH D := Foo, SELECT {(DELETE D), (DELETE D.tgt)}; """)
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_04(self): # Make sure that a newly created subtype gets the appropriate # target link policies await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Foo { CREATE MULTI LINK tgt -> Tgt; }; CREATE TYPE Tgt2 EXTENDING Tgt; """) await self.con.execute(r""" INSERT Foo { tgt := (INSERT Tgt2) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'prohibited by link target policy', ): await self.con.execute(""" DELETE Tgt2; """)
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_05(self): # Make sure that a subtype with newly added bases gets the appropriate # target link policies await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Foo { CREATE MULTI LINK tgt -> Tgt; }; CREATE TYPE Tgt2; ALTER TYPE Tgt2 EXTENDING Tgt; """) await self.con.execute(r""" INSERT Foo { tgt := (INSERT Tgt2) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'prohibited by link target policy', ): await self.con.execute(""" DELETE Tgt2; """) await self.con.execute(r""" DELETE Foo; ALTER TYPE Tgt2 DROP EXTENDING Tgt; DROP TYPE Foo; """) # Make sure that if we drop the base type, everything works right still await self.con.execute(""" DELETE Tgt2; """)
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_06(self): # Make sure that links coming into base types don't # interfere with link policies await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Tgt2 EXTENDING Tgt; CREATE TYPE Foo { CREATE MULTI LINK tgt -> Tgt2; }; CREATE TYPE Bar { CREATE MULTI LINK tgt -> Tgt; }; """) await self.con.execute(r""" INSERT Foo { tgt := (INSERT Tgt2) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'prohibited by link target policy', ): await self.con.execute(""" DELETE Tgt2; """)
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_07(self): # Make sure that swapping between deferred and not works await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Foo { CREATE MULTI LINK tgt -> Tgt; }; """) await self.con.execute(r""" ALTER TYPE Foo ALTER LINK tgt ON TARGET DELETE DEFERRED RESTRICT; """) await self.con.execute(r""" INSERT Foo { tgt := (INSERT Tgt) }; """) await self.con.execute(""" DELETE Tgt; DELETE Foo; """)
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_08(self): # Make sure that swapping between deferred and not works await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Foo { CREATE LINK tgt -> Tgt; }; ALTER TYPE Foo ALTER LINK tgt SET MULTI; """) await self.con.execute(r""" INSERT Foo { tgt := (INSERT Tgt) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'prohibited by link target policy', ): await self.con.execute(""" DELETE Tgt; """) await self.con.execute(""" DELETE Foo; DELETE Tgt; """)
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_09(self): # Make sure that it still works after we rebase a link await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Foo { CREATE LINK tgt -> Tgt; }; CREATE TYPE Bar EXTENDING Foo { ALTER LINK tgt SET OWNED; }; ALTER TYPE Bar DROP EXTENDING Foo; """) await self.con.execute(r""" INSERT Bar { tgt := (INSERT Tgt) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'prohibited by link target policy', ): await self.con.execute(""" DELETE Tgt; """) await self.con.execute(""" DELETE Bar; DELETE Tgt; """)
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_10(self): # Make sure we NULL out the pointer on the delete, which will # trigger the constraint await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Foo { CREATE LINK tgt -> Tgt { ON TARGET DELETE ALLOW; }; CREATE CONSTRAINT expression on (EXISTS .tgt); }; CREATE TYPE Bar EXTENDING Foo; """) await self.con.execute(r""" INSERT Bar { tgt := (INSERT Tgt) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'invalid Bar', ): await self.con.execute(""" DELETE Tgt; """) await self.con.execute(""" DELETE Bar; DELETE Tgt; """)
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_11(self): await self.con.execute(r""" CREATE TYPE Tgt { CREATE PROPERTY name -> str }; CREATE TYPE Foo { CREATE REQUIRED MULTI LINK tgt -> Tgt { ON TARGET DELETE ALLOW; }; }; CREATE TYPE Bar EXTENDING Foo; """) await self.con.execute(r""" INSERT Bar { tgt := {(INSERT Tgt { name := "foo" }), (INSERT Tgt { name := "bar" })} }; INSERT Bar { tgt := (INSERT Tgt { name := "foo" }) }; """) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, "missing value for required link 'tgt'", ): await self.con.execute(""" DELETE Tgt FILTER .name = "foo"; """) await self.con.execute(""" DELETE Tgt FILTER .name = "bar"; DELETE Bar; DELETE Tgt; """)
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_12(self): await self.con.execute(""" create type Tgt; create type Foo { create link tgt -> Tgt { on target delete allow; } }; create type Bar extending Foo { alter link tgt { on target delete restrict; } }; """) # Make sure we can still delete on Foo await self.con.execute(""" insert Foo { tgt := (insert Tgt) }; delete Tgt; """) await self.con.execute(""" insert Bar { tgt := (insert Tgt) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'prohibited by link target policy', ): await self.con.execute(""" delete Tgt; """) await self.con.execute(""" alter type Bar { alter link tgt { reset on target delete; } }; """) await self.con.execute(""" delete Tgt """) await self.assert_query_result( r""" select schema::Link {name, on_target_delete, source: {name}} filter .name = 'tgt'; """, tb.bag([ { "name": "tgt", "on_target_delete": "Allow", "source": {"name": "default::Foo"} }, { "name": "tgt", "on_target_delete": "Allow", "source": {"name": "default::Bar"} } ]), )
) # Make sure we can still delete on Foo await self.con.execute(
test_edgeql_ddl_link_policy_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_link_policy_13(self): # Make sure that swapping between delete target and not works await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Foo { CREATE LINK tgt -> Tgt; }; ALTER TYPE Foo ALTER LINK tgt ON SOURCE DELETE DELETE TARGET; """) await self.con.execute(r""" INSERT Foo { tgt := (INSERT Tgt) }; DELETE Foo; """) await self.assert_query_result( 'select Tgt', [], ) await self.con.execute(r""" ALTER TYPE Foo ALTER LINK tgt ON SOURCE DELETE ALLOW; """) await self.con.execute(r""" INSERT Foo { tgt := (INSERT Tgt) }; DELETE Foo; """) await self.assert_query_result( 'select Tgt', [{}], )
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_14(self): # Make sure that it works when changing cardinality await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Foo { CREATE LINK tgt -> Tgt { ON SOURCE DELETE DELETE TARGET; } }; ALTER TYPE Foo ALTER LINK tgt SET MULTI; """) await self.con.execute(r""" INSERT Foo { tgt := (INSERT Tgt) }; """) await self.con.execute(""" DELETE Foo; """) await self.assert_query_result( 'select Tgt', [], )
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_15(self): # Make sure that it works when changing cardinality await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Foo { CREATE LINK tgt -> Tgt { ON SOURCE DELETE DELETE TARGET; } }; CREATE TYPE Bar EXTENDING Foo; """) await self.con.execute(r""" INSERT Bar { tgt := (INSERT Tgt) }; """) await self.con.execute(""" DELETE Foo; """) await self.assert_query_result( 'select Tgt', [], )
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_16(self): # Make sure that it works when changing cardinality await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Tgt2 EXTENDING Tgt; CREATE TYPE Tgt3; CREATE TYPE Foo { CREATE MULTI LINK tgt -> Tgt | Tgt3 { ON SOURCE DELETE DELETE TARGET; } }; """) await self.con.execute(r""" INSERT Foo { tgt := {(INSERT Tgt), (INSERT Tgt2), (INSERT Tgt3)} }; """) await self.con.execute(""" DELETE Foo; """) await self.assert_query_result( 'select Tgt UNION Tgt3', [], )
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_17(self): # Make sure that ALLOW works when changing optionality await self.con.execute(r""" CREATE TYPE Tgt; CREATE TYPE Src { CREATE MULTI LINK tgt -> Tgt { ON TARGET DELETE ALLOW; } }; """) await self.con.execute(r""" INSERT Src { tgt := (INSERT Tgt) }; """) await self.con.execute(r""" ALTER TYPE Src { ALTER LINK tgt { SET REQUIRED } }; """) async with self.assertRaisesRegexTx(edgedb.MissingRequiredError, ''): await self.con.execute(""" DELETE Tgt; """) await self.con.execute(r""" ALTER TYPE Src { ALTER LINK tgt { SET OPTIONAL } }; """) await self.con.execute(""" DELETE Tgt; """)
) await self.con.execute(r
test_edgeql_ddl_link_policy_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_link_policy_implicit_01(self): await self.con.execute(""" create type T; create type X { create link foo -> schema::ObjectType; }; """) await self.con.execute(""" drop type T; """)
) await self.con.execute(
test_edgeql_ddl_link_policy_implicit_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_dupe_link_storage_01(self): await self.con.execute(r""" CREATE TYPE Foo { CREATE PROPERTY name -> str; }; CREATE TYPE Bar { CREATE PROPERTY name -> str; CREATE LINK foo -> Foo; CREATE PROPERTY x -> int64; }; CREATE TYPE Baz { CREATE PROPERTY name -> str; CREATE MULTI LINK foo -> Foo; CREATE MULTI PROPERTY x -> int64 }; INSERT Foo { name := "foo" }; INSERT Bar { name := "bar", foo := (SELECT Foo LIMIT 1), x := 1 }; INSERT Baz { name := "baz", foo := (SELECT Foo), x := {2, 3} }; """) await self.assert_query_result( r""" SELECT Foo {bars := .<foo[IS Bar] {name}}; """, [{"bars": [{"name": "bar"}]}], ) await self.assert_query_result( r""" SELECT (Bar UNION Baz).foo { name }; """, [{"name": "foo"}] ) await self.assert_query_result( r""" WITH W := (Bar UNION Baz) SELECT _ := (W { name }, W.foo) ORDER BY _.0.name; """, [ [{"name": "bar"}, {}], [{"name": "baz"}, {}] ], ) await self.con.execute(r""" WITH W := (Bar UNION Baz), SELECT (W, W.foo.id); """)
) await self.assert_query_result( r
test_edgeql_ddl_dupe_link_storage_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_scoping_future_01(self): await self.con.execute(""" configure session reset simple_scoping """) await self.con.execute(""" create type T; insert T; insert T; create function f(x: int64 = 0) -> int64 using (x); create function get_whatever() -> bool using ( all(T = T) ); create alias X := all(T = T) """) Q = """ select { func := get_whatever(), alias := X, query := all(T = T) } """ await self.assert_query_result( Q, [dict(func=True, alias=True, query=True)], ) async with self.assertRaisesRegexTx( edgedb.InvalidReferenceError, "attempting to factor", ): await self.con.execute(""" create future warn_old_scoping """) # Config flag is set but future is not: main query does not factor # but schema things do await self.con.execute(""" configure session set simple_scoping := true """) await self.assert_query_result( Q, [dict(func=True, alias=True, query=False)], ) # Future and config flag: nothing factors await self.con.execute(""" create future simple_scoping """) await self.assert_query_result( Q, [dict(func=False, alias=False, query=False)], ) # Config explicitly set to false: query factors await self.con.execute(""" configure session set simple_scoping := false """) await self.assert_query_result( Q, [dict(func=False, alias=False, query=True)], ) # Config not set: falls back to future, nothing factors await self.con.execute(""" configure session reset simple_scoping """) await self.assert_query_result( Q, [dict(func=False, alias=False, query=False)], )
) await self.con.execute(
test_edgeql_ddl_scoping_future_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_scoping_future_02(self): await self.con.execute(""" create future simple_scoping; """) await self.con.execute(""" drop future simple_scoping; """)
) await self.con.execute(
test_edgeql_ddl_scoping_future_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_no_volatile_computable_01(self): async with self.assertRaisesRegexTx( edgedb.QueryError, "volatile functions are not permitted in schema-defined " "computed expressions", ): await self.con.execute(""" CREATE TYPE Foo { CREATE PROPERTY foo := random(); } """) async with self.assertRaisesRegexTx( edgedb.QueryError, "volatile functions are not permitted in schema-defined " "computed expressions", ): await self.con.execute(""" CREATE TYPE Foo { CREATE PROPERTY foo := (SELECT { asdf := random() }).asdf } """) async with self.assertRaisesRegexTx( edgedb.QueryError, "volatile functions are not permitted in schema-defined " "computed expressions", ): await self.con.execute(""" CREATE TYPE Noob { CREATE MULTI LINK friends -> Noob; CREATE LINK best_friends := ( SELECT .friends FILTER random() > 0.5 ); } """) async with self.assertRaisesRegexTx( edgedb.QueryError, "volatile functions are not permitted in schema-defined " "computed expressions", ): await self.con.execute(""" CREATE TYPE Noob { CREATE LINK noob -> Noob { CREATE PROPERTY foo := random(); } } """) async with self.assertRaisesRegexTx( edgedb.QueryError, "volatile functions are not permitted in schema-defined " "computed expressions", ): await self.con.execute(""" CREATE ALIAS Asdf := Object { foo := random() }; """)
) async with self.assertRaisesRegexTx( edgedb.QueryError, "volatile functions are not permitted in schema-defined " "computed expressions", ): await self.con.execute(
test_edgeql_ddl_no_volatile_computable_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_new_required_pointer_01(self): await self.con.execute(r""" CREATE TYPE Foo; INSERT Foo; """) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, "missing value for required property 'name' of object type " "'default::Foo'" ): await self.con.execute(""" ALTER TYPE Foo CREATE REQUIRED PROPERTY name -> str; """)
) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, "missing value for required property 'name' of object type " "'default::Foo'" ): await self.con.execute(
test_edgeql_ddl_new_required_pointer_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_new_required_pointer_02(self): await self.con.execute(r""" CREATE TYPE Foo { CREATE PROPERTY num -> int64; }; INSERT Foo { num := 20 }; """) await self.con.execute(""" ALTER TYPE Foo { CREATE PROPERTY name -> str { SET REQUIRED USING (<str>.num ++ "!") } } """) await self.assert_query_result( r'''SELECT Foo {name, num}''', [{'name': '20!', 'num': 20}] )
) await self.con.execute(
test_edgeql_ddl_new_required_pointer_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_new_required_pointer_03(self): await self.con.execute(r""" CREATE TYPE Foo { CREATE PROPERTY num -> int64; }; INSERT Foo { num := 20 }; """) await self.con.execute(""" ALTER TYPE Foo { CREATE MULTI PROPERTY name -> str { SET REQUIRED USING (<str>.num ++ "!") } } """) await self.assert_query_result( r'''SELECT Foo {name, num}''', [{'name': ['20!'], 'num': 20}] )
) await self.con.execute(
test_edgeql_ddl_new_required_pointer_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_new_required_pointer_04(self): await self.con.execute(r""" CREATE TYPE Foo { CREATE PROPERTY num -> int64; }; CREATE TYPE Bar { CREATE PROPERTY code -> int64 { CREATE CONSTRAINT exclusive; } }; INSERT Foo { num := 20 }; INSERT Bar { code := 40 }; INSERT Foo { num := 30 }; INSERT Bar { code := 60 }; """) await self.con.execute(""" ALTER TYPE Foo { CREATE LINK partner -> Bar { SET REQUIRED USING (SELECT Bar FILTER Bar.code = 2*Foo.num) } } """) await self.assert_query_result( r'''SELECT Foo {num, partner: {code}} ORDER BY .num''', [ {'num': 20, 'partner': {'code': 40}}, {'num': 30, 'partner': {'code': 60}}, ] )
) await self.con.execute(
test_edgeql_ddl_new_required_pointer_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_new_required_pointer_05(self): await self.con.execute(r""" CREATE TYPE Foo { CREATE PROPERTY num -> int64; }; CREATE TYPE Bar { CREATE PROPERTY code -> int64 { CREATE CONSTRAINT exclusive; } }; INSERT Foo { num := 20 }; INSERT Bar { code := 40 }; INSERT Foo { num := 30 }; INSERT Bar { code := 60 }; """) await self.con.execute(""" ALTER TYPE Foo { CREATE MULTI LINK partner -> Bar { SET REQUIRED USING (SELECT Bar FILTER Bar.code = 2*Foo.num) } } """) await self.assert_query_result( r'''SELECT Foo {num, partner: {code}} ORDER BY .num''', [ {'num': 20, 'partner': [{'code': 40}]}, {'num': 30, 'partner': [{'code': 60}]}, ] )
) await self.con.execute(
test_edgeql_ddl_new_required_pointer_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_new_required_pointer_06(self): await self.con.execute(r""" CREATE ABSTRACT TYPE Bar { CREATE PROPERTY num -> int64; }; CREATE TYPE Foo EXTENDING Bar; INSERT Foo { num := 20 }; """) await self.con.execute(""" ALTER TYPE Bar { CREATE PROPERTY name -> str { SET REQUIRED USING (<str>.num ++ "!") } } """) await self.assert_query_result( r'''SELECT Foo {name, num}''', [{'name': '20!', 'num': 20}] )
) await self.con.execute(
test_edgeql_ddl_new_required_pointer_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_new_required_pointer_07(self): await self.con.execute(r""" CREATE ABSTRACT TYPE Bar { CREATE PROPERTY num -> int64; CREATE PROPERTY name -> str; }; CREATE TYPE Foo EXTENDING Bar; INSERT Foo { num := 20 }; """) await self.con.execute(""" ALTER TYPE Bar { ALTER PROPERTY name { SET REQUIRED USING (<str>.num ++ "!") } } """) await self.assert_query_result( r'''SELECT Foo {name, num}''', [{'name': '20!', 'num': 20}] )
) await self.con.execute(
test_edgeql_ddl_new_required_pointer_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_new_required_pointer_08(self): await self.con.execute(r""" CREATE TYPE Bar { CREATE PROPERTY num -> int64; CREATE PROPERTY name -> str; }; CREATE TYPE Foo EXTENDING Bar; INSERT Bar { num := 10 }; INSERT Foo { num := 20 }; """) await self.con.execute(""" ALTER TYPE Bar { ALTER PROPERTY name { SET REQUIRED USING (<str>.num ++ "!") } } """) await self.assert_query_result( r'''SELECT Bar {name, num} ORDER BY .num''', [ {'name': '10!', 'num': 10}, {'name': '20!', 'num': 20}, ] )
) await self.con.execute(
test_edgeql_ddl_new_required_pointer_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_new_required_pointer_09(self): await self.con.execute(r""" CREATE TYPE Foo; INSERT Foo; """) await self.con.execute(""" ALTER TYPE Foo { CREATE MULTI PROPERTY name -> str { SET REQUIRED USING ({"hello", "world"}) } } """) await self.assert_query_result( r'''SELECT Foo {name}''', [{'name': {'hello', 'world'}}] )
) await self.con.execute(
test_edgeql_ddl_new_required_pointer_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_new_required_multi_pointer_01(self): await self.con.execute(r""" CREATE TYPE Foo; INSERT Foo; """) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, "missing value for required property 'name' of object type " "'default::Foo'" ): await self.con.execute(""" ALTER TYPE Foo CREATE REQUIRED MULTI PROPERTY name -> str; """)
) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, "missing value for required property 'name' of object type " "'default::Foo'" ): await self.con.execute(
test_edgeql_ddl_new_required_multi_pointer_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_new_required_multi_pointer_02(self): await self.con.execute(r""" CREATE TYPE Foo; INSERT Foo; """) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, "missing value for required link 'link' of object type " "'default::Foo'" ): await self.con.execute(""" ALTER TYPE Foo CREATE REQUIRED MULTI LINK link -> Object; """)
) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, "missing value for required link 'link' of object type " "'default::Foo'" ): await self.con.execute(
test_edgeql_ddl_new_required_multi_pointer_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_new_required_multi_pointer_03(self): await self.con.execute(r""" CREATE TYPE Foo { CREATE MULTI PROPERTY name -> str; }; INSERT Foo; """) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, "missing value for required property 'name' of object type " "'default::Foo'" ): await self.con.execute(""" ALTER TYPE Foo ALTER PROPERTY name SET REQUIRED; """)
) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, "missing value for required property 'name' of object type " "'default::Foo'" ): await self.con.execute(
test_edgeql_ddl_new_required_multi_pointer_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_new_required_multi_pointer_04(self): await self.con.execute(r""" CREATE TYPE Foo { CREATE MULTI LINK link -> Object; }; INSERT Foo; """) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, "missing value for required link 'link' of object type " "'default::Foo'" ): await self.con.execute(""" ALTER TYPE Foo ALTER LINK link SET REQUIRED; """)
) async with self.assertRaisesRegexTx( edgedb.MissingRequiredError, "missing value for required link 'link' of object type " "'default::Foo'" ): await self.con.execute(
test_edgeql_ddl_new_required_multi_pointer_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_link_union_delete_01(self): await self.con.execute(r""" CREATE TYPE default::M; CREATE ABSTRACT TYPE default::Base { CREATE LINK l -> default::M; }; CREATE TYPE default::A EXTENDING default::Base; CREATE TYPE default::B EXTENDING default::Base; CREATE TYPE default::L { CREATE LINK l -> (default::B | default::A); }; CREATE TYPE ForceRedo { CREATE LINK l -> default::M; }; """) await self.con.execute(r""" insert M; """) await self.con.execute(r""" delete M; """)
) await self.con.execute(r
test_edgeql_ddl_link_union_delete_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_alter_union_01(self): await self.con.execute(r""" CREATE TYPE Foo; CREATE TYPE Bar; """) await self.con.execute(r""" CREATE TYPE Ref { CREATE LINK fubar -> Foo | Bar; } """) await self.con.execute(r""" ALTER TYPE Foo CREATE PROPERTY x -> str; ALTER TYPE Bar CREATE PROPERTY x -> str; """) await self.assert_query_result( r'''SELECT Ref.fubar.x''', [], )
) await self.con.execute(r
test_edgeql_ddl_alter_union_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_alter_union_02(self): await self.con.execute(r""" CREATE TYPE Foo { CREATE PROPERTY x -> str; }; CREATE TYPE Bar { CREATE PROPERTY x -> str; }; CREATE TYPE Baz { CREATE PROPERTY x -> str; }; """) await self.con.execute(r""" CREATE TYPE Ref { CREATE LINK everything -> Foo | Bar | Baz; CREATE LINK fubar -> Foo | Bar; CREATE LINK barbaz -> Bar | Baz; } """) await self.con.execute(r""" ALTER TYPE Baz DROP PROPERTY x; """) await self.assert_query_result( r'''SELECT Ref.fubar.x''', [], ) await self.con.execute(r""" ALTER TYPE Baz CREATE PROPERTY x -> str; """) await self.assert_query_result( r'''SELECT Ref.everything.x''', [], )
) await self.con.execute(r
test_edgeql_ddl_alter_union_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_alter_union_03(self): await self.con.execute(r""" CREATE TYPE Parent; CREATE TYPE Child EXTENDING Parent { CREATE PROPERTY prop -> str; }; CREATE TYPE Foo {CREATE LINK y -> Child}; CREATE TYPE Bar {CREATE LINK y -> Child}; """) await self.con.execute(r""" CREATE TYPE Ref { CREATE LINK fubar -> Foo | Bar; } """) await self.con.execute(r""" ALTER TYPE Foo ALTER LINK y SET TYPE Parent; """) async with self.assertRaisesRegexTx( edgedb.QueryError, "object type 'default::Parent' has no link or property 'prop'", ): await self.assert_query_result( r'''SELECT Ref.fubar.y.prop''', [], )
) await self.con.execute(r
test_edgeql_ddl_alter_union_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_required_computed_01(self): await self.con.execute(r''' CREATE TYPE Profile; CREATE TYPE User { CREATE REQUIRED SINGLE LINK profile -> Profile; }; ''') await self.con.execute(r''' ALTER TYPE Profile { CREATE REQUIRED LINK user := (std::assert_exists((SELECT .<profile[IS User] ))); }; ALTER TYPE Profile { ALTER LINK user SET OPTIONAL; }; ''')
) await self.con.execute(r
test_edgeql_ddl_required_computed_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_recursive_func(self): await self.con.execute(r''' CREATE TYPE SomeThing { CREATE LINK child -> SomeThing; } ''') async with self.assertRaisesRegexTx( edgedb.QueryError, "function 'get_all_children_ordered' does not exist" ): await self.con.execute(r''' CREATE FUNCTION get_all_children_ordered(parent: SomeThing) -> SET OF SomeThing Using ( SELECT SomeThing UNION get_all_children_ordered(parent)) ''') await self.con.execute(r''' CREATE FUNCTION get_all_children_ordered(parent: SomeThing) -> SET OF SomeThing Using ( SELECT SomeThing ) ''') async with self.assertRaisesRegexTx( edgedb.QueryError, r"function 'default::get_all_children_ordered" r"\(parent: default::SomeThing\)' is defined recursively" ): await self.con.execute(r''' ALTER FUNCTION get_all_children_ordered(parent: SomeThing) USING ( SELECT parent.child UNION get_all_children_ordered(parent) ); ''')
) async with self.assertRaisesRegexTx( edgedb.QueryError, "function 'get_all_children_ordered' does not exist" ): await self.con.execute(r
test_edgeql_ddl_recursive_func
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_duplicates_01(self): await self.con.execute(r""" CREATE TYPE Foo; """) with self.assertRaisesRegex( edgedb.errors.SchemaError, r"object type 'default::Foo' already exists"): await self.con.execute(r""" CREATE TYPE Foo; """)
) with self.assertRaisesRegex( edgedb.errors.SchemaError, r"object type 'default::Foo' already exists"): await self.con.execute(r
test_edgeql_ddl_duplicates_01
python
geldata/gel
tests/test_edgeql_ddl.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py
Apache-2.0