2022-03-31 02:47:09 +02:00
|
|
|
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import GRDB
|
|
|
|
import SessionUtilitiesKit
|
|
|
|
|
|
|
|
enum _001_InitialSetupMigration: Migration {
|
2022-05-31 09:41:02 +02:00
|
|
|
static let target: TargetMigrations.Identifier = .snodeKit
|
2023-09-25 10:32:56 +02:00
|
|
|
static let identifier: String = "initialSetup" // stringlint:disable
|
2022-05-30 05:04:26 +02:00
|
|
|
static let needsConfigSync: Bool = false
|
2022-05-31 09:41:02 +02:00
|
|
|
static let minExpectedRunDuration: TimeInterval = 0.1
|
2023-10-03 03:52:29 +02:00
|
|
|
static let fetchedTables: [(TableRecord & FetchableRecord).Type] = []
|
|
|
|
static let createdOrAlteredTables: [(TableRecord & FetchableRecord).Type] = [
|
|
|
|
Snode.self, SnodeSet.self, SnodeReceivedMessageInfo.self
|
|
|
|
]
|
2022-03-31 02:47:09 +02:00
|
|
|
|
|
|
|
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],
|
2022-05-06 04:44:26 +02:00
|
|
|
onDelete: .cascade // Delete if Snode deleted
|
2022-03-31 02:47:09 +02:00
|
|
|
)
|
|
|
|
t.primaryKey([.key, .nodeIndex])
|
|
|
|
}
|
|
|
|
|
|
|
|
try db.create(table: SnodeReceivedMessageInfo.self) { t in
|
2022-04-26 09:31:50 +02:00
|
|
|
t.column(.id, .integer)
|
|
|
|
.notNull()
|
|
|
|
.primaryKey(autoincrement: true)
|
2022-03-31 02:47:09 +02:00
|
|
|
t.column(.key, .text)
|
|
|
|
.notNull()
|
2022-05-06 04:44:26 +02:00
|
|
|
.indexed() // Quicker querying
|
2022-05-12 09:28:27 +02:00
|
|
|
t.column(.hash, .text)
|
|
|
|
.notNull()
|
|
|
|
.indexed() // Quicker querying
|
2022-03-31 02:47:09 +02:00
|
|
|
t.column(.expirationDateMs, .integer)
|
|
|
|
.notNull()
|
2022-05-06 04:44:26 +02:00
|
|
|
.indexed() // Quicker querying
|
2022-03-31 02:47:09 +02:00
|
|
|
|
2022-04-26 09:31:50 +02:00
|
|
|
t.uniqueKey([.key, .hash])
|
2022-03-31 02:47:09 +02:00
|
|
|
}
|
2022-06-01 08:50:21 +02:00
|
|
|
|
2022-07-01 05:08:45 +02:00
|
|
|
Storage.update(progress: 1, for: self, in: target) // In case this is the last migration
|
2022-03-31 02:47:09 +02:00
|
|
|
}
|
|
|
|
}
|