Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the meta_posts data model to split the prior single votes integer into separate upvotes and downvotes columns, along with a migration to backfill existing rows.
Changes:
- Replace
MetaPost.voteswithMetaPost.upvotesandMetaPost.downvotesin Prisma schema. - Add a SQL migration that adds the two new columns, backfills from
votes, then dropsvotes.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| sw-dash/prisma/schema.prisma | Updates Prisma model for MetaPost to use upvotes/downvotes instead of votes. |
| sw-dash/prisma/migrations/20260329000000_split_meta_votes/migration.sql | Migrates meta_posts table by adding new columns, backfilling from votes, and dropping votes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| UPDATE `meta_posts` SET `upvotes` = GREATEST(`votes`, 0), `downvotes` = GREATEST(-`votes`, 0); | ||
|
|
||
| ALTER TABLE `meta_posts` DROP COLUMN `votes`; |
There was a problem hiding this comment.
This migration drops the votes column, but sw-bot still reads/updates meta_posts.votes directly (e.g., UPDATE meta_posts SET votes = votes + %s ... and SELECT votes ...). Deploying this migration without updating the bot will cause runtime SQL errors. Consider either updating sw-bot to use the new columns in the same rollout, or keeping a backward-compatible votes column (e.g., generated from upvotes - downvotes) until all consumers are migrated.
| ALTER TABLE `meta_posts` DROP COLUMN `votes`; | |
| -- NOTE: Intentionally keeping the `votes` column for backward compatibility with existing consumers (e.g., sw-bot). | |
| -- Once all consumers are migrated to use `upvotes` and `downvotes`, a separate migration can safely drop `votes`. |
| @@ -456,7 +456,8 @@ model SpotCheck { | |||
| model MetaPost { | |||
| id Int @id @default(autoincrement()) | |||
| text String @db.Text | |||
There was a problem hiding this comment.
The Prisma model removes the votes field entirely. sw-bot currently depends on a meta_posts.votes column for reads/writes, so this schema change will break that integration unless the bot is updated (or the DB keeps a compatible votes column/view).
| text String @db.Text | |
| text String @db.Text | |
| votes Int @default(0) // legacy column used by sw-bot |
No description provided.