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_migration_eq_function_14(self):
await self.migrate(r"""
function hello14(a: str, b: str) -> str
using edgeql $$
SELECT a ++ b
$$
""")
await self.con.execute("""
SET MODULE test;
""")
await self.assert_query_result(
r"""SELECT hello14('hello', '14');""",
['hello14'],
)
await self.migrate(r"""
# Replace the function with a new one by the same name,
# but working with arrays.
function hello14(a: array<str>, b: array<str>) -> array<str>
using edgeql $$
SELECT a ++ b
$$
""")
await self.assert_query_result(
r"""SELECT hello14(['hello'], ['14']);""",
[['hello', '14']],
)
# make sure that the old one is gone
with self.assertRaisesRegex(
edgedb.QueryError,
r'function "hello14\(arg0: std::str, arg1: std::str\)" '
r'does not exist'):
await self.assert_query_result(
r"""SELECT hello14('hello', '14');""",
['hello14'],
) | )
await self.con.execute( | test_edgeql_migration_eq_function_14 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_function_15(self):
await self.migrate(r"""
function hello15(a: str, b: str) -> str
using edgeql $$
SELECT a ++ b
$$
""")
await self.con.execute("""
SET MODULE test;
""")
await self.assert_query_result(
r"""SELECT hello15('hello', '15');""",
['hello15'],
)
await self.migrate(r"""
# Replace the function with a new one by the same name,
# but working with arrays.
function hello15(a: tuple<str, str>) -> str
using edgeql $$
SELECT a.0 ++ a.1
$$
""")
await self.assert_query_result(
r"""SELECT hello15(('hello', '15'));""",
['hello15'],
)
# make sure that the old one is gone
with self.assertRaisesRegex(
edgedb.QueryError,
r'function "hello15\(arg0: std::str, arg1: std::str\)" '
r'does not exist'):
await self.assert_query_result(
r"""SELECT hello15('hello', '15');""",
['hello15'],
) | )
await self.con.execute( | test_edgeql_migration_eq_function_15 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_function_16(self):
# Test prop default and function order of definition. The
# function happens to be shadowing a "std" function. We expect
# that the function `test::to_upper` will actually be used.
#
# See also `test_schema_get_migration_21`
await self.migrate(r"""
type Foo16 {
property name -> str {
default := str_upper('some_name');
};
}
function str_upper(val: str) -> str {
using (SELECT '^^' ++ std::str_upper(val) ++ '^^');
}
""")
await self.con.execute("""
SET MODULE test;
""")
await self.assert_query_result(
r"""SELECT str_upper('hello');""",
['^^HELLO^^'],
)
await self.con.execute("""
INSERT Foo16;
""")
await self.assert_query_result(
r"""SELECT Foo16.name;""",
['^^SOME_NAME^^'],
) | )
await self.con.execute( | test_edgeql_migration_eq_function_16 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_linkprops_01(self):
await self.migrate(r"""
type Child;
type Base {
link foo -> Child;
};
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {
foo := (INSERT Child)
};
""")
# Migration adding a link property.
await self.migrate(r"""
type Child;
type Base {
link foo -> Child {
property bar -> str
}
};
""")
# actually record a link property
await self.con.execute(r"""
UPDATE
Base
SET {
foo := .foo {
@bar := 'lp01'
}
};
""")
await self.assert_query_result(
r"""
SELECT Base {
foo: { @bar }
};
""",
[{'foo': {'@bar': 'lp01'}}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_linkprops_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_linkprops_02(self):
await self.migrate(r"""
type Child;
type Base {
link foo -> Child {
property bar -> str
}
};
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {foo := (INSERT Child)};
UPDATE Base
SET {
foo := .foo { @bar := 'lp02' },
};
""")
await self.migrate(r"""
type Child;
type Base {
link foo -> Child {
# change the link property name
property bar2 -> str
}
};
""")
await self.assert_query_result(
r"""
SELECT Base {
foo: { @bar2 }
};
""",
[{'foo': {'@bar2': 'lp02'}}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_linkprops_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_linkprops_03(self):
await self.migrate(r"""
type Child;
type Base {
link foo -> Child {
property bar -> int64
}
};
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {foo := (INSERT Child)};
UPDATE Base
SET {
foo := .foo { @bar := 3 },
};
""")
await self.migrate(r"""
type Child;
type Base {
link foo -> Child {
# change the link property type
property bar -> int32
}
};
""")
await self.assert_query_result(
r"""
SELECT Base {
foo: { @bar }
};
""",
[{'foo': {'@bar': 3}}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_linkprops_03 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_linkprops_04(self):
await self.migrate(r"""
type Child;
type Base {
link foo -> Child {
property bar -> str
}
};
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {foo := (INSERT Child)};
UPDATE Base
SET {
foo := .foo { @bar := 'lp04' },
};
""")
await self.migrate(r"""
type Child;
type Base {
# change the link cardinality
multi link foo -> Child {
property bar -> str
}
};
""")
await self.assert_query_result(
r"""
SELECT Base {
foo: { @bar }
};
""",
[{'foo': [{'@bar': 'lp04'}]}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_linkprops_04 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_linkprops_05(self):
await self.migrate(r"""
type Child;
type Base {
multi link foo -> Child {
property bar -> str
}
};
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {foo := (INSERT Child)};
UPDATE Base
SET {
foo := .foo { @bar := 'lp05' },
};
""")
await self.migrate(r"""
type Child;
type Base {
# change the link cardinality
link foo -> Child {
property bar -> str
}
};
""", user_input=[
'SELECT .foo LIMIT 1'
])
await self.assert_query_result(
r"""
SELECT Base {
foo: { @bar }
};
""",
[{'foo': {'@bar': 'lp05'}}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_linkprops_05 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_linkprops_06(self):
await self.migrate(r"""
type Child;
type Base {
link child -> Child {
property foo -> str;
}
};
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {child := (INSERT Child)};
UPDATE Base
SET {
child := .child {
@foo := 'lp06',
},
};
""")
await self.migrate(r"""
type Child;
type Base {
link child -> Child {
property foo -> str;
# add another link prop
property bar -> int64;
}
};
""")
# update the existing data with a new link prop 'bar'
await self.con.execute(r"""
UPDATE Base
SET {
child := .child {
@bar := 111,
@foo := 'lp06',
},
};
""")
await self.assert_query_result(
r"""
SELECT Base {
child: {
@foo,
@bar
}
};
""",
[{
'child': {
'@foo': 'lp06',
'@bar': 111
}
}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_linkprops_06 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_linkprops_07(self):
await self.migrate(r"""
type Child;
type Base {
link child -> Child
};
type Derived extending Base {
overloaded link child -> Child {
property foo -> str
}
};
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Derived {child := (INSERT Child)};
UPDATE Derived
SET {
child := .child {
@foo := 'lp07',
},
};
""")
await self.migrate(r"""
type Child;
type Base {
# move the link property earlier in the inheritance tree
link child -> Child {
property foo -> str
}
};
type Derived extending Base;
""")
await self.assert_query_result(
r"""
SELECT Base {
child: {
@foo,
}
};
""",
[{
'child': {
'@foo': 'lp07',
}
}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_linkprops_07 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_linkprops_08(self):
await self.migrate(r"""
type Child;
type Base {
link child -> Child {
property foo -> str
}
};
type Derived extending Base;
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Derived {child := (INSERT Child)};
""")
await self.con.execute(r"""
UPDATE Derived
SET {
child := .child {
@foo := 'lp08',
},
};
""")
await self.migrate(r"""
type Child;
type Base {
link child -> Child
};
type Derived extending Base {
overloaded link child -> Child {
# move the link property later in the inheritance tree
property foo -> str
}
};
""")
await self.assert_query_result(
r"""
SELECT Derived {
children := count(.child)
};
""",
[{
'children': 1,
}],
)
await self.assert_query_result(
r"""
SELECT Derived {
child: {
@foo,
}
};
""",
[{
'child': {
'@foo': 'lp08',
}
}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_linkprops_08 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_linkprops_09(self):
await self.migrate(r"""
type Child;
type Base {
link child -> Child
};
type Derived extending Base {
overloaded link child -> Child {
property foo -> str
}
};
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Derived {child := (INSERT Child)};
UPDATE Derived
SET {
child := .child {
@foo := 'lp09',
},
};
""")
await self.migrate(r"""
type Child;
# factor out link property all the way to an abstract link
abstract link base_child {
property foo -> str;
}
type Base {
link child extending base_child -> Child;
};
type Derived extending Base;
""")
await self.assert_query_result(
r"""
SELECT Base {
child: {
@foo,
}
};
""",
[{
'child': {
'@foo': 'lp09',
}
}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_linkprops_09 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_linkprops_10(self):
# reverse of the test_edgeql_migration_eq_linkprops_09 refactoring
await self.migrate(r"""
type Child;
abstract link base_child {
property foo -> str;
}
type Base {
link child extending base_child -> Child;
};
type Derived extending Base;
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Derived {child := (INSERT Child)};
UPDATE Derived
SET {
child := .child {
@foo := 'lp10',
},
};
""")
await self.migrate(r"""
type Child;
type Base {
link child -> Child
};
type Derived extending Base {
overloaded link child -> Child {
# move the link property later in the inheritance tree
property foo -> str
}
};
""")
await self.assert_query_result(
r"""
SELECT Derived {
child: {
@foo,
}
};
""",
[{
'child': {
'@foo': 'lp10',
}
}],
)
await self.migrate("") | )
await self.con.execute(r | test_edgeql_migration_eq_linkprops_10 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_linkprops_11(self):
# merging a link with the same properties
await self.migrate(r"""
type Thing;
type Owner {
link item -> Thing {
property foo -> str;
}
};
type Renter {
link item -> Thing {
property foo -> str;
}
};
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Owner {item := (INSERT Thing)};
UPDATE Owner
SET {
item := .item {
@foo := 'owner_lp11',
},
};
INSERT Renter {item := (INSERT Thing)};
UPDATE Renter
SET {
item := .item {
@foo := 'renter_lp11',
},
};
""")
await self.migrate(r"""
type Thing;
type Base {
link item -> Thing {
property foo -> str;
}
};
type Owner extending Base;
type Renter extending Base;
""")
await self.assert_query_result(
r"""
SELECT Owner {
item: {
@foo,
}
};
""",
[{
'item': {
'@foo': 'owner_lp11',
}
}],
)
await self.assert_query_result(
r"""
SELECT Renter {
item: {
@foo,
}
};
""",
[{
'item': {
'@foo': 'renter_lp11',
}
}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_linkprops_11 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_linkprops_12(self):
# merging a link with different properties
await self.migrate(r"""
type Thing;
type Owner {
link item -> Thing {
property foo -> str;
}
};
type Renter {
link item -> Thing {
property bar -> str;
}
};
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Owner {item := (INSERT Thing)};
UPDATE Owner
SET {
item := .item {
@foo := 'owner_lp11',
},
};
INSERT Renter {item := (INSERT Thing)};
UPDATE Renter
SET {
item := .item {
@bar := 'renter_lp11',
},
};
""")
await self.migrate(r"""
type Thing;
type Base {
link item -> Thing {
property foo -> str;
property bar -> str;
}
};
type Owner extending Base;
type Renter extending Base;
""")
await self.assert_query_result(
r"""
SELECT Owner {
item: {
@foo,
@bar,
}
};
""",
[{
'item': {
'@foo': 'owner_lp11',
'@bar': None,
}
}],
)
await self.assert_query_result(
r"""
SELECT Renter {
item: {
@foo,
@bar,
}
};
""",
[{
'item': {
'@foo': None,
'@bar': 'renter_lp11',
}
}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_linkprops_12 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_annotation_01(self):
await self.migrate(r"""
type Base;
""")
await self.con.execute("""
SET MODULE test;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
annotations: {
name,
@value
} ORDER BY .name
}
FILTER .name LIKE 'test::%'
ORDER BY .name;
""",
[{
'name': 'test::Base',
'annotations': [],
}],
)
await self.migrate(r"""
type Base {
# add a title annotation
annotation title := 'Base description 01'
}
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
annotations: {
name,
@value
} ORDER BY .name
}
FILTER .name LIKE 'test::%'
ORDER BY .name;
""",
[{
'name': 'test::Base',
'annotations': [{
'name': 'std::title',
'@value': 'Base description 01'
}],
}],
)
await self.migrate(r"""
# add inheritable and non-inheritable annotations
abstract annotation foo_anno;
abstract inheritable annotation bar_anno;
type Base {
annotation title := 'Base description 01';
annotation foo_anno := 'Base foo_anno 01';
annotation bar_anno := 'Base bar_anno 01';
}
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
annotations: {
name,
@value
} ORDER BY .name
}
FILTER .name LIKE 'test::%'
ORDER BY .name;
""",
[{
'name': 'test::Base',
'annotations': [{
'name': 'std::title',
'@value': 'Base description 01'
}, {
'name': 'test::bar_anno',
'@value': 'Base bar_anno 01'
}, {
'name': 'test::foo_anno',
'@value': 'Base foo_anno 01'
}],
}],
)
await self.migrate(r"""
abstract annotation foo_anno;
abstract inheritable annotation bar_anno;
type Base {
annotation title := 'Base description 01';
annotation foo_anno := 'Base foo_anno 01';
annotation bar_anno := 'Base bar_anno 01';
}
# extend Base
type Derived extending Base;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
annotations: {
name,
@value
} ORDER BY .name
}
FILTER .name LIKE 'test::%'
ORDER BY .name;
""",
[{
'name': 'test::Base',
'annotations': [{
'name': 'std::title',
'@value': 'Base description 01'
}, {
'name': 'test::bar_anno',
'@value': 'Base bar_anno 01'
}, {
'name': 'test::foo_anno',
'@value': 'Base foo_anno 01'
}],
}, {
'name': 'test::Derived',
'annotations': [{
'name': 'test::bar_anno',
'@value': 'Base bar_anno 01'
}],
}],
) | )
await self.con.execute( | test_edgeql_migration_eq_annotation_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_annotation_02(self):
await self.migrate(r"""
type Base;
""")
await self.con.execute("""
SET MODULE test;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
annotations: {
name,
@value
} ORDER BY .name
}
FILTER .name LIKE 'test::%'
ORDER BY .name;
""",
[{
'name': 'test::Base',
'annotations': [],
}],
)
await self.migrate(r"""
abstract annotation foo_anno;
type Base {
annotation title := 'Base description 02';
annotation foo_anno := 'Base foo_anno 02';
}
type Derived extending Base;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
annotations: {
name,
@value
} ORDER BY .name
}
FILTER .name LIKE 'test::%'
ORDER BY .name;
""",
[{
'name': 'test::Base',
'annotations': [{
'name': 'std::title',
'@value': 'Base description 02'
}, {
'name': 'test::foo_anno',
'@value': 'Base foo_anno 02'
}],
}, {
'name': 'test::Derived',
# annotation not inherited
'annotations': [],
}],
)
await self.migrate(r"""
# remove foo_anno
type Base {
annotation title := 'Base description 02';
}
type Derived extending Base;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
annotations: {
name,
@value
} ORDER BY .name
}
FILTER .name LIKE 'test::%'
ORDER BY .name;
""",
[{
'name': 'test::Base',
'annotations': [{
'name': 'std::title',
'@value': 'Base description 02'
}],
}, {
'name': 'test::Derived',
'annotations': [],
}],
) | )
await self.con.execute( | test_edgeql_migration_eq_annotation_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_annotation_03(self):
await self.migrate(r"""
type Base;
""")
await self.con.execute("""
SET MODULE test;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
annotations: {
name,
@value
} ORDER BY .name
}
FILTER .name LIKE 'test::%'
ORDER BY .name;
""",
[{
'name': 'test::Base',
'annotations': [],
}],
)
await self.migrate(r"""
abstract inheritable annotation bar_anno;
type Base {
annotation title := 'Base description 03';
annotation bar_anno := 'Base bar_anno 03';
}
type Derived extending Base;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
annotations: {
name,
@value
} ORDER BY .name
}
FILTER .name LIKE 'test::%'
ORDER BY .name;
""",
[{
'name': 'test::Base',
'annotations': [{
'name': 'std::title',
'@value': 'Base description 03'
}, {
'name': 'test::bar_anno',
'@value': 'Base bar_anno 03'
}],
}, {
'name': 'test::Derived',
# annotation inherited
'annotations': [{
'name': 'test::bar_anno',
'@value': 'Base bar_anno 03'
}],
}],
)
await self.migrate(r"""
# remove bar_anno
type Base {
annotation title := 'Base description 03';
}
type Derived extending Base;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
annotations: {
name,
@value
} ORDER BY .name
}
FILTER .name LIKE 'test::%'
ORDER BY .name;
""",
[{
'name': 'test::Base',
'annotations': [{
'name': 'std::title',
'@value': 'Base description 03'
}],
}, {
'name': 'test::Derived',
'annotations': [],
}],
) | )
await self.con.execute( | test_edgeql_migration_eq_annotation_03 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_annotation_04(self):
# Test migration of annotation value and nothing else.
await self.migrate(r"""
abstract annotation description;
type Base {
annotation description := "1";
}
""")
await self.con.execute("""
SET MODULE test;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
annotations: {
name,
@value
} ORDER BY .name
}
FILTER .name LIKE 'test::%'
ORDER BY .name;
""",
[{
'name': 'test::Base',
'annotations': [{
'name': 'test::description',
'@value': '1',
}],
}],
)
await self.migrate(r"""
abstract annotation description;
type Base {
annotation description := "2";
}
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
annotations: {
name,
@value
} ORDER BY .name
}
FILTER .name LIKE 'test::%'
ORDER BY .name;
""",
[{
'name': 'test::Base',
'annotations': [{
'name': 'test::description',
'@value': '2',
}],
}],
) | )
await self.con.execute( | test_edgeql_migration_eq_annotation_04 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_describe_annot_01(self):
await self.migrate('''
abstract annotation foo;
type Base {
annotation foo := "1";
};
''')
await self.con.execute('''
START MIGRATION TO {
module test {
abstract annotation bar;
type Base {
annotation bar := "1";
};
}
};
''')
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text': (
'ALTER ABSTRACT ANNOTATION test::foo '
'RENAME TO test::bar;'
)
}],
},
}) | )
await self.con.execute( | test_edgeql_migration_describe_annot_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_index_01(self):
await self.con.execute("""
SET MODULE test;
""")
await self.migrate(r"""
type Base {
property name -> str;
}
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
indexes: {
expr
}
}
FILTER .name = 'test::Base';
""",
[{
'name': 'test::Base',
'indexes': [],
}],
)
await self.migrate(r"""
type Base {
property name -> str;
# an index
index on (.name);
}
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
indexes: {
expr
}
}
FILTER .name = 'test::Base';
""",
[{
'name': 'test::Base',
'indexes': [{
'expr': '.name'
}]
}],
)
await self.migrate(r"""
type Base {
# rename the indexed property
property title -> str;
index on (.title);
}
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
indexes: {
expr
}
}
FILTER .name = 'test::Base';
""",
[{
'name': 'test::Base',
'indexes': [{
'expr': '.title'
}]
}],
) | )
await self.migrate(r | test_edgeql_migration_eq_index_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_index_02(self):
await self.migrate(r"""
type Base {
property name -> str;
index on (.name);
}
""")
await self.con.execute("""
SET MODULE test;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
indexes: {
expr
}
}
FILTER .name = 'test::Base';
""",
[{
'name': 'test::Base',
'indexes': [{
'expr': '.name'
}]
}],
)
await self.migrate(r"""
type Base {
property name -> str;
# remove the index
}
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
indexes: {
expr
}
}
FILTER .name = 'test::Base';
""",
[{
'name': 'test::Base',
'indexes': [],
}],
) | )
await self.con.execute( | test_edgeql_migration_eq_index_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_index_03(self):
await self.migrate(r"""
type Base {
property name -> int64;
}
""")
await self.con.execute("""
SET MODULE test;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
indexes: {
expr
}
}
FILTER .name = 'test::Base';
""",
[{
'name': 'test::Base',
'indexes': [],
}],
)
await self.migrate(r"""
type Base {
property name -> int64;
# an index
index on (.name);
}
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
indexes: {
expr
}
}
FILTER .name = 'test::Base';
""",
[{
'name': 'test::Base',
'indexes': [{
'expr': '.name'
}]
}],
)
await self.migrate(r"""
type Base {
# change the indexed property type
property name -> int32;
index on (.name);
}
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
indexes: {
expr
}
}
FILTER .name = 'test::Base';
""",
[{
'name': 'test::Base',
'indexes': [{
'expr': '.name'
}]
}],
) | )
await self.con.execute( | test_edgeql_migration_eq_index_03 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_index_04(self):
await self.migrate(r"""
type Base {
property first_name -> str;
property last_name -> str;
property name := .first_name ++ ' ' ++ .last_name;
}
""")
await self.con.execute("""
SET MODULE test;
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
indexes: {
expr
}
}
FILTER .name = 'test::Base';
""",
[{
'name': 'test::Base',
'indexes': [],
}],
)
await self.migrate(r"""
type Base {
property first_name -> str;
property last_name -> str;
property name := .first_name ++ ' ' ++ .last_name;
# an index on a computable
index on (.name);
}
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
name,
indexes: {
expr
}
}
FILTER .name = 'test::Base';
""",
[{
'name': 'test::Base',
'indexes': [{
'expr': '.name'
}]
}],
) | )
await self.con.execute( | test_edgeql_migration_eq_index_04 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_01(self):
await self.migrate(r"""
type Base;
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base;
""")
await self.migrate(r"""
type Base {
property foo -> array<float32>;
}
""")
await self.con.execute(r"""
UPDATE Base
SET {
foo := [1.2, 4.5]
};
""")
await self.assert_query_result(
r"""SELECT Base.foo;""",
[[1.2, 4.5]],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_02(self):
await self.migrate(r"""
type Base;
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base;
""")
await self.migrate(r"""
type Base {
property foo -> tuple<str, int32>;
}
""")
await self.con.execute(r"""
UPDATE Base
SET {
foo := ('hello', 42)
};
""")
await self.assert_query_result(
r"""SELECT Base.foo;""",
[['hello', 42]],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_03(self):
await self.migrate(r"""
type Base;
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base;
""")
await self.migrate(r"""
type Base {
# nested collection
property foo -> tuple<str, int32, array<float32>>;
}
""")
await self.con.execute(r"""
UPDATE Base
SET {
foo := ('test', 42, [1.2, 4.5])
};
""")
await self.assert_query_result(
r"""SELECT Base.foo;""",
[['test', 42, [1.2, 4.5]]],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_03 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_04(self):
await self.migrate(r"""
type Base;
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base;
""")
await self.migrate(r"""
type Base {
property foo -> tuple<a: str, b: int32>;
}
""")
await self.con.execute(r"""
UPDATE Base
SET {
foo := (a := 'hello', b := 42)
};
""")
await self.assert_query_result(
r"""SELECT Base.foo;""",
[{'a': 'hello', 'b': 42}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_04 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_06(self):
await self.migrate(r"""
type Base {
property foo -> array<int32>;
}
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {
foo := [1, 2]
}
""")
# sanity check
await self.assert_query_result(
r"""SELECT Base.foo;""",
[[1, 2]],
)
await self.migrate(r"""
type Base {
property foo -> array<float64>;
}
""")
await self.assert_query_result(
r"""SELECT Base.foo;""",
[[1.0, 2.0]],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_06 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_07(self):
await self.con.execute("""
SET MODULE test;
""")
await self.migrate(r"""
type Base {
# convert property type to tuple
property bar -> array<str>;
property foo -> tuple<str, int32>;
}
""")
await self.con.execute(r"""
INSERT Base {
bar := ['123'],
foo := ('test', <int32>7),
}
""")
await self.migrate(
r"""
type Base {
property bar -> array<int64>;
property foo -> tuple<str, int32, int32>;
}
""",
user_input=[
"<array<int64>>.bar",
"(.foo.0, .foo.1, 0)",
]
)
await self.assert_query_result(
r"""SELECT Base.bar;""",
[[123]],
)
await self.assert_query_result(
r"""SELECT Base.foo;""",
[['test', 7, 0]],
) | )
await self.migrate(r | test_edgeql_migration_eq_collections_07 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_08(self):
await self.migrate(r"""
type Base {
property foo -> tuple<int32, int32>;
}
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {
foo := (0, 8)
}
""")
await self.migrate(r"""
type Base {
# convert property type to a tuple with different (but
# cast-compatible) element types
property foo -> tuple<int64, int32>;
}
""")
await self.assert_query_result(
r"""SELECT Base.foo;""",
[[0, 8]],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_08 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_09(self):
await self.migrate(r"""
type Base {
property foo -> tuple<str, int32>;
}
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {
foo := ('test', 9)
}
""")
await self.migrate(r"""
type Base {
# convert property type from unnamed to named tuple
property foo -> tuple<a: str, b: int32>;
}
""")
# In theory, since under normal circumstances we can cast an
# unnamed tuple into named, it's reasonable to expect this
# migration to preserve data here.
await self.assert_query_result(
r"""SELECT Base.foo;""",
[{'a': 'test', 'b': 9}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_09 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_13(self):
await self.migrate(r"""
type Base {
property foo -> float32;
};
# alias that don't have arrays
alias BaseAlias := Base { bar := Base.foo };
alias CollAlias := Base.foo;
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {
foo := 13.5,
}
""")
# make sure that the alias initialized correctly
await self.assert_query_result(
r"""SELECT BaseAlias{bar};""",
[{'bar': 13.5}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[13.5],
)
await self.migrate(r"""
type Base {
property foo -> float32;
};
# "same" alias that now have arrays
alias BaseAlias := Base { bar := [Base.foo] };
alias CollAlias := [Base.foo];
""")
await self.assert_query_result(
r"""SELECT BaseAlias{bar};""",
[{'bar': [13.5]}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[[13.5]],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_13 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_14(self):
await self.migrate(r"""
type Base {
property name -> str;
property foo -> float32;
};
# alias that don't have tuples
alias BaseAlias := Base { bar := Base.foo };
alias CollAlias := Base.foo;
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {
name := 'coll_14',
foo := 14.5,
}
""")
# make sure that the alias initialized correctly
await self.assert_query_result(
r"""SELECT BaseAlias{bar};""",
[{'bar': 14.5}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[14.5],
)
await self.migrate(r"""
type Base {
property name -> str;
property foo -> float32;
};
# "same" alias that now have tuples
alias BaseAlias := Base { bar := (Base.name, Base.foo) };
alias CollAlias := (Base.name, Base.foo);
""")
await self.assert_query_result(
r"""SELECT BaseAlias{bar};""",
[{'bar': ['coll_14', 14.5]}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[['coll_14', 14.5]],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_14 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_15(self):
await self.migrate(r"""
type Base {
property name -> str;
property number -> int32;
property foo -> float32;
};
# alias that don't have nested collections
alias BaseAlias := Base { bar := Base.foo };
alias CollAlias := Base.foo;
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {
name := 'coll_15',
number := 15,
foo := 15.5,
}
""")
# make sure that the alias initialized correctly
await self.assert_query_result(
r"""SELECT BaseAlias{bar};""",
[{'bar': 15.5}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[15.5],
)
await self.migrate(r"""
type Base {
property name -> str;
property number -> int32;
property foo -> float32;
};
# "same" alias that now have nested collections
alias BaseAlias := Base {
bar := (Base.name, Base.number, [Base.foo])
};
alias CollAlias := (Base.name, Base.number, [Base.foo]);
""")
await self.assert_query_result(
r"""SELECT BaseAlias{bar};""",
[{'bar': ['coll_15', 15, [15.5]]}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[['coll_15', 15, [15.5]]],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_15 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_16(self):
await self.migrate(r"""
type Base {
property name -> str;
property foo -> float32;
};
# alias that don't have named tuples
alias BaseAlias := Base { bar := Base.foo };
alias CollAlias := Base.foo;
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {
name := 'coll_16',
foo := 16.5,
}
""")
# make sure that the alias initialized correctly
await self.assert_query_result(
r"""SELECT BaseAlias{bar};""",
[{'bar': 16.5}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[16.5],
)
await self.migrate(r"""
type Base {
property name -> str;
property foo -> float32;
};
# "same" alias that now have named tuples
alias BaseAlias := Base {
bar := (a := Base.name, b := Base.foo)
};
alias CollAlias := (a := Base.name, b := Base.foo);
""")
await self.assert_query_result(
r"""SELECT BaseAlias{bar};""",
[{'bar': {'a': 'coll_16', 'b': 16.5}}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[{'a': 'coll_16', 'b': 16.5}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_16 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_17(self):
await self.migrate(r"""
type Base {
property foo -> float32;
property bar -> int32;
};
# alias with array<int32>
alias BaseAlias := Base { data := [Base.bar] };
alias CollAlias := [Base.bar];
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {
foo := 17.5,
bar := 17,
}
""")
# make sure that the alias initialized correctly
await self.assert_query_result(
r"""SELECT BaseAlias{data};""",
[{'data': [17]}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[[17]],
)
await self.migrate(r"""
type Base {
property foo -> float32;
property bar -> int32;
};
# alias with array<float32>
alias BaseAlias := Base { data := [Base.foo] };
alias CollAlias := [Base.foo];
""")
await self.assert_query_result(
r"""SELECT BaseAlias{data};""",
[{'data': [17.5]}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[[17.5]],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_17 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_18(self):
await self.migrate(r"""
type Base {
property name -> str;
property number -> int32;
property foo -> float32;
};
# alias with tuple<str, int32>
alias BaseAlias := Base {
data := (Base.name, Base.number)
};
alias CollAlias := (Base.name, Base.number);
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {
name := 'coll_18',
number := 18,
foo := 18.5,
}
""")
# make sure that the alias initialized correctly
await self.assert_query_result(
r"""SELECT BaseAlias{data};""",
[{'data': ['coll_18', 18]}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[['coll_18', 18]],
)
await self.migrate(r"""
type Base {
property name -> str;
property number -> int32;
property foo -> float32;
};
# alias with tuple<str, int32, float32>
alias BaseAlias := Base {
data := (Base.name, Base.number, Base.foo)
};
alias CollAlias := (Base.name, Base.number, Base.foo);
""")
await self.assert_query_result(
r"""SELECT BaseAlias{data};""",
[{'data': ['coll_18', 18, 18.5]}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[['coll_18', 18, 18.5]],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_18 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_20(self):
await self.migrate(r"""
type Base {
property name -> str;
property number -> int32;
property foo -> float32;
};
# alias with tuple<str, int32>
alias BaseAlias := Base {
data := (Base.name, Base.number)
};
alias CollAlias := (Base.name, Base.number);
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {
name := 'test20',
number := 20,
foo := 123.5,
}
""")
# make sure that the alias initialized correctly
await self.assert_query_result(
r"""SELECT BaseAlias{data};""",
[{'data': ['test20', 20]}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[['test20', 20]],
)
await self.migrate(r"""
type Base {
property name -> str;
property number -> int32;
property foo -> float32;
};
# alias with tuple<str, float32>
alias BaseAlias := Base {
data := (Base.name, Base.foo)
};
alias CollAlias := (Base.name, Base.foo);
""")
await self.assert_query_result(
r"""SELECT BaseAlias {data};""",
[{'data': ['test20', 123.5]}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[['test20', 123.5]],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_20 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_collections_21(self):
await self.migrate(r"""
type Base {
property name -> str;
property foo -> float32;
};
# alias with tuple<str, float32>
alias BaseAlias := Base {
data := (Base.name, Base.foo)
};
alias CollAlias := (Base.name, Base.foo);
""")
await self.con.execute(r"""
SET MODULE test;
INSERT Base {
name := 'coll_21',
foo := 21.5,
}
""")
# make sure that the alias initialized correctly
await self.assert_query_result(
r"""SELECT BaseAlias{data};""",
[{'data': ['coll_21', 21.5]}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[['coll_21', 21.5]],
)
await self.migrate(r"""
type Base {
property name -> str;
property foo -> float32;
};
# alias with named tuple<a: str, b: float32>
alias BaseAlias := Base {
data := (a := Base.name, b := Base.foo)
};
alias CollAlias := (a := Base.name, b := Base.foo);
""")
await self.assert_query_result(
r"""SELECT BaseAlias{data};""",
[{'data': {'a': 'coll_21', 'b': 21.5}}],
)
await self.assert_query_result(
r"""SELECT CollAlias;""",
[{'a': 'coll_21', 'b': 21.5}],
) | )
await self.con.execute(r | test_edgeql_migration_eq_collections_21 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_eq_drop_module(self):
await self.migrate(r"""
type Base;
""", module='test')
await self.migrate(r"""
scalar type foo extending std::str;
""", module='newtest')
await self.assert_query_result(
'SELECT (SELECT schema::Module FILTER .name LIKE "%test").name;',
{'newtest', 'std::_test'},
) | , module='test')
await self.migrate(r | test_edgeql_migration_eq_drop_module | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_inherited_optionality_01(self):
await self.migrate(r"""
type User;
type Message {
required link author -> User;
required property body -> str;
};
""")
await self.start_migration(r"""
type User;
type BaseMessage {
required link author -> User;
required property body -> str;
}
type Message extending BaseMessage;
""")
await self.fast_forward_describe_migration() | )
await self.start_migration(r | test_edgeql_migration_inherited_optionality_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_rename_type_02(self):
await self.migrate(r"""
type Note {
property note -> str;
}
type Subtype extending Note;
type Link {
link a -> Note;
}
type Uses {
required property x -> str {
default := (SELECT Note.note LIMIT 1)
}
};
type ComputeLink {
property foo -> str;
multi link x := (
SELECT Note FILTER Note.note = ComputeLink.foo);
};
alias Alias := Note;
""")
await self.migrate(r"""
type Remark {
property note -> str;
}
type Subtype extending Remark;
type Link {
link a -> Remark;
}
type Uses {
required property x -> str {
default := (SELECT Remark.note LIMIT 1)
}
};
type ComputeLink {
property foo -> str;
multi link x := (
SELECT Remark FILTER Remark.note = ComputeLink.foo);
};
alias Alias := Remark;
""")
await self.migrate("") | )
await self.migrate(r | test_edgeql_migration_rename_type_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_rename_type_03(self):
await self.migrate(r"""
type Note {
property note -> str;
}
""")
await self.migrate(r"""
type Remark {
property note -> str;
}
type Subtype extending Remark;
type Link {
link a -> Remark;
}
type Uses {
required property x -> str {
default := (SELECT Remark.note LIMIT 1)
}
};
type ComputeLink {
property foo -> str;
multi link x := (
SELECT Remark FILTER Remark.note = ComputeLink.foo);
};
alias Alias := Remark;
""")
await self.migrate("") | )
await self.migrate(r | test_edgeql_migration_rename_type_03 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_annotation_05(self):
await self.migrate(r"""
abstract inheritable annotation my_anno;
type Base {
property my_prop -> str {
annotation my_anno := 'Base my_anno 05';
}
}
type Derived extending Base {
overloaded property my_prop -> str {
annotation my_anno := 'Derived my_anno 05';
}
}
""")
await self.migrate(r"""
# rename annotated & inherited property
abstract inheritable annotation my_anno;
type Base {
property renamed_prop -> str {
annotation my_anno := 'Base my_anno 05';
}
}
type Derived extending Base {
overloaded property renamed_prop -> str {
annotation my_anno := 'Derived my_anno 05';
}
}
""")
await self.migrate("") | )
await self.migrate(r | test_edgeql_migration_annotation_05 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_reset_optional_01(self):
await self.migrate(r'''
abstract type Person {
required property name -> str;
}
type PC extending Person;
''')
await self.migrate(r'''
abstract type Person {
property name -> str;
}
type PC extending Person;
''')
await self.migrate(r'''
abstract type Person {
required property name -> str;
}
type PC extending Person;
''', user_input=['""']) | )
await self.migrate(r | test_edgeql_migration_reset_optional_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_reset_optional_02(self):
await self.migrate(r'''
abstract type Person {
required property name -> str;
}
type PC extending Person {
overloaded required property name -> str;
}
''')
await self.migrate(r'''
abstract type Person {
property name -> str;
}
type PC extending Person {
overloaded property name -> str;
}
''') | )
await self.migrate(r | test_edgeql_migration_reset_optional_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_reset_optional_03(self):
await self.migrate(r'''
abstract type Person {
required property name -> str;
}
type PC extending Person {
overloaded required property name -> str;
}
''')
await self.migrate(r'''
abstract type Person {
optional property name -> str;
}
type PC extending Person {
overloaded optional property name -> str;
}
''') | )
await self.migrate(r | test_edgeql_migration_reset_optional_03 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_reset_optional_04(self):
await self.migrate(r'''
abstract type Person {
optional property name -> str;
}
type PC extending Person {
overloaded optional property name -> str;
}
''')
await self.migrate(r'''
abstract type Person {
required property name -> str;
}
type PC extending Person {
overloaded required property name -> str;
}
''', user_input=["''", "''"]) | )
await self.migrate(r | test_edgeql_migration_reset_optional_04 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_inherited_default_02(self):
await self.migrate(r"""
abstract type Foo {
multi link link -> Obj {
};
}
type Bar extending Foo {}
type Obj {
required property name -> str {
constraint exclusive;
}
}
""")
await self.migrate(r"""
abstract type Foo {
multi link link -> Obj {
default := ( select Obj filter .name = 'X' )
};
}
type Bar extending Foo {}
type Obj {
required property name -> str {
constraint exclusive;
}
}
""") | )
await self.migrate(r | test_edgeql_migration_inherited_default_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_scalar_array_01(self):
await self.migrate(r"""
type User {
required property scopes -> array<scope>;
}
scalar type scope extending int64 {
constraint one_of (1, 2);
}
""")
await self.migrate(r"""
type User {
required property scopes -> array<scope>;
}
scalar type scope extending int64 {
constraint one_of (1, 2, 3);
}
""") | )
await self.migrate(r | test_edgeql_migration_scalar_array_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_scalar_array_02(self):
await self.migrate(r"""
scalar type scope extending int64;
""")
await self.migrate(r"""
type User {
required property scopes -> array<scope>;
}
scalar type scope extending int64 {
constraint one_of (1, 2);
}
""") | )
await self.migrate(r | test_edgeql_migration_scalar_array_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_force_alter(self):
await self.con.execute('''
START MIGRATION TO {
module test {
type Obj1 {
property foo -> str;
property bar -> str;
}
type Obj2 {
property o -> int64;
link o1 -> Obj1;
}
};
};
''')
await self.fast_forward_describe_migration()
await self.con.execute('''
START MIGRATION TO {
module test {
type Obj1 {
property foo -> str;
property bar -> str;
}
type NewObj2 {
property name -> str;
annotation title := 'Obj2';
}
};
};
''')
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
'CREATE TYPE test::NewObj2 {\n'
" CREATE ANNOTATION std::title := 'Obj2';\n"
' CREATE PROPERTY name'
': std::str;\n'
'};'
}],
},
})
await self.con.execute('''
ALTER CURRENT MIGRATION REJECT PROPOSED;
''')
# We get the parts suggested to us granularly. We only bother
# to check the first one.
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
'ALTER TYPE test::Obj2 {\n'
' DROP LINK o1;\n'
'\n'
'};'
}],
},
})
await self.fast_forward_describe_migration() | )
await self.fast_forward_describe_migration()
await self.con.execute( | test_edgeql_migration_force_alter | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_future_01(self):
await self.con.execute('''
START MIGRATION TO {
using future nonrecursive_access_policies;
};
''')
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
"CREATE FUTURE nonrecursive_access_policies;"
}],
'confidence': 1.0,
},
})
await self.fast_forward_describe_migration()
await self.assert_query_result(
r"""
SELECT schema::FutureBehavior {
name,
}
FILTER .name = 'nonrecursive_access_policies'
""",
[{
'name': 'nonrecursive_access_policies',
}]
)
await self.con.execute('''
START MIGRATION TO {
};
''')
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
'DROP FUTURE nonrecursive_access_policies;'
}],
'confidence': 1.0,
},
})
await self.fast_forward_describe_migration()
await self.assert_query_result(
r"""
SELECT schema::FutureBehavior {
name,
}
FILTER .name = 'nonrecursive_access_policies'
""",
[]
) | )
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
"CREATE FUTURE nonrecursive_access_policies;"
}],
'confidence': 1.0,
},
})
await self.fast_forward_describe_migration()
await self.assert_query_result(
r | test_edgeql_migration_future_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_extensions_01(self):
await self.con.execute('''
START MIGRATION TO {
using extension graphql;
};
''')
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
"CREATE EXTENSION graphql VERSION '1.0';"
}],
'confidence': 1.0,
},
})
await self.fast_forward_describe_migration()
await self.assert_query_result(
r"""
SELECT schema::Extension {
name,
}
FILTER .name = 'graphql'
""",
[{
'name': 'graphql',
}]
)
await self.con.execute('''
START MIGRATION TO {
};
''')
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
'DROP EXTENSION graphql;'
}],
'confidence': 1.0,
},
})
await self.fast_forward_describe_migration()
await self.assert_query_result(
r"""
SELECT schema::Extension {
name,
}
FILTER .name = 'graphql'
""",
[],
)
await self.con.execute('''
START MIGRATION TO {
using extension graphql version '1.0';
};
''')
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
"CREATE EXTENSION graphql VERSION '1.0';"
}],
'confidence': 1.0,
},
})
await self.fast_forward_describe_migration() | )
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
"CREATE EXTENSION graphql VERSION '1.0';"
}],
'confidence': 1.0,
},
})
await self.fast_forward_describe_migration()
await self.assert_query_result(
r | test_edgeql_migration_extensions_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_confidence_01(self):
await self.con.execute('''
START MIGRATION TO {
module test {
type Obj1 {
property foo -> str;
property bar -> str;
}
};
};
''')
await self.fast_forward_describe_migration()
await self.con.execute('''
START MIGRATION TO {
module test {
type NewObj1 {
property foo -> str;
property bar -> str;
}
};
};
''')
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
'ALTER TYPE test::Obj1 RENAME TO test::NewObj1;'
}],
'confidence': 0.637027,
},
})
await self.con.execute('''
ALTER CURRENT MIGRATION REJECT PROPOSED;
''')
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
'CREATE TYPE test::NewObj1 {\n'
' CREATE PROPERTY bar: std::str;'
'\n CREATE PROPERTY foo: std::str;'
'\n};'
}],
'confidence': 1.0,
},
}) | )
await self.fast_forward_describe_migration()
await self.con.execute( | test_edgeql_migration_confidence_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_confidence_02(self):
await self.con.execute('''
START MIGRATION TO {
module test {
type Obj1;
};
};
''')
await self.fast_forward_describe_migration()
await self.con.execute('''
START MIGRATION TO {
module test {
type Obj1;
type Obj2;
};
};
''')
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
'CREATE TYPE test::Obj2;'
}],
'confidence': 1.0,
},
}) | )
await self.fast_forward_describe_migration()
await self.con.execute( | test_edgeql_migration_confidence_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_confidence_03(self):
await self.con.execute('''
START MIGRATION TO {
module test {
type Obj1;
};
};
''')
await self.fast_forward_describe_migration()
await self.con.execute('''
START MIGRATION TO {
module test {
type Obj1 {
property x -> str;
}
};
};
''')
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
'ALTER TYPE test::Obj1 {\n '
'CREATE PROPERTY x: std::str;\n};'
}],
'confidence': 1.0,
},
}) | )
await self.fast_forward_describe_migration()
await self.con.execute( | test_edgeql_migration_confidence_03 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_confidence_04(self):
await self.con.execute('''
START MIGRATION TO {
module test {
type Obj1 {
link link -> Object;
}
};
};
''')
await self.fast_forward_describe_migration()
await self.con.execute('''
START MIGRATION TO {
module test {
type Obj1 {
link link -> Object {
property x -> str;
}
}
};
};
''')
await self.assert_describe_migration({
'confirmed': [],
'complete': False,
'proposed': {
'statements': [{
'text':
'ALTER TYPE test::Obj1 {\n '
'ALTER LINK link {\n '
'CREATE PROPERTY x: std::str;\n };\n};'
}],
'confidence': 1.0,
},
}) | )
await self.fast_forward_describe_migration()
await self.con.execute( | test_edgeql_migration_confidence_04 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_data_safety_01(self):
await self.start_migration('''
type Obj1;
''')
await self.fast_forward_describe_migration()
await self.start_migration('''
type Obj1;
type Obj2;
''')
# Creations are safe
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'statements': [{
'text':
'CREATE TYPE test::Obj2;'
}],
'data_safe': True,
},
})
await self.fast_forward_describe_migration()
await self.start_migration('''
type Obj1;
''')
# Deletions are NOT safe
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'statements': [{
'text': 'DROP TYPE test::Obj2;'
}],
'data_safe': False,
},
})
await self.fast_forward_describe_migration()
# Renames are safe
await self.start_migration('''
type Obj11;
''')
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'statements': [{
'text': 'ALTER TYPE test::Obj1 RENAME TO test::Obj11;'
}],
'data_safe': True,
},
})
await self.fast_forward_describe_migration()
# Again, creations are safe.
await self.start_migration('''
type Obj11 {
property name -> str {
constraint exclusive;
}
}
''')
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'statements': [{
'text': """
ALTER TYPE test::Obj11 {
CREATE PROPERTY name: std::str {
CREATE CONSTRAINT std::exclusive;
};
};
""",
}],
'data_safe': True,
},
})
await self.fast_forward_describe_migration()
await self.start_migration('''
type Obj11 {
property name -> str;
}
''')
# Dropping constraints is safe.
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'statements': [{
'text': """
ALTER TYPE test::Obj11 {
ALTER PROPERTY name {
DROP CONSTRAINT std::exclusive;
};
};
""",
}],
'data_safe': True,
},
})
await self.fast_forward_describe_migration()
await self.start_migration('''
type Obj11 {
property name -> str {
annotation title := 'name';
}
}
''')
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'statements': [{
'text': """
ALTER TYPE test::Obj11 {
ALTER PROPERTY name {
CREATE ANNOTATION std::title := 'name';
};
};
""",
}],
'data_safe': True,
},
})
await self.fast_forward_describe_migration()
# Dropping annotations is fine also.
await self.start_migration('''
type Obj11 {
property name -> str;
}
''')
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'statements': [{
'text': """
ALTER TYPE test::Obj11 {
ALTER PROPERTY name {
DROP ANNOTATION std::title;
};
};
""",
}],
'data_safe': True,
},
})
await self.fast_forward_describe_migration()
await self.start_migration('''
scalar type foo extending str;
type Obj11 {
property name -> str;
}
''')
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'statements': [{
'text': "CREATE SCALAR TYPE test::foo EXTENDING std::str;",
}],
'data_safe': True,
},
})
await self.fast_forward_describe_migration()
# Dropping scalar types is fine also.
await self.start_migration('''
type Obj11 {
property name -> str;
}
''')
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'statements': [{
'text': "DROP SCALAR TYPE test::foo;",
}],
'data_safe': True,
},
})
await self.fast_forward_describe_migration()
await self.start_migration('''
type Obj11 {
property name -> str;
index on (.name);
}
''')
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'statements': [{
'text': """
ALTER TYPE test::Obj11 {
CREATE INDEX ON (.name);
};
""",
}],
'data_safe': True,
},
})
await self.fast_forward_describe_migration()
# Dropping indexes is fine also.
await self.start_migration('''
type Obj11 {
property name -> str;
}
''')
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'statements': [{
'text': """
ALTER TYPE test::Obj11 {
DROP INDEX ON (.name);
};
""",
}],
'data_safe': True,
},
})
await self.fast_forward_describe_migration()
# Changing single to multi is fine.
await self.start_migration('''
type Obj11 {
multi property name -> str;
}
''')
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'statements': [{
'text': """
ALTER TYPE test::Obj11 {
ALTER PROPERTY name {
SET MULTI;
};
};
""",
}],
'data_safe': True,
},
})
await self.fast_forward_describe_migration()
# But changing multi to single is NOT
await self.start_migration('''
type Obj11 {
single property name -> str;
}
''')
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'statements': [{
'text': r"""
ALTER TYPE test::Obj11 {
ALTER PROPERTY name {
SET SINGLE USING (\(conv_expr));
};
};
""",
}],
'data_safe': False,
},
})
await self.fast_forward_describe_migration(
user_input=[
'(SELECT .name LIMIT 1)'
]
)
# And changing a property to computed is NOT!
await self.start_migration('''
type Obj11 {
single property name := "test";
}
''')
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'data_safe': False,
},
})
await self.fast_forward_describe_migration()
# But just changing a computed is
await self.start_migration('''
type Obj11 {
single property name := "fffff";
}
''')
await self.assert_describe_migration({
'confirmed': [],
'proposed': {
'data_safe': True,
},
})
await self.fast_forward_describe_migration() | )
await self.fast_forward_describe_migration()
await self.start_migration( | test_edgeql_migration_data_safety_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_prompt_id_01(self):
await self.start_migration('''
type Bar { link spam -> Spam };
type Spam { link bar -> Bar };
''')
await self.assert_describe_migration({
'proposed': {
'prompt_id': 'CreateObjectType TYPE test::Bar',
'statements': [{
'text': 'CREATE TYPE test::Bar;'
}],
'confidence': 1.0,
},
})
await self.fast_forward_describe_migration(limit=1)
await self.assert_describe_migration({
'proposed': {
'prompt_id': 'CreateObjectType TYPE test::Spam',
'statements': [{
'text': """
CREATE TYPE test::Spam {
CREATE LINK bar: test::Bar;
};
""",
}],
'confidence': 1.0,
},
})
await self.fast_forward_describe_migration(limit=1)
# N.B: It is important that the prompt_id here match the
# prompt_id in the first migration, so that the migration tool
# will automatically apply this proposal as part of the
# earlier action.
await self.assert_describe_migration({
'proposed': {
'prompt_id': 'CreateObjectType TYPE test::Bar',
'statements': [{
'text': """
ALTER TYPE test::Bar {
CREATE LINK spam: test::Spam;
};
""",
}],
'confidence': 1.0,
},
}) | )
await self.assert_describe_migration({
'proposed': {
'prompt_id': 'CreateObjectType TYPE test::Bar',
'statements': [{
'text': 'CREATE TYPE test::Bar;'
}],
'confidence': 1.0,
},
})
await self.fast_forward_describe_migration(limit=1)
await self.assert_describe_migration({
'proposed': {
'prompt_id': 'CreateObjectType TYPE test::Spam',
'statements': [{
'text': | test_edgeql_migration_prompt_id_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_user_input_01(self):
await self.migrate('''
type Bar { property foo -> str };
''')
await self.start_migration('''
type Bar { property foo -> int64 };
''')
await self.assert_describe_migration({
'proposed': {
'statements': [{
'text': '''
ALTER TYPE test::Bar {
ALTER PROPERTY foo {
SET TYPE std::int64 USING (\\(cast_expr));
};
};
'''
}],
'required_user_input': [{
'placeholder': 'cast_expr',
'prompt': (
"Please specify a conversion expression"
" to alter the type of property 'foo'"
),
'old_type': 'std::str',
'new_type': 'std::int64',
'pointer_name': 'foo',
}],
},
}) | )
await self.start_migration( | test_edgeql_migration_user_input_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_user_input_02(self):
await self.migrate('''
type Bar { multi property foo -> str };
''')
await self.start_migration('''
type Bar { single property foo -> str };
''')
await self.assert_describe_migration({
'proposed': {
'statements': [{
'text': '''
ALTER TYPE test::Bar {
ALTER PROPERTY foo {
SET SINGLE USING (\\(conv_expr));
};
};
'''
}],
'required_user_input': [{
'placeholder': 'conv_expr',
'prompt': (
"Please specify an expression in order to convert"
" property 'foo' of object type 'test::Bar' to"
" 'single' cardinality"
),
'type': 'std::str',
'pointer_name': 'foo',
}],
},
}) | )
await self.start_migration( | test_edgeql_migration_user_input_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_user_input_03(self):
await self.migrate('''
type Bar {
required property foo -> int64;
};
''')
await self.con.execute('''
SET MODULE test;
INSERT Bar { foo := 42 };
INSERT Bar { foo := 1337 };
''')
await self.start_migration('''
type Bar {
required property foo -> int64;
required property bar -> str;
};
''')
await self.assert_describe_migration({
'proposed': {
'statements': [{
'text': '''
ALTER TYPE test::Bar {
CREATE REQUIRED PROPERTY bar: std::str {
SET REQUIRED USING (\\(fill_expr));
};
};
'''
}],
'required_user_input': [{
'placeholder': 'fill_expr',
'prompt': (
"Please specify an expression to populate existing "
"objects in order to make property 'bar' of object "
"type 'test::Bar' required"
),
'type': 'std::str',
'pointer_name': 'bar',
}],
},
})
await self.fast_forward_describe_migration(
user_input=[
'<str>.foo ++ "!"'
]
)
await self.assert_query_result(
'''
SELECT Bar {foo, bar} ORDER BY .foo
''',
[
{'foo': 42, 'bar': "42!"},
{'foo': 1337, 'bar': "1337!"},
],
) | )
await self.con.execute( | test_edgeql_migration_user_input_03 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_user_input_04(self):
await self.migrate('''
type BlogPost {
property title -> str;
}
''')
await self.con.execute('''
SET MODULE test;
INSERT BlogPost { title := "Programming Considered Harmful" }
''')
await self.start_migration('''
abstract type HasContent {
required property content -> str;
}
type BlogPost extending HasContent {
property title -> str;
}
''')
await self.interact([
"did you create object type 'test::HasContent'?",
("did you alter object type 'test::BlogPost'?", "y",
'"This page intentionally left blank"'),
# XXX: There is a final follow-up prompt, since the DDL
# generated above somewhat wrongly leaves 'content' owned
# by the child. This is kind of wrong, but also *works*, so
# maybe it's fine for now.
"did you alter property 'content' of object type "
"'test::BlogPost'?",
])
await self.fast_forward_describe_migration()
await self.assert_query_result(
'''
SELECT BlogPost {title, content}
''',
[
{
'title': "Programming Considered Harmful",
'content': "This page intentionally left blank",
},
],
) | )
await self.con.execute( | test_edgeql_migration_user_input_04 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_user_input_05(self):
await self.migrate(
'''
type Organization {
required property name -> str;
}
type Department {
required property name -> str;
}
'''
)
await self.start_migration(
'''
type Organization {
required property name -> str;
}
type Department {
required link org -> Organization;
};
'''
)
await self.fast_forward_describe_migration(
user_input=[
'insert test::Organization { name := "default" }'
]
) | type Organization {
required property name -> str;
}
type Department {
required property name -> str;
} | test_edgeql_migration_user_input_05 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_user_input_06(self):
await self.migrate('''
type Bar {
property foo -> int64;
};
''')
await self.con.execute('''
SET MODULE test;
INSERT Bar { foo := 42 };
INSERT Bar;
''')
await self.start_migration('''
type Bar {
required property foo -> str;
};
''')
await self.assert_describe_migration({
'proposed': {
'required_user_input': [
{
'placeholder': 'fill_expr',
'type': 'std::int64',
},
{
'placeholder': 'cast_expr',
'old_type': 'std::int64',
'new_type': 'std::str',
},
],
},
})
await self.fast_forward_describe_migration(
user_input=[
"0",
"<str>.foo",
]
)
await self.assert_query_result(
'''
SELECT Bar {foo} ORDER BY .foo
''',
[
{'foo': "0"},
{'foo': "42"},
],
) | )
await self.con.execute( | test_edgeql_migration_user_input_06 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_backlink_01(self):
await self.migrate('''
type User {
link posts := .<user;
}
abstract type Action {
required link user -> User;
}
type Post extending Action;
''')
# Make sure that the objects can actually be created and
# queried.
await self.con.execute('''
SET MODULE test;
INSERT User;
''')
post = await self.con.query_single('''
INSERT Post {
user := (SELECT User LIMIT 1),
};
''')
await self.assert_query_result(
r'''
SELECT User{
id,
posts: {
id
} LIMIT 1 # this LIMIT is needed as a workaround
# for another bug
}
''',
[
{
'posts': [{'id': str(post.id)}],
},
],
) | )
# Make sure that the objects can actually be created and
# queried.
await self.con.execute( | test_edgeql_migration_backlink_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_misplaced_commands(self):
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute ALTER CURRENT MIGRATION"
r" outside of a migration block",
):
await self.con.execute('''
ALTER CURRENT MIGRATION REJECT PROPOSED;
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute DESCRIBE CURRENT MIGRATION"
r" outside of a migration block",
):
await self.con.execute('''
DESCRIBE CURRENT MIGRATION;
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute COMMIT MIGRATION"
r" outside of a migration block",
):
await self.con.execute('''
COMMIT MIGRATION;
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute ABORT MIGRATION"
r" outside of a migration block",
):
await self.con.execute('''
ABORT MIGRATION;
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute POPULATE MIGRATION"
r" outside of a migration block",
):
await self.con.execute('''
POPULATE MIGRATION;
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute CREATE DATABASE"
r" in a migration block",
):
await self.start_migration('type Foo;')
await self.con.execute('''
CREATE DATABASE should_not_happen;
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute CREATE ROLE"
r" in a migration block",
):
await self.start_migration('type Foo;')
await self.con.execute('''
CREATE ROLE should_not_happen;
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute CREATE MIGRATION"
r" in a migration block",
):
await self.start_migration('type Foo;')
await self.con.execute('''
CREATE MIGRATION blah;
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute START MIGRATION"
r" in a migration block",
):
await self.start_migration('type Foo;')
await self.con.execute('''
START MIGRATION TO { module test { type Foo; }};
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute START TRANSACTION"
r" in a migration block",
):
await self.start_migration('type Foo;')
await self.con.query('''
START TRANSACTION;
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute START TRANSACTION"
r" in a migration block",
):
await self.start_migration('type Foo;')
await self.con.query('''
START TRANSACTION;
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute CONFIGURE INSTANCE"
r" in a migration block",
):
await self.start_migration('type Foo;')
await self.con.execute('''
CONFIGURE INSTANCE SET _foo := 123;
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute CONFIGURE DATABASE"
r" in a migration block",
):
await self.start_migration('type Foo;')
await self.con.execute('''
CONFIGURE CURRENT DATABASE SET _foo := 123;
''') | )
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"cannot execute DESCRIBE CURRENT MIGRATION"
r" outside of a migration block",
):
await self.con.execute( | test_edgeql_migration_misplaced_commands | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_alias_01(self):
await self.migrate(r'''
type Foo {
property name -> str;
property comp := Alias;
};
alias Alias := {0, 1, 2, 3};
''')
# Make sure that the objects can actually be created and
# queried.
await self.con.execute('''
SET MODULE test;
INSERT Foo {name := 'foo'};
''')
await self.assert_query_result(
r'''
SELECT Foo {
name,
comp,
}
''',
[
{
'name': 'foo',
'comp': {0, 1, 2, 3},
},
],
) | )
# Make sure that the objects can actually be created and
# queried.
await self.con.execute( | test_edgeql_migration_alias_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_alias_02(self):
await self.migrate(r'''
type Foo {
property name -> str;
property comp := Alias + 0;
};
alias Alias := {0, 1, 2, 3};
''')
# Make sure that the objects can actually be created and
# queried.
await self.con.execute('''
SET MODULE test;
INSERT Foo {name := 'foo'};
''')
await self.assert_query_result(
r'''
SELECT Foo {
name,
comp,
}
''',
[
{
'name': 'foo',
'comp': {0, 1, 2, 3},
},
],
)
await self.migrate(r'''
type Foo {
property name -> str;
property comp := Alias + 0;
};
alias Alias := {4, 5};
''')
await self.assert_query_result(
r'''
SELECT Foo {
name,
comp,
}
''',
[
{
'name': 'foo',
'comp': {4, 5},
},
],
) | )
# Make sure that the objects can actually be created and
# queried.
await self.con.execute( | test_edgeql_migration_alias_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_alias_03(self):
await self.migrate(r'''
type Foo {
property name -> str;
property comp := {Alias, Alias};
};
alias Alias := 42;
''')
# Make sure that the objects can actually be created and
# queried.
await self.con.execute('''
SET MODULE test;
INSERT Foo {name := 'foo'};
''')
await self.assert_query_result(
r'''
SELECT Foo {
name,
comp,
}
''',
[
{
'name': 'foo',
'comp': [42, 42],
},
],
)
await self.migrate(r'''
type Foo {
property name -> str;
property comp := {Alias, Alias};
};
alias Alias := 'alias';
''')
await self.assert_query_result(
r'''
SELECT Foo {
name,
comp,
}
''',
[
{
'name': 'foo',
'comp': ['alias', 'alias'],
},
],
) | )
# Make sure that the objects can actually be created and
# queried.
await self.con.execute( | test_edgeql_migration_alias_03 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_alias_04(self):
# Same as the previous test, but using a single DDL command to
# migrate.
await self.migrate(r'''
type Foo {
property name -> str;
property comp := {Alias, Alias};
};
alias Alias := 42;
''')
# Make sure that the objects can actually be created and
# queried.
await self.con.execute('''
SET MODULE test;
INSERT Foo {name := 'foo'};
''')
await self.assert_query_result(
r'''
SELECT Foo {
name,
comp,
}
''',
[
{
'name': 'foo',
'comp': [42, 42],
},
],
)
# Instead of using an SDL migration, use a single DDL command.
await self.con.execute('''
ALTER ALIAS Alias USING ('alias');
''')
await self.assert_query_result(
r'''
SELECT Foo {
name,
comp,
}
''',
[
{
'name': 'foo',
'comp': ['alias', 'alias'],
},
],
) | )
# Make sure that the objects can actually be created and
# queried.
await self.con.execute( | test_edgeql_migration_alias_04 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_alias_05(self):
await self.migrate(r'''
type Foo {
property name -> str;
link comp := Alias;
};
type Bar;
alias Alias := Bar {val := 42};
''')
# Make sure that the objects can actually be created and
# queried.
await self.con.execute('''
SET MODULE test;
INSERT Bar;
INSERT Foo {name := 'foo'};
''')
await self.assert_query_result(
r'''
SELECT Foo {
name,
comp: {
val
},
}
''',
[
{
'name': 'foo',
'comp': {
'val': 42,
},
},
],
) | )
# Make sure that the objects can actually be created and
# queried.
await self.con.execute( | test_edgeql_migration_alias_05 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_alias_06(self):
await self.migrate(r'''
type Foo {
property name -> str;
property comp := Alias.val;
};
type Bar;
alias Alias := Bar {val := 42};
''')
# Make sure that the objects can actually be created and
# queried.
await self.con.execute('''
SET MODULE test;
INSERT Bar;
INSERT Foo {name := 'foo'};
''')
await self.assert_query_result(
r'''
SELECT Foo {
name,
comp,
}
''',
[
{
'name': 'foo',
'comp': {42},
},
],
)
await self.migrate(r'''
type Foo {
property name -> str;
property comp := Alias.val;
};
type Bar;
alias Alias := Bar {val := 'val'};
''')
await self.assert_query_result(
r'''
SELECT Foo {
name,
comp,
}
''',
[
{
'name': 'foo',
'comp': {'val'},
},
],
) | )
# Make sure that the objects can actually be created and
# queried.
await self.con.execute( | test_edgeql_migration_alias_06 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_alias_07(self):
await self.migrate(r'''
type Foo {
property name -> str;
link comp := Alias.alias_link;
};
type Bar {
property val -> str;
};
type Fuz {
property val -> str;
};
alias Alias := Bar {
alias_link := Fuz {
alias_comp := 42,
}
};
''')
# Make sure that the objects can actually be created and
# queried.
await self.con.execute('''
SET MODULE test;
INSERT Bar {val := 'bar'};
INSERT Fuz {val := 'fuz'};
INSERT Foo {name := 'foo'};
''')
await self.assert_query_result(
r'''
SELECT Foo {
name,
comp: {
val,
alias_comp,
},
}
''',
[
{
'name': 'foo',
'comp': [{
'val': 'fuz',
'alais_comp': 42,
}],
},
],
)
await self.migrate(r'''
type Foo {
property name -> str;
link comp := Alias.alias_link;
};
type Bar {
property val -> str;
};
type Fuz {
property val -> str;
};
alias Alias := Bar {
alias_link := Fuz {
alias_comp := 42,
}
};
''')
await self.assert_query_result(
r'''
SELECT Foo {
name,
comp: {
val
},
}
''',
[
{
'name': 'foo',
'comp': [{
'val': 'bar',
'alais_comp': 42,
}],
},
],
) | )
# Make sure that the objects can actually be created and
# queried.
await self.con.execute( | test_edgeql_migration_alias_07 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_alias_08(self):
await self.migrate(r'''
type Foo;
type Bar;
alias X := Foo;
''')
await self.migrate(r'''
type Foo;
type Bar;
alias X := Bar;
''')
await self.migrate(r'''
type Foo;
type Bar;
alias X := 30;
''')
await self.migrate(r'''
type Foo;
type Bar;
alias X := "30";
''')
await self.migrate(r'''
type Foo;
type Bar;
alias X := (Bar { z := 10 }, 30);
''')
await self.migrate(r'''
type Foo;
type Bar;
alias X := ((Bar { z := 10 }, 30), 20);
''')
# delete it
await self.migrate(r'''
type Foo;
type Bar;
''') | )
await self.migrate(r | test_edgeql_migration_alias_08 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_alias_09(self):
await self.migrate(r'''
type Foo;
type Bar;
alias X := Foo { bar := Bar { z := 1 } };
''')
await self.migrate(r'''
type Foo;
type Bar;
alias X := Bar;
''') | )
await self.migrate(r | test_edgeql_migration_alias_09 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_tuple_01(self):
await self.migrate(r'''
type Bag {
property switching_tuple -> tuple<name: str, weight: int64>;
};
''')
with self.assertRaisesRegex(
AssertionError,
r"Please specify a conversion expression to alter the type of "
r"property 'switching_tuple'"
):
await self.migrate(r'''
type Bag {
property switching_tuple -> tuple<name: str, age: int64>;
};
''') | )
with self.assertRaisesRegex(
AssertionError,
r"Please specify a conversion expression to alter the type of "
r"property 'switching_tuple'"
):
await self.migrate(r | test_edgeql_migration_tuple_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_drop_constraint_01(self):
await self.migrate(r'''
abstract type Named {
required property name -> str {
delegated constraint exclusive;
}
}
type User {
link avatar -> Card {
property text -> str;
property tag := .name ++ (("-" ++ @text) ?? "");
}
}
type Card extending Named;
type SpecialCard extending Card;
''')
await self.migrate(r'''
abstract type Named {
required property name -> str;
}
type User {
link avatar -> Card {
property text -> str;
property tag := .name ++ (("-" ++ @text) ?? "");
}
}
type Card extending Named;
type SpecialCard extending Card;
''') | )
await self.migrate(r | test_edgeql_migration_drop_constraint_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_drop_constraint_02(self):
await self.migrate(r'''
abstract type Named {
required property name -> str {
delegated constraint exclusive;
}
}
type User {
link avatar -> Card {
property text -> str;
property tag := .name ++ (("-" ++ @text) ?? "");
}
}
type Card extending Named;
type SpecialCard extending Card;
type SpecialCard2 extending Card;
type VerySpecialCard extending SpecialCard, SpecialCard2;
''')
await self.migrate(r'''
abstract type Named {
required property name -> str;
}
type User {
link avatar -> Card {
property text -> str;
property tag := .name ++ (("-" ++ @text) ?? "");
}
}
type Card extending Named;
type SpecialCard extending Card;
type SpecialCard2 extending Card;
type VerySpecialCard extending SpecialCard, SpecialCard2;
''') | )
await self.migrate(r | test_edgeql_migration_drop_constraint_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_drop_constraint_03(self):
await self.migrate(r'''
type C {
required property val -> str {
constraint exclusive;
}
}
type Foo {
required link foo -> C {
default := (SELECT C FILTER .val = 'D00');
}
}
''')
await self.migrate(r'''
type Foo {
required link foo -> C {
default := (SELECT C FILTER .val = 'D00');
}
}
type C {
required property val -> str {
constraint exclusive;
}
}
''')
await self.migrate('') | )
await self.migrate(r | test_edgeql_migration_drop_constraint_03 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_drop_constraint_04(self):
await self.migrate(r'''
type C {
required property val -> str {
constraint exclusive;
}
}
type Foo {
required link foo -> C {
default := (SELECT C FILTER .val = 'D00');
}
}
''')
await self.migrate(r'''
type C {
required property val -> str;
}
type Foo {
required multi link foo -> C {
default := (SELECT C FILTER .val = 'D00');
}
}
''') | )
await self.migrate(r | test_edgeql_migration_drop_constraint_04 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_drop_constraint_05(self):
await self.migrate(r'''
type C {
required property val -> str {
constraint exclusive;
}
required property val2 -> str {
constraint exclusive;
}
}
type Foo {
required link foo -> C {
default := (SELECT C FILTER .val = 'D00');
}
}
''')
await self.migrate(r'''
type C {
required property val2 -> str {
constraint exclusive;
}
}
type Foo {
required link foo -> C {
default := (SELECT C FILTER .val2 = 'D00');
}
}
''') | )
await self.migrate(r | test_edgeql_migration_drop_constraint_05 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_fiddly_delete_01(self):
await self.migrate(r'''
type Document {
multi link entries -> Entry {
constraint exclusive;
}
multi link fields := .entries.field;
required link form -> Form;
}
type Entry {
required link field -> Field;
required property value -> str;
link form := .field.form;
}
type Field {
required property name -> str;
link form := .<fields[IS Form];
}
type Form {
required property name -> str {
constraint exclusive;
}
multi link fields -> Field;
}
''')
await self.migrate(r'''
type Entry {
required link field -> Field;
required property value -> str;
link form := .field.form;
}
type Field {
required property name -> str;
link form := .<fields[IS Form];
}
type Form {
required property name -> str {
constraint exclusive;
}
multi link fields -> Field;
}
''') | )
await self.migrate(r | test_edgeql_migration_fiddly_delete_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_on_target_delete_01(self):
await self.migrate(
r"""
type User {
multi link workspaces -> Workspace {
property title -> str;
on target delete allow;
}
}
type Workspace {
multi link users := .<workspaces[is User];
}
"""
)
await self.migrate(
r"""
type User {
multi link workspaces := .<users[is Workspace];
}
type Workspace {
multi link users -> User {
property title -> str;
on target delete allow;
}
}
"""
) | )
await self.migrate(
r | test_edgeql_migration_on_target_delete_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_on_target_delete_02(self):
await self.migrate(
r"""
type Tgt;
type Foo {
link tgt -> Tgt {
on target delete allow;
}
}
type Bar extending Foo {
overloaded link tgt -> Tgt {
on target delete restrict;
}
}
"""
)
await self.con.execute("""
with module test
insert Bar { tgt := (insert Tgt) };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
'prohibited by link target policy',
):
await self.con.execute("""
with module test
delete Tgt;
""")
await self.migrate(
r"""
type Tgt;
type Foo {
link tgt -> Tgt {
on target delete allow;
}
}
type Bar extending Foo;
"""
)
await self.con.execute("""
with module test
delete Tgt;
""") | )
await self.con.execute( | test_edgeql_migration_on_target_delete_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_rename_with_stuff_01(self):
await self.migrate(
r"""
type Base {
property x -> str;
property xbang := .x ++ "!";
}
type NamedObject extending Base {
required property foo -> str;
}
"""
)
await self.migrate(
r"""
type Base {
property x -> str;
property xbang := .x ++ "!";
}
type ReNamedObject extending Base {
required property foo -> str;
}
"""
) | )
await self.migrate(
r | test_edgeql_migration_rename_with_stuff_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_access_policy_01(self):
await self.migrate(r"""
type Test2 {
access policy asdf allow all using (true);
}
""")
await self.migrate(r"""
type Test2 {
access policy asdf allow all;
}
""")
await self.migrate(r"""
abstract type Parent {
access policy asdf allow all;
}
type Test2 extending Parent;
""")
await self.migrate(r"""
abstract type Parent {
access policy asdf when (true) allow all;
}
type Test2 extending Parent;
""") | )
await self.migrate(r | test_edgeql_migration_access_policy_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_globals_02(self):
await self.migrate(r"""
global current_user_id -> uuid;
global current_user := (
select Member filter .id = global current_user_id
);
type Foo;
type Base {
link avatar -> Foo {
constraint exclusive;
}
}
type Member;
""")
schema = r"""
global current_user_id -> uuid;
global current_user := (
select Member filter .id = global current_user_id
);
type Foo;
type Base {
link avatar -> Foo {
constraint exclusive;
}
}
type Member extending Base;
"""
# Make sure it doesn't get into a wedged state
await self.migrate(schema)
await self.migrate(schema) | )
schema = r | test_edgeql_migration_globals_02 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_globals_03(self):
# Test modifying a computed global that is used in an access
# policy on the type it refers to.
await self.migrate(r"""
global cur -> uuid;
global scopes := ((select Foo filter .id = global cur).scopes);
type Foo {
multi scopes: str;
access policy s allow select using ('f' in global scopes);
};
""")
await self.migrate(r"""
global cur -> uuid;
global scopes := (
select (select Foo filter .id = global cur).scopes);
type Foo {
multi scopes: str;
access policy s allow select using ('f' in global scopes);
};
""") | )
await self.migrate(r | test_edgeql_migration_globals_03 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_globals_04(self):
await self.migrate(r"""
global cur := true;
type Foo {
access policy s allow select using (global cur);
};
type Bar {
access policy s allow select using (global cur);
};
""")
await self.migrate(r"""
global ok := (exists Foo);
global cur := global ok;
type Foo {
access policy s allow select using (global cur);
};
type Bar {
access policy s allow select using (global cur);
};
""") | )
await self.migrate(r | test_edgeql_migration_globals_04 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_dml_rewrites_01(self):
await self.migrate(r"""
type Post {
required title: str;
modified: datetime {
rewrite insert, update using (datetime_of_statement())
}
}
""")
await self.migrate(r"""
type BlogPost {
required title: str;
modified: datetime {
rewrite insert, update using (datetime_of_statement())
}
}
""")
await self.migrate(r"""
type BlogPost {
required title: str;
modified: datetime {
rewrite insert, update using (datetime_of_transaction())
}
}
""")
await self.migrate('') | )
await self.migrate(r | test_edgeql_migration_dml_rewrites_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_policies_and_collections(self):
# An infinite recursion bug with this this was found by accident
# when a number of tests accidentally were in the non isolated test.
# (Simplified a bit.)
await self.migrate(r"""
abstract type Base {
access policy locked allow all using (false);
}
type Src {
required link tgt -> Base {
constraint exclusive;
}
}
""")
await self.migrate(r"""
alias Foo := 20;
""") | )
await self.migrate(r | test_edgeql_migration_policies_and_collections | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_drop_required_01(self):
await self.migrate(r"""
abstract type AbstractLinkTarget {
multi link linkSources := .<abstractTarget[is LinkSource];
}
type ImplementationType extending AbstractLinkTarget {}
type LinkSource {
required link abstractTarget -> AbstractLinkTarget;
}
""")
await self.migrate(r"""
abstract type AbstractLinkTarget {
multi link linkSources := .<abstractTarget[is LinkSource];
}
type ImplementationType extending AbstractLinkTarget {}
type LinkSource {
link abstractTarget -> AbstractLinkTarget;
}
""") | )
await self.migrate(r | test_edgeql_migration_drop_required_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_link_to_sub_with_ref_01(self):
# Test moving a link to a subtype while a ref exists to it
await self.migrate(r"""
type Athlete {
multi link schedules := Athlete.<owner[IS AthleteSchedule];
}
abstract type Schedule {
required property name -> str;
required link owner -> Athlete;
}
type AthleteSchedule extending Schedule;
""")
await self.migrate(r"""
type Athlete {
multi link schedules := Athlete.<owner[IS AthleteSchedule];
}
abstract type Schedule {
required property name -> str;
}
type AthleteSchedule extending Schedule {
required link owner -> Athlete;
}
""") | )
await self.migrate(r | test_edgeql_migration_link_to_sub_with_ref_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_lift_01(self):
await self.migrate(r"""
abstract type A;
abstract type B;
abstract type Foo extending A;
type Bar extending Foo, B;
""")
await self.migrate(r"""
abstract type A;
abstract type B;
abstract type Foo extending A, B;
type Bar extending Foo;
""") | )
await self.migrate(r | test_edgeql_migration_lift_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_nested_backticks_01(self):
await self.migrate(r"""
module nested { type Test };
""")
await self.migrate(r"""
module nested { type Test };
module `back``ticked` { type Test };
""") | )
await self.migrate(r | test_edgeql_migration_nested_backticks_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_abstract_index_01(self):
await self.migrate(
r"""
abstract index MyIndex extending fts::index;
type Base {
property name -> str;
index MyIndex on (
fts::with_options(.name, language := fts::Language.eng)
);
};
"""
)
await self.migrate(
r"""
abstract index MyIndex extending fts::index;
type Base {
property name -> str;
index MyIndex on (
fts::with_options(.name, language := fts::Language.eng)
);
};
type Child extending Base;
"""
)
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"because other objects in the schema depend on it"):
await self.con.execute('''
drop abstract index test::MyIndex
''')
await self.migrate(
r"""
abstract index MyIndex extending fts::index;
type Base {
property name -> str;
index MyIndex on (
fts::with_options(.name, language := fts::Language.eng)
);
};
type Child extending Base;
"""
)
await self.migrate(
r"""
abstract index MyIndex extending fts::index {
annotation title := "test";
}
type Base {
property name -> str;
index MyIndex on (
fts::with_options(.name, language := fts::Language.eng)
);
};
type Child extending Base;
"""
)
await self.migrate("") | )
await self.migrate(
r | test_edgeql_migration_abstract_index_01 | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
async def test_edgeql_migration_property_ref(self):
await self.migrate(r'''
type Log {
body: str;
timestamp: datetime {
default := datetime_current();
}
}
type Person {
required name: str;
trigger log_delete after insert for each
when (__new__.name not like "SKIP%") do (
insert Log { body := __new__.name }
);
}
''')
await self.migrate(r'''
type Log {
body: str;
}
type Person {
required name: str;
trigger log_delete after insert for each
when (false) do (
insert Log { body := __new__.name }
);
}
''') | )
await self.migrate(r | test_edgeql_migration_property_ref | python | geldata/gel | tests/test_edgeql_data_migration.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.