Skip to content

Commit

Permalink
call setSchema in createTables, copy custom schema
Browse files Browse the repository at this point in the history
  • Loading branch information
alazier committed Jan 29, 2015
1 parent b32d56f commit cfcafaf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
11 changes: 3 additions & 8 deletions Realm/RLMObjectStore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,9 @@ static bool RLMRealmCreateTables(RLMRealm *realm, RLMSchema *targetSchema, bool
// create metadata tables if neded
bool changed = RLMRealmCreateMetadataTables(realm);

realm.schema = targetSchema;

// first pass to create missing tables
NSMutableArray *objectSchemaToUpdate = [NSMutableArray array];
for (RLMObjectSchema *objectSchema in realm.schema.objectSchema) {
for (RLMObjectSchema *objectSchema in targetSchema.objectSchema) {
bool created = false;
objectSchema.table = RLMTableForObjectClass(realm, objectSchema.className, created).get();

Expand Down Expand Up @@ -230,11 +228,8 @@ static bool RLMRealmCreateTables(RLMRealm *realm, RLMSchema *targetSchema, bool

// FIXME - remove deleted tables

for (RLMObjectSchema *objectSchema in realm.schema.objectSchema) {
objectSchema.realm = realm;
RLMObjectSchema *tableSchema = [RLMObjectSchema schemaFromTableForClassName:objectSchema.className realm:realm];
RLMVerifyAndAlignColumns(tableSchema, objectSchema);
}
// set and validate final schema
RLMRealmSetSchema(realm, targetSchema, true);

return changed;
}
Expand Down
5 changes: 3 additions & 2 deletions Realm/RLMRealm.mm
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,9 @@ + (instancetype)realmWithPath:(NSString *)path
}
else {
// if we are the first realm at this path, set/align schema or perform migration if needed
RLMSchema *targetSchema = customSchema ?: [RLMSchema.sharedSchema copy];
NSError *error = RLMUpdateRealmToSchemaVersion(realm, schemaVersionForPath(path), targetSchema, [realm migrationBlock:key]);
RLMSchema *targetSchema = customSchema ?: RLMSchema.sharedSchema;
NSError *error = RLMUpdateRealmToSchemaVersion(realm, schemaVersionForPath(path),
[targetSchema copy], [realm migrationBlock:key]);
if (error) {
setOrThrowError(error, outError);
return nil;
Expand Down

0 comments on commit cfcafaf

Please sign in to comment.