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.
110 lines
2.2 KiB
Matlab
110 lines
2.2 KiB
Matlab
8 years ago
|
//
|
||
7 years ago
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||
8 years ago
|
//
|
||
9 years ago
|
|
||
|
#import "OWSDatabaseMigration.h"
|
||
4 years ago
|
#import <SessionMessagingKit/OWSPrimaryStorage.h>
|
||
|
#import <SessionMessagingKit/SSKEnvironment.h>
|
||
5 years ago
|
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
|
||
9 years ago
|
|
||
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
|
@implementation OWSDatabaseMigration
|
||
|
|
||
7 years ago
|
#pragma mark - Dependencies
|
||
|
|
||
|
- (OWSPrimaryStorage *)primaryStorage
|
||
|
{
|
||
|
OWSAssertDebug(SSKEnvironment.shared.primaryStorage);
|
||
|
|
||
|
return SSKEnvironment.shared.primaryStorage;
|
||
|
}
|
||
|
|
||
|
#pragma mark -
|
||
|
|
||
7 years ago
|
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||
|
{
|
||
7 years ago
|
OWSLogInfo(@"marking migration as complete.");
|
||
7 years ago
|
|
||
|
[super saveWithTransaction:transaction];
|
||
|
}
|
||
|
|
||
7 years ago
|
- (instancetype)init
|
||
9 years ago
|
{
|
||
|
self = [super initWithUniqueId:[self.class migrationId]];
|
||
|
if (!self) {
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
+ (MTLPropertyStorage)storageBehaviorForPropertyWithKey:(NSString *)propertyKey
|
||
|
{
|
||
7 years ago
|
if ([propertyKey isEqualToString:@"primaryStorage"]) {
|
||
9 years ago
|
return MTLPropertyStorageNone;
|
||
|
} else {
|
||
|
return [super storageBehaviorForPropertyWithKey:propertyKey];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
+ (NSString *)migrationId
|
||
|
{
|
||
7 years ago
|
OWSAbstractMethod();
|
||
|
return @"";
|
||
9 years ago
|
}
|
||
|
|
||
|
+ (NSString *)collection
|
||
|
{
|
||
|
// We want all subclasses in the same collection
|
||
|
return @"OWSDatabaseMigration";
|
||
|
}
|
||
|
|
||
|
- (void)runUpWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||
|
{
|
||
7 years ago
|
OWSAbstractMethod();
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
- (void)runUpWithCompletion:(OWSDatabaseMigrationCompletion)completion
|
||
9 years ago
|
{
|
||
7 years ago
|
OWSAssertDebug(completion);
|
||
7 years ago
|
|
||
5 years ago
|
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||
5 years ago
|
[self runUpWithTransaction:transaction];
|
||
|
}
|
||
|
completion:^{
|
||
|
OWSLogInfo(@"Completed migration %@", self.uniqueId);
|
||
|
[self save];
|
||
|
|
||
|
completion();
|
||
|
}];
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
#pragma mark - Database Connections
|
||
|
|
||
|
#ifdef DEBUG
|
||
|
+ (YapDatabaseConnection *)dbReadConnection
|
||
|
{
|
||
|
return self.dbReadWriteConnection;
|
||
|
}
|
||
|
|
||
|
+ (YapDatabaseConnection *)dbReadWriteConnection
|
||
|
{
|
||
7 years ago
|
return SSKEnvironment.shared.migrationDBConnection;
|
||
7 years ago
|
}
|
||
|
|
||
|
- (YapDatabaseConnection *)dbReadConnection
|
||
|
{
|
||
|
return OWSDatabaseMigration.dbReadConnection;
|
||
|
}
|
||
|
|
||
|
- (YapDatabaseConnection *)dbReadWriteConnection
|
||
|
{
|
||
|
return OWSDatabaseMigration.dbReadWriteConnection;
|
||
|
}
|
||
|
#endif
|
||
|
|
||
9 years ago
|
@end
|
||
|
|
||
|
NS_ASSUME_NONNULL_END
|