Update migrations.

This commit is contained in:
Matthew Chen 2018-11-27 16:59:38 -05:00
parent 86b18ddac6
commit 4556025566
6 changed files with 29 additions and 44 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -19,35 +19,22 @@ NS_ASSUME_NONNULL_BEGIN
@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:
- (NSArray<OWSDatabaseMigration *> *)allMigrations
{
OWSPrimaryStorage *primaryStorage = OWSPrimaryStorage.sharedManager;
return @[
[[OWS100RemoveTSRecipientsMigration alloc] initWithPrimaryStorage:primaryStorage],
[[OWS102MoveLoggingPreferenceToUserDefaults alloc] initWithPrimaryStorage:primaryStorage],
[[OWS103EnableVideoCalling alloc] initWithPrimaryStorage:primaryStorage],
[[OWS104CreateRecipientIdentities alloc] initWithPrimaryStorage:primaryStorage],
[[OWS105AttachmentFilePaths alloc] initWithPrimaryStorage:primaryStorage],
[[OWS106EnsureProfileComplete alloc] initWithPrimaryStorage:primaryStorage],
[[OWS107LegacySounds alloc] initWithPrimaryStorage:primaryStorage],
[[OWS108CallLoggingPreference alloc] initWithPrimaryStorage:primaryStorage],
[[OWS109OutgoingMessageState alloc] initWithPrimaryStorage:primaryStorage],
[[OWS111UDAttributesMigration alloc] initWithPrimaryStorage:primaryStorage],
[[OWS112TypingIndicatorsMigration alloc] initWithPrimaryStorage:primaryStorage],
[[OWS113MultiAttachmentMediaMessages alloc] initWithPrimaryStorage:primaryStorage],
[[OWS100RemoveTSRecipientsMigration alloc] init],
[[OWS102MoveLoggingPreferenceToUserDefaults alloc] init],
[[OWS103EnableVideoCalling alloc] init],
[[OWS104CreateRecipientIdentities alloc] init],
[[OWS105AttachmentFilePaths alloc] init],
[[OWS106EnsureProfileComplete alloc] init],
[[OWS107LegacySounds alloc] init],
[[OWS108CallLoggingPreference alloc] init],
[[OWS109OutgoingMessageState alloc] init],
[[OWS111UDAttributesMigration alloc] init],
[[OWS112TypingIndicatorsMigration alloc] init],
[[OWS113MultiAttachmentMediaMessages alloc] init],
];
}