diff --git a/src/impl/realm_coordinator.cpp b/src/impl/realm_coordinator.cpp index e305b420..d59cad08 100644 --- a/src/impl/realm_coordinator.cpp +++ b/src/impl/realm_coordinator.cpp @@ -21,6 +21,7 @@ #include "impl/cached_realm.hpp" #include "impl/external_commit_helper.hpp" #include "object_store.hpp" +#include "schema.hpp" #include @@ -96,7 +97,7 @@ std::shared_ptr RealmCoordinator::get_realm(Realm::Config config) } } - auto realm = std::make_shared(config); + auto realm = std::make_shared(std::move(config)); realm->init(shared_from_this()); m_cached_realms.emplace_back(realm, m_config.cache); return realm; @@ -107,6 +108,13 @@ const Schema* RealmCoordinator::get_schema() const noexcept return m_cached_realms.empty() ? nullptr : m_config.schema.get(); } +void RealmCoordinator::update_schema(Schema const& schema) +{ + // FIXME: this should probably be doing some sort of validation and + // notifying all Realm instances of the new schema in some way + m_config.schema = std::make_unique(schema); +} + RealmCoordinator::RealmCoordinator() = default; RealmCoordinator::~RealmCoordinator() diff --git a/src/impl/realm_coordinator.hpp b/src/impl/realm_coordinator.hpp index 46cfcec3..ee1d748b 100644 --- a/src/impl/realm_coordinator.hpp +++ b/src/impl/realm_coordinator.hpp @@ -24,6 +24,8 @@ #include namespace realm { +class Schema; + namespace _impl { class CachedRealm; class ExternalCommitHelper; @@ -68,6 +70,9 @@ public: // Called by m_notifier when there's a new commit to send notifications for void on_change(); + // Update the schema in the cached config + void update_schema(Schema const& new_schema); + private: Realm::Config m_config; diff --git a/src/shared_realm.cpp b/src/shared_realm.cpp index 81c70117..5c5b818a 100644 --- a/src/shared_realm.cpp +++ b/src/shared_realm.cpp @@ -186,6 +186,7 @@ void Realm::update_schema(std::unique_ptr schema, uint64_t version) ObjectStore::verify_schema(*m_config.schema, *schema, m_config.read_only); m_config.schema = std::move(schema); m_config.schema_version = version; + m_coordinator->update_schema(*m_config.schema); return false; }; @@ -243,6 +244,8 @@ void Realm::update_schema(std::unique_ptr schema, uint64_t version) m_config.schema_version = old_config.schema_version; throw; } + + m_coordinator->update_schema(*m_config.schema); } static void check_read_write(Realm *realm)