Skip to content

Commit

Permalink
Actually add full text indexes when processing schema changes that re…
Browse files Browse the repository at this point in the history
…quire them (#6823)
  • Loading branch information
jbreams authored Jul 25, 2023
1 parent fdf34f4 commit 5e87cf3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* None.

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
* Trying to search a full-text indexes created as a result of an additive schema change (i.e. applying the differences between the local schema and a synchronized realm's schema) could have resulted in an IllegalOperation error with the error code `Column has no fulltext index`. ([PR #6823](https://github.com/realm/realm-core/pull/6823)).
* None.

### Breaking changes
Expand Down
5 changes: 3 additions & 2 deletions src/realm/object-store/object_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,9 @@ void ObjectStore::apply_additive_changes(Group& group, std::vector<SchemaChange>
}
void operator()(AddIndex op)
{
if (update_indexes)
table(op.object).add_search_index(op.property->column_key);
if (update_indexes) {
add_search_index(table(op.object), *op.property, op.type);
}
}
void operator()(RemoveIndex op)
{
Expand Down
62 changes: 62 additions & 0 deletions test/object-store/sync/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ using util::any_cast;
using util::Optional;

using namespace std::string_view_literals;
using namespace std::literals::string_literals;

namespace {
std::shared_ptr<SyncUser> log_in(std::shared_ptr<App> app, AppCredentials credentials = AppCredentials::anonymous())
Expand Down Expand Up @@ -3517,6 +3518,67 @@ TEMPLATE_TEST_CASE("app: partition types", "[sync][pbs][app][partition][baas]",
}
}

TEST_CASE("app: full-text compatible with sync", "[sync][app]") {
std::string base_url = get_base_url();
const std::string valid_pk_name = "_id";
REQUIRE(!base_url.empty());

Schema schema{
{"TopLevel",
{
{valid_pk_name, PropertyType::ObjectId, Property::IsPrimary{true}},
{"full_text", Property::IsFulltextIndexed{true}},
}},
};

auto server_app_config = minimal_app_config(base_url, "full_text", schema);
auto app_session = create_app(server_app_config);
const auto partition = random_string(100);
TestAppSession test_session(app_session, nullptr);
SyncTestFile config(test_session.app(), partition, schema);
SharedRealm realm;
SECTION("sync open") {
INFO("realm opened without async open");
realm = Realm::get_shared_realm(config);
}
SECTION("async open") {
INFO("realm opened with async open");
auto async_open_task = Realm::get_synchronized_realm(config);

auto [realm_promise, realm_future] = util::make_promise_future<ThreadSafeReference>();
async_open_task->start(
[promise = std::move(realm_promise)](ThreadSafeReference ref, std::exception_ptr ouch) mutable {
if (ouch) {
try {
std::rethrow_exception(ouch);
}
catch (...) {
promise.set_error(exception_to_status());
}
}
else {
promise.emplace_value(std::move(ref));
}
});

realm = Realm::get_shared_realm(std::move(realm_future.get()));
}

CppContext c(realm);
auto obj_id_1 = ObjectId::gen();
auto obj_id_2 = ObjectId::gen();
realm->begin_transaction();
Object::create(c, realm, "TopLevel", std::any(AnyDict{{"_id", obj_id_1}, {"full_text", "Hello, world!"s}}));
Object::create(c, realm, "TopLevel", std::any(AnyDict{{"_id", obj_id_2}, {"full_text", "Hello, everyone!"s}}));
realm->commit_transaction();

auto table = realm->read_group().get_table("class_TopLevel");
REQUIRE(table->search_index_type(table->get_column_key("full_text")) == IndexType::Fulltext);
Results world_results(realm, Query(table).fulltext(table->get_column_key("full_text"), "world"));
REQUIRE(world_results.size() == 1);
REQUIRE(world_results.get<Obj>(0).get_primary_key() == Mixed{obj_id_1});
}

#endif // REALM_ENABLE_AUTH_TESTS

TEST_CASE("app: custom error handling", "[sync][app][custom errors][baas]") {
Expand Down

0 comments on commit 5e87cf3

Please sign in to comment.