diff --git a/src/shared_realm.cpp b/src/shared_realm.cpp index 8f51a96e..4720582c 100644 --- a/src/shared_realm.cpp +++ b/src/shared_realm.cpp @@ -201,12 +201,20 @@ void Realm::update_schema(std::unique_ptr schema, uint64_t version) { schema->validate(); - // If the schema version matches, just verify that the schema itself also matches - bool needs_update = !m_config.read_only && (m_config.schema_version != version || ObjectStore::needs_update(*m_config.schema, *schema)); - if (!needs_update) { + auto needs_update = [&] { + // If the schema version matches, just verify that the schema itself also matches + bool needs_write = !m_config.read_only && (m_config.schema_version != version || ObjectStore::needs_update(*m_config.schema, *schema)); + if (needs_write) { + return true; + } + ObjectStore::verify_schema(*m_config.schema, *schema, m_config.read_only); m_config.schema = std::move(schema); m_config.schema_version = version; + return false; + }; + + if (!needs_update()) { return; } @@ -225,11 +233,13 @@ void Realm::update_schema(std::unique_ptr schema, uint64_t version) // recheck everything auto current_schema_version = ObjectStore::get_schema_version(read_group()); if (current_schema_version != m_config.schema_version) { - cancel_transaction(); - m_config.schema_version = current_schema_version; *m_config.schema = ObjectStore::schema_from_group(read_group()); - return update_schema(std::move(schema), version); + + if (!needs_update()) { + cancel_transaction(); + return; + } } Config old_config(m_config);