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.
45 lines
1.9 KiB
Swift
45 lines
1.9 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import Foundation
|
|
import GRDB
|
|
import SessionUtilitiesKit
|
|
|
|
/// This migration adds the new types needed for Emoji Reacts
|
|
enum _008_EmojiReacts: Migration {
|
|
static let target: TargetMigrations.Identifier = .messagingKit
|
|
static let identifier: String = "EmojiReacts"
|
|
static let minExpectedRunDuration: TimeInterval = 0.01
|
|
static let fetchedTables: [(TableRecord & FetchableRecord).Type] = []
|
|
static let createdOrAlteredTables: [(TableRecord & FetchableRecord).Type] = [Reaction.self]
|
|
static let droppedTables: [(TableRecord & FetchableRecord).Type] = []
|
|
|
|
static func migrate(_ db: Database, using dependencies: Dependencies) throws {
|
|
try db.create(table: "reaction") { t in
|
|
t.column("interactionId", .numeric)
|
|
.notNull()
|
|
.indexed() // Quicker querying
|
|
.references("interaction", onDelete: .cascade) // Delete if Interaction deleted
|
|
t.column("serverHash", .text)
|
|
t.column("timestampMs", .text)
|
|
.notNull()
|
|
t.column("authorId", .text)
|
|
.notNull()
|
|
.indexed() // Quicker querying
|
|
t.column("emoji", .text)
|
|
.notNull()
|
|
.indexed() // Quicker querying
|
|
t.column("count", .integer)
|
|
.notNull()
|
|
.defaults(to: 0)
|
|
t.column("sortId", .integer)
|
|
.notNull()
|
|
.defaults(to: 0)
|
|
|
|
/// A specific author should only be able to have a single instance of each emoji on a particular interaction
|
|
t.uniqueKey(["interactionId", "emoji", "authorId"])
|
|
}
|
|
|
|
Storage.update(progress: 1, for: self, in: target, using: dependencies)
|
|
}
|
|
}
|