mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.8 KiB
Matlab
93 lines
2.8 KiB
Matlab
8 years ago
|
//
|
||
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
9 years ago
|
|
||
|
#import "OWSDatabaseMigrationRunner.h"
|
||
7 years ago
|
#import "OWS100RemoveTSRecipientsMigration.h"
|
||
|
#import "OWS102MoveLoggingPreferenceToUserDefaults.h"
|
||
|
#import "OWS103EnableVideoCalling.h"
|
||
7 years ago
|
#import "OWS104CreateRecipientIdentities.h"
|
||
7 years ago
|
#import "OWS105AttachmentFilePaths.h"
|
||
7 years ago
|
#import "OWSDatabaseMigration.h"
|
||
7 years ago
|
#import <SignalMessaging/SignalMessaging-Swift.h>
|
||
7 years ago
|
#import <SignalServiceKit/AppContext.h>
|
||
9 years ago
|
|
||
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
|
@implementation OWSDatabaseMigrationRunner
|
||
|
|
||
|
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
|
||
|
{
|
||
|
self = [super init];
|
||
|
if (!self) {
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
_storageManager = storageManager;
|
||
|
|
||
|
return self;
|
||
|
}
|
||
|
|
||
7 years ago
|
// This should all migrations which do NOT qualify as safeBlockingMigrations:
|
||
9 years ago
|
- (NSArray<OWSDatabaseMigration *> *)allMigrations
|
||
|
{
|
||
7 years ago
|
TSStorageManager *storageManager = TSStorageManager.sharedManager;
|
||
|
return @[
|
||
|
[[OWS100RemoveTSRecipientsMigration alloc] initWithStorageManager:storageManager],
|
||
|
[[OWS102MoveLoggingPreferenceToUserDefaults alloc] initWithStorageManager:storageManager],
|
||
|
[[OWS103EnableVideoCalling alloc] initWithStorageManager:storageManager],
|
||
|
// OWS104CreateRecipientIdentities is run separately. See runSafeBlockingMigrations.
|
||
|
[[OWS105AttachmentFilePaths alloc] initWithStorageManager:storageManager],
|
||
|
[[OWS106EnsureProfileComplete alloc] initWithStorageManager:storageManager]
|
||
|
];
|
||
|
}
|
||
|
|
||
|
// 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.
|
||
|
- (NSArray<OWSDatabaseMigration *> *)safeBlockingMigrations
|
||
|
{
|
||
|
TSStorageManager *storageManager = TSStorageManager.sharedManager;
|
||
|
return @[
|
||
|
[[OWS104CreateRecipientIdentities alloc] initWithStorageManager:storageManager],
|
||
|
];
|
||
9 years ago
|
}
|
||
|
|
||
|
- (void)assumeAllExistingMigrationsRun
|
||
|
{
|
||
|
for (OWSDatabaseMigration *migration in self.allMigrations) {
|
||
8 years ago
|
DDLogInfo(@"%@ Skipping migration on new install: %@", self.logTag, migration);
|
||
9 years ago
|
[migration save];
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
- (void)runSafeBlockingMigrations
|
||
|
{
|
||
7 years ago
|
[self runMigrations:self.safeBlockingMigrations];
|
||
8 years ago
|
}
|
||
|
|
||
9 years ago
|
- (void)runAllOutstanding
|
||
|
{
|
||
8 years ago
|
[self runMigrations:self.allMigrations];
|
||
|
}
|
||
|
|
||
|
- (void)runMigrations:(NSArray<OWSDatabaseMigration *> *)migrations
|
||
|
{
|
||
|
OWSAssert(migrations);
|
||
|
|
||
|
for (OWSDatabaseMigration *migration in migrations) {
|
||
9 years ago
|
if ([OWSDatabaseMigration fetchObjectWithUniqueID:migration.uniqueId]) {
|
||
8 years ago
|
DDLogDebug(@"%@ Skipping previously run migration: %@", self.logTag, migration);
|
||
9 years ago
|
} else {
|
||
8 years ago
|
DDLogWarn(@"%@ Running migration: %@", self.logTag, migration);
|
||
9 years ago
|
[migration runUp];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@end
|
||
|
|
||
|
NS_ASSUME_NONNULL_END
|