Fixup e61c81 by migrating old schema

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent c14e4bb7b3
commit baf564db2e

@ -5,6 +5,31 @@
#import "TSAttachment.h" #import "TSAttachment.h"
#import <YapDatabase/YapDatabaseTransaction.h> #import <YapDatabase/YapDatabaseTransaction.h>
static const NSUInteger OWSMessageSchemaVersion = 2;
@interface TSMessage ()
/**
* The version of the model class's schema last used to serialize this model. Use this to manage data migrations during
* object de/serialization.
*
* e.g.
*
* - (id)initWithCoder:(NSCoder *)coder
* {
* self = [super initWithCoder:coder];
* if (!self) { return self; }
* if (_schemaVersion < 2) {
* _newName = [coder decodeObjectForKey:@"oldName"]
* }
* ...
* _schemaVersion = 2;
* }
*/
@property (nonatomic, readonly) NSUInteger schemaVersion;
@end
@implementation TSMessage @implementation TSMessage
- (instancetype)initWithTimestamp:(uint64_t)timestamp - (instancetype)initWithTimestamp:(uint64_t)timestamp
@ -24,6 +49,24 @@
return self; return self;
} }
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (!self) {
return self;
}
if (_schemaVersion < 2) {
if (!_attachmentIds) {
_attachmentIds = [coder decodeObjectForKey:@"attachments"];
}
}
_schemaVersion = OWSMessageSchemaVersion;
return self;
}
- (BOOL)hasAttachments - (BOOL)hasAttachments
{ {
return self.attachmentIds ? (self.attachmentIds.count > 0) : false; return self.attachmentIds ? (self.attachmentIds.count > 0) : false;

@ -77,7 +77,6 @@
} }
}]; }];
// TODO Make sure we're not deleting group update avatars
NSArray<NSString *> *filenamesToDelete = [attachmentIdFilenames allValues]; NSArray<NSString *> *filenamesToDelete = [attachmentIdFilenames allValues];
NSMutableArray<NSString *> *absolutePathsToDelete = [NSMutableArray arrayWithCapacity:[filenamesToDelete count]]; NSMutableArray<NSString *> *absolutePathsToDelete = [NSMutableArray arrayWithCapacity:[filenamesToDelete count]];
for (NSString *filename in filenamesToDelete) { for (NSString *filename in filenamesToDelete) {

@ -54,7 +54,6 @@
+ (void)enumerateCollectionObjectsWithTransaction:(YapDatabaseReadTransaction *)transaction + (void)enumerateCollectionObjectsWithTransaction:(YapDatabaseReadTransaction *)transaction
usingBlock:(void (^)(id object, BOOL *stop))block; usingBlock:(void (^)(id object, BOOL *stop))block;
/** /**
* @return A shared database connection. * @return A shared database connection.
*/ */
@ -69,15 +68,12 @@
* *
* @return Instance of the object or nil if non-existent * @return Instance of the object or nil if non-existent
*/ */
+ (instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID transaction:(YapDatabaseReadTransaction *)transaction; + (instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID transaction:(YapDatabaseReadTransaction *)transaction;
+ (instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID; + (instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID;
/** /**
* Saves the object with a new YapDatabaseConnection * Saves the object with a new YapDatabaseConnection
*/ */
- (void)save; - (void)save;
/** /**
@ -85,18 +81,13 @@
* *
* @param transaction Database transaction * @param transaction Database transaction
*/ */
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
/** /**
* The unique identifier of the stored object * The unique identifier of the stored object
*/ */
@property (nonatomic) NSString *uniqueId; @property (nonatomic) NSString *uniqueId;
- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)remove; - (void)remove;

Loading…
Cancel
Save