Update migrations.

pull/1/head
Matthew Chen 7 years ago
parent 86b18ddac6
commit 4556025566

@ -488,8 +488,7 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
// restoration of backup contents. If some of migrations don't // restoration of backup contents. If some of migrations don't
// complete, they'll be run the next time the app launches. // complete, they'll be run the next time the app launches.
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[[[OWSDatabaseMigrationRunner alloc] initWithPrimaryStorage:self.primaryStorage] [[[OWSDatabaseMigrationRunner alloc] init] runAllOutstandingWithCompletion:^{
runAllOutstandingWithCompletion:^{
completion(YES); completion(YES);
}]; }];
}); });

@ -57,8 +57,7 @@ NS_ASSUME_NONNULL_BEGIN
if (!previousVersion) { if (!previousVersion) {
OWSLogInfo(@"No previous version found. Probably first launch since install - nothing to migrate."); OWSLogInfo(@"No previous version found. Probably first launch since install - nothing to migrate.");
OWSDatabaseMigrationRunner *runner = OWSDatabaseMigrationRunner *runner = [[OWSDatabaseMigrationRunner alloc] init];
[[OWSDatabaseMigrationRunner alloc] initWithPrimaryStorage:[OWSPrimaryStorage sharedManager]];
[runner assumeAllExistingMigrationsRun]; [runner assumeAllExistingMigrationsRun];
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
completion(); completion();
@ -95,8 +94,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[[OWSDatabaseMigrationRunner alloc] initWithPrimaryStorage:[OWSPrimaryStorage sharedManager]] [[[OWSDatabaseMigrationRunner alloc] init] runAllOutstandingWithCompletion:completion];
runAllOutstandingWithCompletion:completion];
}); });
} }

@ -12,8 +12,6 @@ typedef void (^OWSDatabaseMigrationCompletion)(void);
@interface OWSDatabaseMigration : TSYapDatabaseObject @interface OWSDatabaseMigration : TSYapDatabaseObject
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage;
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage; @property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
// Prefer nonblocking (async) migrations by overriding `runUpWithTransaction:` in a subclass. // Prefer nonblocking (async) migrations by overriding `runUpWithTransaction:` in a subclass.

@ -10,6 +10,17 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSDatabaseMigration @implementation OWSDatabaseMigration
#pragma mark - Dependencies
- (OWSPrimaryStorage *)primaryStorage
{
OWSAssertDebug(SSKEnvironment.shared.primaryStorage);
return SSKEnvironment.shared.primaryStorage;
}
#pragma mark -
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction - (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSLogInfo(@"marking migration as complete."); OWSLogInfo(@"marking migration as complete.");
@ -17,15 +28,13 @@ NS_ASSUME_NONNULL_BEGIN
[super saveWithTransaction:transaction]; [super saveWithTransaction:transaction];
} }
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage - (instancetype)init
{ {
self = [super initWithUniqueId:[self.class migrationId]]; self = [super initWithUniqueId:[self.class migrationId]];
if (!self) { if (!self) {
return self; return self;
} }
_primaryStorage = primaryStorage;
return self; return self;
} }

@ -6,14 +6,8 @@ NS_ASSUME_NONNULL_BEGIN
typedef void (^OWSDatabaseMigrationCompletion)(void); typedef void (^OWSDatabaseMigrationCompletion)(void);
@class OWSPrimaryStorage;
@interface OWSDatabaseMigrationRunner : NSObject @interface OWSDatabaseMigrationRunner : NSObject
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage;
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
/** /**
* Run any outstanding version migrations. * Run any outstanding version migrations.
*/ */

@ -19,35 +19,22 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSDatabaseMigrationRunner @implementation OWSDatabaseMigrationRunner
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
{
self = [super init];
if (!self) {
return self;
}
_primaryStorage = primaryStorage;
return self;
}
// This should all migrations which do NOT qualify as safeBlockingMigrations: // This should all migrations which do NOT qualify as safeBlockingMigrations:
- (NSArray<OWSDatabaseMigration *> *)allMigrations - (NSArray<OWSDatabaseMigration *> *)allMigrations
{ {
OWSPrimaryStorage *primaryStorage = OWSPrimaryStorage.sharedManager;
return @[ return @[
[[OWS100RemoveTSRecipientsMigration alloc] initWithPrimaryStorage:primaryStorage], [[OWS100RemoveTSRecipientsMigration alloc] init],
[[OWS102MoveLoggingPreferenceToUserDefaults alloc] initWithPrimaryStorage:primaryStorage], [[OWS102MoveLoggingPreferenceToUserDefaults alloc] init],
[[OWS103EnableVideoCalling alloc] initWithPrimaryStorage:primaryStorage], [[OWS103EnableVideoCalling alloc] init],
[[OWS104CreateRecipientIdentities alloc] initWithPrimaryStorage:primaryStorage], [[OWS104CreateRecipientIdentities alloc] init],
[[OWS105AttachmentFilePaths alloc] initWithPrimaryStorage:primaryStorage], [[OWS105AttachmentFilePaths alloc] init],
[[OWS106EnsureProfileComplete alloc] initWithPrimaryStorage:primaryStorage], [[OWS106EnsureProfileComplete alloc] init],
[[OWS107LegacySounds alloc] initWithPrimaryStorage:primaryStorage], [[OWS107LegacySounds alloc] init],
[[OWS108CallLoggingPreference alloc] initWithPrimaryStorage:primaryStorage], [[OWS108CallLoggingPreference alloc] init],
[[OWS109OutgoingMessageState alloc] initWithPrimaryStorage:primaryStorage], [[OWS109OutgoingMessageState alloc] init],
[[OWS111UDAttributesMigration alloc] initWithPrimaryStorage:primaryStorage], [[OWS111UDAttributesMigration alloc] init],
[[OWS112TypingIndicatorsMigration alloc] initWithPrimaryStorage:primaryStorage], [[OWS112TypingIndicatorsMigration alloc] init],
[[OWS113MultiAttachmentMediaMessages alloc] initWithPrimaryStorage:primaryStorage], [[OWS113MultiAttachmentMediaMessages alloc] init],
]; ];
} }

Loading…
Cancel
Save