Skip to content

Commit

Permalink
poll-answers data-plane: add pollAnswerCount, pollAnswers to post_agg…
Browse files Browse the repository at this point in the history
… table
  • Loading branch information
keaysma committed Dec 15, 2024
1 parent 0db3150 commit 55baf04
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,29 @@ export async function up(db: Kysely<unknown>): Promise<void> {
// Aids in index uniqueness plus answer counting
.addUniqueConstraint('poll_answer_unique_subject_answer', ['subject', 'answer', 'creator'])
.execute()

await db.schema
.alterTable('post_agg')
.addColumn('pollAnswerCount', 'bigint', (col) => col.notNull().defaultTo(0))
.execute()

await db.schema
.alterTable('post_agg')
.addColumn('pollAnswers', 'json', (col) => col.notNull().defaultTo(sql`${JSON.stringify([])}`))
.execute()

}

export async function down(db: Kysely<unknown>): Promise<void> {
await db.schema.dropTable('poll_answer').execute()

await db.schema
.alterTable('post_agg')
.dropColumn('pollAnswerCount')
.execute()

await db.schema
.alterTable('post_agg')
.dropColumn('pollAnswers')
.execute()
}
2 changes: 2 additions & 0 deletions packages/bsky/src/data-plane/server/db/tables/post-agg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface PostAgg {
replyCount: Generated<number>
repostCount: Generated<number>
quoteCount: Generated<number>
pollAnswerCount: Generated<number>
pollAnswers: Generated<number[]>
}

export type PartialDB = {
Expand Down

0 comments on commit 55baf04

Please sign in to comment.