mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-25 20:55:40 +00:00
Actually update the coordinator's copy of the schema
This commit is contained in:
parent
a3dab7e4b1
commit
638b4ec35e
@ -21,6 +21,7 @@
|
||||
#include "impl/cached_realm.hpp"
|
||||
#include "impl/external_commit_helper.hpp"
|
||||
#include "object_store.hpp"
|
||||
#include "schema.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
@ -96,7 +97,7 @@ std::shared_ptr<Realm> RealmCoordinator::get_realm(Realm::Config config)
|
||||
}
|
||||
}
|
||||
|
||||
auto realm = std::make_shared<Realm>(config);
|
||||
auto realm = std::make_shared<Realm>(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>(schema);
|
||||
}
|
||||
|
||||
RealmCoordinator::RealmCoordinator() = default;
|
||||
|
||||
RealmCoordinator::~RealmCoordinator()
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include <realm/string_data.hpp>
|
||||
|
||||
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;
|
||||
|
||||
|
@ -186,6 +186,7 @@ void Realm::update_schema(std::unique_ptr<Schema> 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> 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user