Fixed an issue where the 2.0.2 migration broke the original _003_ migration

pull/667/head
Morgan Pretty 3 years ago
parent c8bcd8fb33
commit d116ac0ebe

@ -175,7 +175,7 @@ enum _001_InitialSetupMigration: Migration {
.notNull() .notNull()
} }
try db.create(table: GroupMember.self) { t in try db.create(table: _006_FixHiddenModAdminSupport.PreMigrationGroupMember.self) { t in
// Note: Since we don't know whether this will be stored against a 'ClosedGroup' or // Note: Since we don't know whether this will be stored against a 'ClosedGroup' or
// an 'OpenGroup' we add the foreign key constraint against the thread itself (which // an 'OpenGroup' we add the foreign key constraint against the thread itself (which
// shares the same 'id' as the 'groupId') so we can cascade delete automatically // shares the same 'id' as the 'groupId') so we can cascade delete automatically

@ -647,11 +647,10 @@ enum _003_YDBToGRDBMigration: Migration {
} }
try groupModel.groupMemberIds.forEach { memberId in try groupModel.groupMemberIds.forEach { memberId in
try GroupMember( try _006_FixHiddenModAdminSupport.PreMigrationGroupMember(
groupId: threadId, groupId: threadId,
profileId: memberId, profileId: memberId,
role: .standard, role: .standard
isHidden: false
).insert(db) ).insert(db)
if !validProfileIds.contains(memberId) { if !validProfileIds.contains(memberId) {
@ -660,11 +659,10 @@ enum _003_YDBToGRDBMigration: Migration {
} }
try groupModel.groupAdminIds.forEach { adminId in try groupModel.groupAdminIds.forEach { adminId in
try GroupMember( try _006_FixHiddenModAdminSupport.PreMigrationGroupMember(
groupId: threadId, groupId: threadId,
profileId: adminId, profileId: adminId,
role: .admin, role: .admin
isHidden: false
).insert(db) ).insert(db)
if !validProfileIds.contains(adminId) { if !validProfileIds.contains(adminId) {
@ -673,11 +671,10 @@ enum _003_YDBToGRDBMigration: Migration {
} }
try (closedGroupZombieMemberIds[legacyThread.uniqueId] ?? []).forEach { zombieId in try (closedGroupZombieMemberIds[legacyThread.uniqueId] ?? []).forEach { zombieId in
try GroupMember( try _006_FixHiddenModAdminSupport.PreMigrationGroupMember(
groupId: threadId, groupId: threadId,
profileId: zombieId, profileId: zombieId,
role: .zombie, role: .zombie
isHidden: false
).insert(db) ).insert(db)
if !validProfileIds.contains(zombieId) { if !validProfileIds.contains(zombieId) {

@ -28,3 +28,41 @@ enum _006_FixHiddenModAdminSupport: Migration {
Storage.update(progress: 1, for: self, in: target) // In case this is the last migration Storage.update(progress: 1, for: self, in: target) // In case this is the last migration
} }
} }
// MARK: - Pre-Migration Types
extension _006_FixHiddenModAdminSupport {
internal struct PreMigrationGroupMember: Codable, PersistableRecord, TableRecord, ColumnExpressible {
public static var databaseTableName: String { "groupMember" }
public typealias Columns = CodingKeys
public enum CodingKeys: String, CodingKey, ColumnExpression {
case groupId
case profileId
case role
}
public enum Role: Int, Codable, DatabaseValueConvertible {
case standard
case zombie
case moderator
case admin
}
public let groupId: String
public let profileId: String
public let role: Role
// MARK: - Initialization
public init(
groupId: String,
profileId: String,
role: Role
) {
self.groupId = groupId
self.profileId = profileId
self.role = role
}
}
}

Loading…
Cancel
Save