Rename all "index" columns to "order"

This commit is contained in:
Justin Mazzocchi 2021-01-31 07:49:09 -08:00
parent 2dae234849
commit a6cbe6e96d
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
8 changed files with 19 additions and 17 deletions

View file

@ -7,14 +7,14 @@ import Mastodon
struct AccountPinnedStatusJoin: ContentDatabaseRecord {
let accountId: Account.Id
let statusId: Status.Id
let index: Int
let order: Int
}
extension AccountPinnedStatusJoin {
enum Columns {
static let accountId = Column(CodingKeys.accountId)
static let statusId = Column(CodingKeys.statusId)
static let index = Column(CodingKeys.index)
static let order = Column(CodingKeys.order)
}
static let status = belongsTo(StatusRecord.self)

View file

@ -58,7 +58,7 @@ extension AccountRecord {
static let identityProofs = hasMany(IdentityProofRecord.self)
static let featuredTags = hasMany(FeaturedTagRecord.self)
static let pinnedStatusJoins = hasMany(AccountPinnedStatusJoin.self)
.order(AccountPinnedStatusJoin.Columns.index)
.order(AccountPinnedStatusJoin.Columns.order)
static let pinnedStatuses = hasMany(
StatusRecord.self,
through: pinnedStatusJoins,

View file

@ -226,7 +226,7 @@ extension ContentDatabase {
.references("statusRecord", onDelete: .cascade)
t.column("statusId", .text).indexed().notNull()
.references("statusRecord", onDelete: .cascade)
t.column("index", .integer).notNull()
t.column("order", .integer).notNull()
t.primaryKey(["parentId", "statusId"], onConflict: .replace)
}
@ -236,7 +236,7 @@ extension ContentDatabase {
.references("statusRecord", onDelete: .cascade)
t.column("statusId", .text).indexed().notNull()
.references("statusRecord", onDelete: .cascade)
t.column("index", .integer).notNull()
t.column("order", .integer).notNull()
t.primaryKey(["parentId", "statusId"], onConflict: .replace)
}
@ -246,7 +246,7 @@ extension ContentDatabase {
.references("accountRecord", onDelete: .cascade)
t.column("statusId", .text).indexed().notNull()
.references("statusRecord", onDelete: .cascade)
t.column("index", .integer).notNull()
t.column("order", .integer).notNull()
t.primaryKey(["accountId", "statusId"], onConflict: .replace)
}

View file

@ -135,12 +135,12 @@ public extension ContentDatabase {
databaseWriter.writePublisher {
for (index, status) in context.ancestors.enumerated() {
try status.save($0)
try StatusAncestorJoin(parentId: parentId, statusId: status.id, index: index).save($0)
try StatusAncestorJoin(parentId: parentId, statusId: status.id, order: index).save($0)
}
for (index, status) in context.descendants.enumerated() {
try status.save($0)
try StatusDescendantJoin(parentId: parentId, statusId: status.id, index: index).save($0)
try StatusDescendantJoin(parentId: parentId, statusId: status.id, order: index).save($0)
}
try StatusAncestorJoin.filter(
@ -161,7 +161,7 @@ public extension ContentDatabase {
databaseWriter.writePublisher {
for (index, status) in pinnedStatuses.enumerated() {
try status.save($0)
try AccountPinnedStatusJoin(accountId: accountId, statusId: status.id, index: index).save($0)
try AccountPinnedStatusJoin(accountId: accountId, statusId: status.id, order: index).save($0)
}
try AccountPinnedStatusJoin.filter(

View file

@ -7,14 +7,14 @@ import Mastodon
struct StatusAncestorJoin: ContentDatabaseRecord {
let parentId: Status.Id
let statusId: Status.Id
let index: Int
let order: Int
}
extension StatusAncestorJoin {
enum Columns {
static let parentId = Column(CodingKeys.parentId)
static let statusId = Column(CodingKeys.statusId)
static let index = Column(CodingKeys.index)
static let order = Column(CodingKeys.order)
}
static let status = belongsTo(StatusRecord.self, using: ForeignKey([Columns.statusId]))

View file

@ -7,14 +7,14 @@ import Mastodon
struct StatusDescendantJoin: ContentDatabaseRecord {
let parentId: Status.Id
let statusId: Status.Id
let index: Int
let order: Int
}
extension StatusDescendantJoin {
enum Columns {
static let parentId = Column(CodingKeys.parentId)
static let statusId = Column(CodingKeys.statusId)
static let index = Column(CodingKeys.index)
static let order = Column(CodingKeys.order)
}
static let status = belongsTo(StatusRecord.self, using: ForeignKey([Columns.statusId]))

View file

@ -95,11 +95,11 @@ extension StatusRecord {
static let ancestorJoins = hasMany(
StatusAncestorJoin.self,
using: ForeignKey([StatusAncestorJoin.Columns.parentId]))
.order(StatusAncestorJoin.Columns.index)
.order(StatusAncestorJoin.Columns.order)
static let descendantJoins = hasMany(
StatusDescendantJoin.self,
using: ForeignKey([StatusDescendantJoin.Columns.parentId]))
.order(StatusDescendantJoin.Columns.index)
.order(StatusDescendantJoin.Columns.order)
static let ancestors = hasMany(StatusRecord.self,
through: ancestorJoins,
using: StatusAncestorJoin.status)

View file

@ -17,7 +17,8 @@ extension TimelineItemsInfo {
let pinnedStatusInfos: [StatusInfo]
}
static func addingIncludes<T: DerivableRequest>( _ request: T, ordered: Bool) -> T where T.RowDecoder == TimelineRecord {
static func addingIncludes<T: DerivableRequest>( _ request: T,
ordered: Bool) -> T where T.RowDecoder == TimelineRecord {
let statusesAssociation = ordered ? TimelineRecord.orderedStatuses : TimelineRecord.statuses
return request.including(all: StatusInfo.addingIncludes(statusesAssociation).forKey(CodingKeys.statusInfos))
@ -26,7 +27,8 @@ extension TimelineItemsInfo {
.forKey(CodingKeys.pinnedStatusesInfo))
}
static func request(_ request: QueryInterfaceRequest<TimelineRecord>, ordered: Bool) -> QueryInterfaceRequest<Self> {
static func request(_ request: QueryInterfaceRequest<TimelineRecord>,
ordered: Bool) -> QueryInterfaceRequest<Self> {
addingIncludes(request, ordered: ordered).asRequest(of: self)
}