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.
		
		
		
		
		
			
		
			
				
	
	
		
			62 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Swift
		
	
			
		
		
	
	
			62 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Swift
		
	
| // Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
 | |
| 
 | |
| import Foundation
 | |
| import GRDB
 | |
| import SessionUtilitiesKit
 | |
| 
 | |
| enum _001_InitialSetupMigration: Migration {
 | |
|     static let target: TargetMigrations.Identifier = .snodeKit
 | |
|     static let identifier: String = "initialSetup" // stringlint:disable
 | |
|     static let needsConfigSync: Bool = false
 | |
|     static let minExpectedRunDuration: TimeInterval = 0.1
 | |
|     static let fetchedTables: [(TableRecord & FetchableRecord).Type] = []
 | |
|     static let createdOrAlteredTables: [(TableRecord & FetchableRecord).Type] = [
 | |
|         Snode.self, SnodeSet.self, SnodeReceivedMessageInfo.self
 | |
|     ]
 | |
|     
 | |
|     static func migrate(_ db: Database) throws {
 | |
|         try db.create(table: Snode.self) { t in
 | |
|             t.column(.address, .text).notNull()
 | |
|             t.column(.port, .integer).notNull()
 | |
|             t.column(.ed25519PublicKey, .text).notNull()
 | |
|             t.column(.x25519PublicKey, .text).notNull()
 | |
|             
 | |
|             t.primaryKey([.address, .port])
 | |
|         }
 | |
|         
 | |
|         try db.create(table: SnodeSet.self) { t in
 | |
|             t.column(.key, .text).notNull()
 | |
|             t.column(.nodeIndex, .integer).notNull()
 | |
|             t.column(.address, .text).notNull()
 | |
|             t.column(.port, .integer).notNull()
 | |
|             
 | |
|             t.foreignKey(
 | |
|                 [.address, .port],
 | |
|                 references: Snode.self,
 | |
|                 columns: [.address, .port],
 | |
|                 onDelete: .cascade                                    // Delete if Snode deleted
 | |
|             )
 | |
|             t.primaryKey([.key, .nodeIndex])
 | |
|         }
 | |
|         
 | |
|         try db.create(table: SnodeReceivedMessageInfo.self) { t in
 | |
|             t.deprecatedColumn(name: "id", .integer)                  // stringlint:disable
 | |
|                 .notNull()
 | |
|                 .primaryKey(autoincrement: true)
 | |
|             t.column(.key, .text)
 | |
|                 .notNull()
 | |
|                 .indexed()                                            // Quicker querying
 | |
|             t.column(.hash, .text)
 | |
|                 .notNull()
 | |
|                 .indexed()                                            // Quicker querying
 | |
|             t.column(.expirationDateMs, .integer)
 | |
|                 .notNull()
 | |
|                 .indexed()                                            // Quicker querying
 | |
|             
 | |
|             t.uniqueKey([.key, .hash])
 | |
|         }
 | |
|         
 | |
|         Storage.update(progress: 1, for: self, in: target) // In case this is the last migration
 | |
|     }
 | |
| }
 |