Skip to content

add cols#87

Open
Nullskulls wants to merge 1 commit intomainfrom
track-up-and-downvotes-seperately
Open

add cols#87
Nullskulls wants to merge 1 commit intomainfrom
track-up-and-downvotes-seperately

Conversation

@Nullskulls
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.votes with MetaPost.upvotes and MetaPost.downvotes in Prisma schema.
  • Add a SQL migration that adds the two new columns, backfills from votes, then drops votes.

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`;
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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`.

Copilot uses AI. Check for mistakes.
@@ -456,7 +456,8 @@ model SpotCheck {
model MetaPost {
id Int @id @default(autoincrement())
text String @db.Text
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
text String @db.Text
text String @db.Text
votes Int @default(0) // legacy column used by sw-bot

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants