add api to delete a table and remove the pk for an object type
This commit is contained in:
parent
b3bee56f38
commit
107c2de9b6
|
@ -24,7 +24,6 @@
|
||||||
#include <realm/table_view.hpp>
|
#include <realm/table_view.hpp>
|
||||||
#include <realm/util/assert.hpp>
|
#include <realm/util/assert.hpp>
|
||||||
|
|
||||||
#include <set>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
using namespace realm;
|
using namespace realm;
|
||||||
|
@ -209,7 +208,6 @@ bool ObjectStore::create_tables(Group *group, ObjectStore::Schema &target_schema
|
||||||
|
|
||||||
// first pass to create missing tables
|
// first pass to create missing tables
|
||||||
vector<ObjectSchema *> to_update;
|
vector<ObjectSchema *> to_update;
|
||||||
set<string> target_type_names;
|
|
||||||
for (auto& object_schema : target_schema) {
|
for (auto& object_schema : target_schema) {
|
||||||
bool created = false;
|
bool created = false;
|
||||||
ObjectStore::table_for_object_type_create_if_needed(group, object_schema.name, created);
|
ObjectStore::table_for_object_type_create_if_needed(group, object_schema.name, created);
|
||||||
|
@ -219,9 +217,6 @@ bool ObjectStore::create_tables(Group *group, ObjectStore::Schema &target_schema
|
||||||
to_update.push_back(&object_schema);
|
to_update.push_back(&object_schema);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep track of names to figure out what tables need deletion
|
|
||||||
target_type_names.insert(object_schema.name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// second pass adds/removes columns for out of date tables
|
// second pass adds/removes columns for out of date tables
|
||||||
|
@ -278,19 +273,6 @@ bool ObjectStore::create_tables(Group *group, ObjectStore::Schema &target_schema
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove primary key entries for deleted types
|
|
||||||
// FIXME - delete actual tables once we have proper testing
|
|
||||||
ObjectStore::Schema schema;
|
|
||||||
for (int i = (int)group->size() - 1; i >= 0 ; i--) {
|
|
||||||
string object_type = object_type_for_table_name(group->get_table_name(i));
|
|
||||||
if (object_type.length()) {
|
|
||||||
if (target_type_names.find(object_type) == target_type_names.end()) {
|
|
||||||
set_primary_key_for_object(group, object_type, "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,3 +403,12 @@ void ObjectStore::validate_primary_column_uniqueness(Group *group, Schema &schem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectStore::delete_data_for_object(Group *group, const StringData &object_type) {
|
||||||
|
TableRef table = table_for_object_type(group, object_type);
|
||||||
|
if (table) {
|
||||||
|
group->remove_table(table->get_index_in_group());
|
||||||
|
set_primary_key_for_object(group, object_type, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,9 @@ namespace realm {
|
||||||
// check if indexes are up to date - if false you need to call update_realm_with_schema
|
// check if indexes are up to date - if false you need to call update_realm_with_schema
|
||||||
static bool indexes_are_up_to_date(Group *group, Schema &schema);
|
static bool indexes_are_up_to_date(Group *group, Schema &schema);
|
||||||
|
|
||||||
|
// deletes the table for the given type
|
||||||
|
static void delete_data_for_object(Group *group, const StringData &object_type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// set a new schema version
|
// set a new schema version
|
||||||
static void set_schema_version(Group *group, uint64_t version);
|
static void set_schema_version(Group *group, uint64_t version);
|
||||||
|
@ -84,7 +87,7 @@ namespace realm {
|
||||||
static bool create_metadata_tables(Group *group);
|
static bool create_metadata_tables(Group *group);
|
||||||
|
|
||||||
// set references to tables on targetSchema and create/update any missing or out-of-date tables
|
// 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
|
// if update existing is true, updates existing tables, otherwise only adds and initializes new tables
|
||||||
static bool create_tables(realm::Group *group, ObjectStore::Schema &target_schema, bool update_existing);
|
static bool create_tables(realm::Group *group, ObjectStore::Schema &target_schema, bool update_existing);
|
||||||
|
|
||||||
// get primary key property name for object type
|
// get primary key property name for object type
|
||||||
|
|
Loading…
Reference in New Issue