add hook for detecting file format upgrade

This commit is contained in:
Ari Lazier 2016-05-05 19:39:50 -07:00
parent 28a7efcd1b
commit 87c9dda321
4 changed files with 22 additions and 15 deletions

View File

@ -246,7 +246,6 @@
children = ( children = (
F6BCCFDF1C83809A00FE31AE /* lib */, F6BCCFDF1C83809A00FE31AE /* lib */,
F62A35131C18E6E2004A917D /* iOS */, F62A35131C18E6E2004A917D /* iOS */,
F60103051CC4ADE500EC01BA /* JS */,
F6874A441CAD2ACD00EEEE36 /* JSC */, F6874A441CAD2ACD00EEEE36 /* JSC */,
F62BF9001CAC72C40022BCDC /* Node */, F62BF9001CAC72C40022BCDC /* Node */,
F62A35141C18E783004A917D /* Object Store */, F62A35141C18E783004A917D /* Object Store */,
@ -322,13 +321,6 @@
name = Frameworks; name = Frameworks;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
F60103051CC4ADE500EC01BA /* JS */ = {
isa = PBXGroup;
children = (
);
name = JS;
sourceTree = "<group>";
};
F62A35131C18E6E2004A917D /* iOS */ = { F62A35131C18E6E2004A917D /* iOS */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (

View File

@ -337,6 +337,13 @@ void Realm<T>::constructor(ContextType ctx, ObjectType this_object, size_t argc,
ensure_directory_exists_for_file(config.path); ensure_directory_exists_for_file(config.path);
SharedRealm realm = realm::Realm::get_shared_realm(config); SharedRealm realm = realm::Realm::get_shared_realm(config);
// Fix for datetime -> timestamp conversion
if (realm->config().upgrade_initial_version != realm->config().upgrade_final_version &&
realm->config().upgrade_initial_version < 5) {
assert(0);
}
auto delegate = new RealmDelegate<T>(realm, Context<T>::get_global_context(ctx)); auto delegate = new RealmDelegate<T>(realm, Context<T>::get_global_context(ctx));
delegate->m_defaults = std::move(defaults); delegate->m_defaults = std::move(defaults);
delegate->m_constructors = std::move(constructors); delegate->m_constructors = std::move(constructors);

View File

@ -43,13 +43,15 @@ Realm::Config::Config(const Config& c)
, cache(c.cache) , cache(c.cache)
, disable_format_upgrade(c.disable_format_upgrade) , disable_format_upgrade(c.disable_format_upgrade)
, automatic_change_notifications(c.automatic_change_notifications) , automatic_change_notifications(c.automatic_change_notifications)
, upgrade_final_version(0)
, upgrade_initial_version(0)
{ {
if (c.schema) { if (c.schema) {
schema = std::make_unique<Schema>(*c.schema); schema = std::make_unique<Schema>(*c.schema);
} }
} }
Realm::Config::Config() : schema_version(ObjectStore::NotVersioned) { } Realm::Config::Config() : schema_version(ObjectStore::NotVersioned), upgrade_initial_version(0), upgrade_final_version(0) { }
Realm::Config::Config(Config&&) = default; Realm::Config::Config(Config&&) = default;
Realm::Config::~Config() = default; Realm::Config::~Config() = default;
@ -71,7 +73,7 @@ Realm::Realm(Config config)
} }
} }
void Realm::open_with_config(const Config& config, void Realm::open_with_config(Config& config,
std::unique_ptr<Replication>& history, std::unique_ptr<Replication>& history,
std::unique_ptr<SharedGroup>& shared_group, std::unique_ptr<SharedGroup>& shared_group,
std::unique_ptr<Group>& read_only_group) std::unique_ptr<Group>& read_only_group)
@ -85,9 +87,12 @@ void Realm::open_with_config(const Config& config,
throw InvalidEncryptionKeyException(); throw InvalidEncryptionKeyException();
} }
history = realm::make_client_history(config.path, config.encryption_key.data()); history = realm::make_client_history(config.path, config.encryption_key.data());
SharedGroup::DurabilityLevel durability = config.in_memory ? SharedGroup::durability_MemOnly : SharedGroup::DurabilityLevel durability = config.in_memory ? SharedGroup::durability_MemOnly : SharedGroup::durability_Full;
SharedGroup::durability_Full; shared_group = std::make_unique<SharedGroup>(*history, durability, config.encryption_key.data(), !config.disable_format_upgrade,
shared_group = std::make_unique<SharedGroup>(*history, durability, config.encryption_key.data(), !config.disable_format_upgrade); [&](int from_version, int to_version) {
config.upgrade_initial_version = from_version;
config.upgrade_final_version = to_version;
});
} }
} }
catch (util::File::PermissionDenied const& ex) { catch (util::File::PermissionDenied const& ex) {

View File

@ -82,6 +82,9 @@ namespace realm {
// everything can be done deterministically on one thread, and // everything can be done deterministically on one thread, and
// speeds up tests that don't need notifications. // speeds up tests that don't need notifications.
bool automatic_change_notifications = true; bool automatic_change_notifications = true;
// File format versions populated when a file format updrade takes place
// during realm opening
int upgrade_initial_version, upgrade_final_version;
Config(); Config();
Config(Config&&); Config(Config&&);
@ -156,7 +159,7 @@ namespace realm {
static _impl::RealmCoordinator& get_coordinator(Realm& realm) { return *realm.m_coordinator; } static _impl::RealmCoordinator& get_coordinator(Realm& realm) { return *realm.m_coordinator; }
}; };
static void open_with_config(const Config& config, static void open_with_config(Config& config,
std::unique_ptr<Replication>& history, std::unique_ptr<Replication>& history,
std::unique_ptr<SharedGroup>& shared_group, std::unique_ptr<SharedGroup>& shared_group,
std::unique_ptr<Group>& read_only_group); std::unique_ptr<Group>& read_only_group);