2017-03-14 23:16:05 +01:00
|
|
|
//
|
|
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
2016-09-28 18:21:14 +02:00
|
|
|
|
|
|
|
#import "OWSDatabaseMigrationRunner.h"
|
|
|
|
#import "OWS100RemoveTSRecipientsMigration.h"
|
2017-01-24 01:48:14 +01:00
|
|
|
#import "OWS102MoveLoggingPreferenceToUserDefaults.h"
|
2017-03-14 23:16:05 +01:00
|
|
|
#import "OWS103EnableVideoCalling.h"
|
2017-05-23 17:28:12 +02:00
|
|
|
#import "OWS104CreateRecipientIdentities.h"
|
2017-06-20 23:39:44 +02:00
|
|
|
#import "OWS105AttachmentFilePaths.h"
|
2017-07-24 16:14:58 +02:00
|
|
|
#import "Signal-Swift.h"
|
2016-09-28 18:21:14 +02:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
@implementation OWSDatabaseMigrationRunner
|
|
|
|
|
|
|
|
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
_storageManager = storageManager;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray<OWSDatabaseMigration *> *)allMigrations
|
|
|
|
{
|
2016-11-08 19:08:04 +01:00
|
|
|
return @[
|
|
|
|
[[OWS100RemoveTSRecipientsMigration alloc] initWithStorageManager:self.storageManager],
|
2017-03-14 23:16:05 +01:00
|
|
|
[[OWS102MoveLoggingPreferenceToUserDefaults alloc] initWithStorageManager:self.storageManager],
|
2017-05-23 17:28:12 +02:00
|
|
|
[[OWS103EnableVideoCalling alloc] initWithStorageManager:self.storageManager],
|
2017-07-05 21:53:43 +02:00
|
|
|
// OWS104CreateRecipientIdentities is run separately. See runSafeBlockingMigrations.
|
2017-07-24 16:14:58 +02:00
|
|
|
[[OWS105AttachmentFilePaths alloc] initWithStorageManager:self.storageManager],
|
|
|
|
[[OWS106EnsureProfileComplete alloc] initWithStorageManager:self.storageManager]
|
2016-11-08 19:08:04 +01:00
|
|
|
];
|
2016-09-28 18:21:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)assumeAllExistingMigrationsRun
|
|
|
|
{
|
|
|
|
for (OWSDatabaseMigration *migration in self.allMigrations) {
|
|
|
|
DDLogInfo(@"%@ Skipping migration on new install: %@", self.tag, migration);
|
|
|
|
[migration save];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 19:43:18 +02:00
|
|
|
- (void)runSafeBlockingMigrations
|
|
|
|
{
|
2017-07-05 21:53:43 +02:00
|
|
|
// This should only include migrations which:
|
|
|
|
//
|
|
|
|
// a) Do read/write database transactions and therefore would block on the async database
|
|
|
|
// view registration.
|
|
|
|
// b) Will not affect any of the data used by the async database views.
|
2017-06-15 19:43:18 +02:00
|
|
|
[self runMigrations:@[
|
|
|
|
[[OWS104CreateRecipientIdentities alloc] initWithStorageManager:self.storageManager],
|
|
|
|
]];
|
|
|
|
}
|
|
|
|
|
2016-09-28 18:21:14 +02:00
|
|
|
- (void)runAllOutstanding
|
|
|
|
{
|
2017-06-15 19:43:18 +02:00
|
|
|
[self runMigrations:self.allMigrations];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)runMigrations:(NSArray<OWSDatabaseMigration *> *)migrations
|
|
|
|
{
|
|
|
|
OWSAssert(migrations);
|
|
|
|
|
|
|
|
for (OWSDatabaseMigration *migration in migrations) {
|
2016-09-28 18:21:14 +02:00
|
|
|
if ([OWSDatabaseMigration fetchObjectWithUniqueID:migration.uniqueId]) {
|
|
|
|
DDLogDebug(@"%@ Skipping previously run migration: %@", self.tag, migration);
|
|
|
|
} else {
|
|
|
|
DDLogWarn(@"%@ Running migration: %@", self.tag, migration);
|
|
|
|
[migration runUp];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Logging
|
|
|
|
|
|
|
|
+ (NSString *)tag
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:@"[%@]", self.class];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)tag
|
|
|
|
{
|
|
|
|
return self.class.tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|