Remove the tracking of if any changes were made from update_realm_with_schema()
It was no longer actually used for anything since we now check if any changes are actually needed before calling it (to avoid beginning a write transaction when not needed).
This commit is contained in:
parent
9c2d4703ed
commit
8d7b5d8d08
|
@ -52,13 +52,11 @@ bool ObjectStore::has_metadata_tables(const Group *group) {
|
|||
return group->get_table(c_primaryKeyTableName) && group->get_table(c_metadataTableName);
|
||||
}
|
||||
|
||||
bool ObjectStore::create_metadata_tables(Group *group) {
|
||||
bool changed = false;
|
||||
void ObjectStore::create_metadata_tables(Group *group) {
|
||||
TableRef table = group->get_or_add_table(c_primaryKeyTableName);
|
||||
if (table->get_column_count() == 0) {
|
||||
table->add_column(type_String, c_primaryKeyObjectClassColumnName);
|
||||
table->add_column(type_String, c_primaryKeyPropertyNameColumnName);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
table = group->get_or_add_table(c_metadataTableName);
|
||||
|
@ -68,10 +66,7 @@ bool ObjectStore::create_metadata_tables(Group *group) {
|
|||
// set initial version
|
||||
table->add_empty_row();
|
||||
table->set_int(c_versionColumnIndex, c_zeroRowIndex, ObjectStore::NotVersioned);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
uint64_t ObjectStore::get_schema_version(const Group *group) {
|
||||
|
@ -255,9 +250,7 @@ static void copy_property_values(const Property& source, const Property& destina
|
|||
// set references to tables on targetSchema and create/update any missing or out-of-date tables
|
||||
// if update existing is true, updates existing tables, otherwise validates existing tables
|
||||
// NOTE: must be called from within write transaction
|
||||
bool ObjectStore::create_tables(Group *group, Schema &target_schema, bool update_existing) {
|
||||
bool changed = false;
|
||||
|
||||
void ObjectStore::create_tables(Group *group, Schema &target_schema, bool update_existing) {
|
||||
// first pass to create missing tables
|
||||
std::vector<ObjectSchema *> to_update;
|
||||
for (auto& object_schema : target_schema) {
|
||||
|
@ -267,7 +260,6 @@ bool ObjectStore::create_tables(Group *group, Schema &target_schema, bool update
|
|||
// we will modify tables for any new objectSchema (table was created) or for all if update_existing is true
|
||||
if (update_existing || created) {
|
||||
to_update.push_back(&object_schema);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,7 +283,6 @@ bool ObjectStore::create_tables(Group *group, Schema &target_schema, bool update
|
|||
table->remove_column(current_prop.table_column);
|
||||
|
||||
current_prop.table_column = target_prop->table_column;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
bool inserted_placeholder_column = false;
|
||||
|
@ -314,7 +305,6 @@ bool ObjectStore::create_tables(Group *group, Schema &target_schema, bool update
|
|||
table->remove_column(current_prop.table_column);
|
||||
++deleted;
|
||||
current_prop.table_column = npos;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,8 +329,6 @@ bool ObjectStore::create_tables(Group *group, Schema &target_schema, bool update
|
|||
target_prop.is_nullable);
|
||||
break;
|
||||
}
|
||||
|
||||
changed = true;
|
||||
}
|
||||
else {
|
||||
target_prop.table_column = current_prop->table_column;
|
||||
|
@ -361,16 +349,13 @@ bool ObjectStore::create_tables(Group *group, Schema &target_schema, bool update
|
|||
// if there is a primary key set, check if it is the same as the old key
|
||||
if (current_schema.primary_key != target_object_schema->primary_key) {
|
||||
set_primary_key_for_object(group, target_object_schema->name, target_object_schema->primary_key);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
else if (current_schema.primary_key.length()) {
|
||||
// there is no primary key, so if there was one nil out
|
||||
set_primary_key_for_object(group, target_object_schema->name, "");
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool ObjectStore::is_schema_at_version(const Group *group, uint64_t version) {
|
||||
|
@ -405,7 +390,7 @@ bool ObjectStore::needs_update(Schema const& old_schema, Schema const& schema) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ObjectStore::update_realm_with_schema(Group *group, Schema const& old_schema,
|
||||
void ObjectStore::update_realm_with_schema(Group *group, Schema const& old_schema,
|
||||
uint64_t version, Schema &schema,
|
||||
MigrationFunction migration) {
|
||||
// Recheck the schema version after beginning the write transaction as
|
||||
|
@ -414,8 +399,8 @@ bool ObjectStore::update_realm_with_schema(Group *group, Schema const& old_schem
|
|||
bool migrating = !is_schema_at_version(group, version);
|
||||
|
||||
// create tables
|
||||
bool changed = create_metadata_tables(group);
|
||||
changed = create_tables(group, schema, migrating) || changed;
|
||||
create_metadata_tables(group);
|
||||
create_tables(group, schema, migrating);
|
||||
|
||||
if (!migrating) {
|
||||
// If we aren't migrating, then verify that all of the tables which
|
||||
|
@ -423,10 +408,10 @@ bool ObjectStore::update_realm_with_schema(Group *group, Schema const& old_schem
|
|||
verify_schema(old_schema, schema, true);
|
||||
}
|
||||
|
||||
changed = update_indexes(group, schema) || changed;
|
||||
update_indexes(group, schema);
|
||||
|
||||
if (!migrating) {
|
||||
return changed;
|
||||
return;
|
||||
}
|
||||
|
||||
// apply the migration block if provided and there's any old data
|
||||
|
@ -437,7 +422,6 @@ bool ObjectStore::update_realm_with_schema(Group *group, Schema const& old_schem
|
|||
}
|
||||
|
||||
set_schema_version(group, version);
|
||||
return true;
|
||||
}
|
||||
|
||||
Schema ObjectStore::schema_from_group(const Group *group) {
|
||||
|
|
|
@ -52,12 +52,11 @@ namespace realm {
|
|||
static bool needs_update(Schema const& old_schema, Schema const& schema);
|
||||
|
||||
// updates a Realm from old_schema to the given target schema, creating and updating tables as needed
|
||||
// returns if any changes were made
|
||||
// passed in target schema is updated with the correct column mapping
|
||||
// optionally runs migration function if schema is out of date
|
||||
// NOTE: must be performed within a write transaction
|
||||
typedef std::function<void(Group *, Schema &)> MigrationFunction;
|
||||
static bool update_realm_with_schema(Group *group, Schema const& old_schema, uint64_t version,
|
||||
static void update_realm_with_schema(Group *group, Schema const& old_schema, uint64_t version,
|
||||
Schema &schema, MigrationFunction migration);
|
||||
|
||||
// get a table for an object type
|
||||
|
@ -86,11 +85,11 @@ namespace realm {
|
|||
// create any metadata tables that don't already exist
|
||||
// must be in write transaction to set
|
||||
// returns true if it actually did anything
|
||||
static bool create_metadata_tables(Group *group);
|
||||
static void create_metadata_tables(Group *group);
|
||||
|
||||
// set references to tables on targetSchema and create/update any missing or out-of-date tables
|
||||
// if update existing is true, updates existing tables, otherwise only adds and initializes new tables
|
||||
static bool create_tables(realm::Group *group, Schema &target_schema, bool update_existing);
|
||||
static void create_tables(realm::Group *group, Schema &target_schema, bool update_existing);
|
||||
|
||||
// verify a target schema against an expected schema, setting the table_column property on each schema object
|
||||
// updates the column mapping on the target_schema
|
||||
|
|
|
@ -197,7 +197,7 @@ SharedRealm Realm::get_shared_realm(Config config)
|
|||
return realm;
|
||||
}
|
||||
|
||||
bool Realm::update_schema(std::unique_ptr<Schema> schema, uint64_t version)
|
||||
void Realm::update_schema(std::unique_ptr<Schema> schema, uint64_t version)
|
||||
{
|
||||
schema->validate();
|
||||
|
||||
|
@ -207,7 +207,7 @@ bool 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;
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
begin_transaction();
|
||||
|
@ -248,11 +248,10 @@ bool Realm::update_schema(std::unique_ptr<Schema> schema, uint64_t version)
|
|||
m_config.schema = std::move(schema);
|
||||
m_config.schema_version = version;
|
||||
|
||||
bool changed = ObjectStore::update_realm_with_schema(read_group(), *old_config.schema,
|
||||
version, *m_config.schema,
|
||||
migration_function);
|
||||
ObjectStore::update_realm_with_schema(read_group(), *old_config.schema,
|
||||
version, *m_config.schema,
|
||||
migration_function);
|
||||
commit_transaction();
|
||||
return changed;
|
||||
}
|
||||
catch (...) {
|
||||
m_config.schema = std::move(old_config.schema);
|
||||
|
|
|
@ -79,8 +79,7 @@ namespace realm {
|
|||
// updating indexes as necessary. Uses the existing migration function
|
||||
// on the Config, and the resulting Schema and version with updated
|
||||
// column mappings are set on the realms config upon success.
|
||||
// returns if any changes were made
|
||||
bool update_schema(std::unique_ptr<Schema> schema, uint64_t version);
|
||||
void update_schema(std::unique_ptr<Schema> schema, uint64_t version);
|
||||
|
||||
static uint64_t get_schema_version(Config const& config);
|
||||
|
||||
|
|
Loading…
Reference in New Issue