Skip to content

Commit 5de8d14

Browse files
committed
Add a test for FTS indexes upgraded from old buggy versions
1 parent 82525bd commit 5de8d14

File tree

5 files changed

+113
-14
lines changed

5 files changed

+113
-14
lines changed

.github/scripts/patches/create-databases.py

+25-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Create databases on the older edgedb version
22

33
import edgedb
4+
5+
import os
46
import subprocess
57
import sys
68

@@ -10,13 +12,27 @@
1012
]
1113
proc = subprocess.Popen(cmd)
1214

15+
def migrate(con, filename):
16+
with open(os.path.join("tests/schemas/", filename)) as f:
17+
body = f.read()
18+
con.execute(f'''
19+
START MIGRATION TO {{
20+
module default {{
21+
{body}
22+
}}
23+
}};
24+
POPULATE MIGRATION;
25+
COMMIT MIGRATION;
26+
''')
27+
28+
1329
try:
1430
db = edgedb.create_client(
1531
host='localhost', port=10000, tls_security='insecure'
1632
)
1733
for name in [
1834
'json', 'functions', 'expressions', 'casts', 'policies', 'vector',
19-
'scope', 'httpextauth', 'extai'
35+
'scope', 'httpextauth', 'extai', 'ftsregression'
2036
]:
2137
db.execute(f'create database {name};')
2238

@@ -25,17 +41,7 @@
2541
db2 = edgedb.create_client(
2642
host='localhost', port=10000, tls_security='insecure', database='scope'
2743
)
28-
with open("tests/schemas/cards.esdl") as f:
29-
body = f.read()
30-
db2.execute(f'''
31-
START MIGRATION TO {{
32-
module default {{
33-
{body}
34-
}}
35-
}};
36-
POPULATE MIGRATION;
37-
COMMIT MIGRATION;
38-
''')
44+
migrate(db2, "cards.esdl")
3945

4046
# Put something in the query cache
4147
db2.query(r'''
@@ -48,6 +54,13 @@
4854

4955
db2.close()
5056

57+
db2 = edgedb.create_client(
58+
host='localhost', port=10000, tls_security='insecure',
59+
database='ftsregression'
60+
)
61+
migrate(db2, "fts_regression.esdl")
62+
db2.close()
63+
5164
# Compile a query from the CLI.
5265
# (At one point, having a cached query with proto version 1 caused
5366
# trouble...)

.github/workflows.src/tests-patches.tpl.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
# has timeouts.
6363
edb server --bootstrap-only --data-dir test-dir
6464
# Should we run *all* the tests?
65-
edb test -j2 -v --data-dir test-dir tests/test_edgeql_json.py tests/test_edgeql_casts.py tests/test_edgeql_functions.py tests/test_edgeql_expressions.py tests/test_edgeql_policies.py tests/test_edgeql_vector.py tests/test_edgeql_scope.py tests/test_http_ext_auth.py tests/test_ext_ai.py
65+
edb test -j2 -v --data-dir test-dir tests/test_edgeql_json.py tests/test_edgeql_casts.py tests/test_edgeql_functions.py tests/test_edgeql_expressions.py tests/test_edgeql_policies.py tests/test_edgeql_vector.py tests/test_edgeql_scope.py tests/test_http_ext_auth.py tests/test_ext_ai.py tests/test_edgeql_data_migration.py
6666
6767
- name: Test downgrading a database after an upgrade
6868
if: ${{ !contains(matrix.edgedb-version, '-rc') && !contains(matrix.edgedb-version, '-beta') }}

.github/workflows/tests-patches.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/schemas/fts_regression.esdl

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# This source file is part of the EdgeDB open source project.
3+
#
4+
# Copyright 2016-present MagicStack Inc. and the EdgeDB authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
abstract type Named {
20+
index fts::index on (
21+
std::fts::with_options(
22+
.name, language := std::fts::Language.eng));
23+
required name: std::str;
24+
};
25+
26+
type Project0 extending Named;

tests/test_edgeql_data_migration.py

+60
Original file line numberDiff line numberDiff line change
@@ -13334,3 +13334,63 @@ async def test_edgeql_migration_rewrite_raw_02(self):
1333413334
await self.con.execute(r"""
1333513335
create applied migration { }
1333613336
""")
13337+
13338+
13339+
class TestEdgeQLFtsRegression(EdgeQLDataMigrationTestCase):
13340+
PARALLELISM_GRANULARITY = 'default'
13341+
13342+
SCHEMA = os.path.join(os.path.dirname(__file__), 'schemas',
13343+
'fts_regression.esdl')
13344+
13345+
DEFAULT_MODULE = 'default'
13346+
13347+
async def test_edgeql_fts_regression_01(self):
13348+
await self.start_migration('''
13349+
abstract type Named {
13350+
index std::fts::index on (
13351+
std::fts::with_options(
13352+
.name, language := std::fts::Language.eng));
13353+
required name: std::str;
13354+
};
13355+
13356+
type Project0 extending Named;
13357+
''', module='default')
13358+
13359+
# no changes
13360+
await self.assert_describe_migration({
13361+
'confirmed': [],
13362+
'complete': True,
13363+
})
13364+
13365+
13366+
async def test_edgeql_fts_regression_02(self):
13367+
await self.migrate('''
13368+
abstract type Named {
13369+
index fts::index on (
13370+
fts::with_options(
13371+
.name, language := std::fts::Language.eng));
13372+
required name: std::str;
13373+
};
13374+
13375+
type Project0 extending Named;
13376+
type Project1 extending Named {
13377+
overloaded name {
13378+
constraint exclusive;
13379+
}
13380+
};
13381+
''', module='default')
13382+
13383+
await self.migrate('', module='default')
13384+
13385+
async def test_edgeql_fts_regression_03(self):
13386+
await self.migrate('', module='default')
13387+
13388+
async def test_edgeql_fts_regression_04(self):
13389+
await self.assert_query_result(
13390+
'''
13391+
select schema::Index { name }
13392+
filter exists .<indexes[is schema::ObjectType]
13393+
and .name like '%index';
13394+
''',
13395+
[{"name": "std::fts::index"}, {"name": "std::fts::index"}]
13396+
)

0 commit comments

Comments
 (0)