Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions migrations/2026-04-23-000918_to_bigint/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- TODO: is there a reasonable rollback procedure? I think we could undo the
-- data type changes, but it would likely mean deleting some comments from the
-- database that can no longer be represented. Is that a reasonable tradeoff?
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For rollback deleting out of range comment IDs seems to be the only option.

But we could keep a copy of those comments (in the migrated but un-rolled-back database), and move them across once we have a successful future migration.

begin; commit;
56 changes: 56 additions & 0 deletions migrations/2026-04-23-000918_to_bigint/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
begin;

-- Update all issuecomment referencing columns to bigints

alter table issuecomment alter column id set data type bigint;

alter table fcp_concern alter column fk_initiating_comment set data type bigint;
alter table fcp_concern alter column fk_resolved_comment set data type bigint;

alter table fcp_proposal alter column fk_bot_tracking_comment set data type bigint;
alter table fcp_proposal alter column fk_initiating_comment set data type bigint;

alter table poll alter column fk_bot_tracking_comment set data type bigint;
alter table poll alter column fk_initiating_comment set data type bigint;

alter table rfc_feedback_request alter column fk_feedback_comment set data type bigint;

-- Drop all foreign key constraints so that we can update values one by one.

alter table fcp_concern drop constraint fcp_concern_fk_initiating_comment_fkey;
alter table fcp_concern drop constraint fcp_concern_fk_resolved_comment_fkey;

alter table fcp_proposal drop constraint fcp_proposal_fk_bot_tracking_comment_fkey;
alter table fcp_proposal drop constraint fcp_proposal_fk_initiating_comment_fkey;

alter table poll drop constraint poll_fk_bot_tracking_comment_fkey;
alter table poll drop constraint poll_fk_initiating_comment_fkey;

alter table rfc_feedback_request drop constraint rfc_feedback_request_fk_feedback_comment_fkey;

-- Then update all the values to be u64'd, not i32 storing u32 value.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nitpick: Technically the representation is unsigned, but the range is 0..=i64::MAX:
https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-INT

(But the difference is unlikely to ever matter.)

Suggested change
-- Then update all the values to be u64'd, not i32 storing u32 value.
-- Then update all the values to be unsigned in an i64 field, not i32 storing u32 value.


update fcp_concern set fk_initiating_comment = fk_initiating_comment::bigint + 4294967296 where fk_initiating_comment < 0;
update fcp_concern set fk_resolved_comment = fk_resolved_comment::bigint + 4294967296 where fk_resolved_comment < 0;

update fcp_proposal set fk_bot_tracking_comment = fk_bot_tracking_comment::bigint + 4294967296 where fk_bot_tracking_comment < 0;
update fcp_proposal set fk_initiating_comment = fk_initiating_comment::bigint + 4294967296 where fk_initiating_comment < 0;

update poll set fk_bot_tracking_comment = fk_bot_tracking_comment::bigint + 4294967296 where fk_bot_tracking_comment < 0;
update poll set fk_initiating_comment = fk_initiating_comment::bigint + 4294967296 where fk_initiating_comment < 0;

update rfc_feedback_request set fk_feedback_comment = fk_feedback_comment::bigint + 4294967296 where fk_feedback_comment < 0;

update issuecomment set id = id::bigint + 4294967296 where id < 0;

-- Then re-create the foreign key constraints.

alter table fcp_concern add CONSTRAINT fcp_concern_fk_initiating_comment_fkey FOREIGN KEY (fk_initiating_comment) REFERENCES issuecomment(id);
alter table fcp_concern add CONSTRAINT fcp_concern_fk_resolved_comment_fkey FOREIGN KEY (fk_resolved_comment) REFERENCES issuecomment(id);
alter table fcp_proposal add CONSTRAINT fcp_proposal_fk_bot_tracking_comment_fkey FOREIGN KEY (fk_bot_tracking_comment) REFERENCES issuecomment(id);
alter table fcp_proposal add CONSTRAINT fcp_proposal_fk_initiating_comment_fkey FOREIGN KEY (fk_initiating_comment) REFERENCES issuecomment(id);
alter table poll add CONSTRAINT poll_fk_bot_tracking_comment_fkey FOREIGN KEY (fk_bot_tracking_comment) REFERENCES issuecomment(id);
alter table poll add CONSTRAINT poll_fk_initiating_comment_fkey FOREIGN KEY (fk_initiating_comment) REFERENCES issuecomment(id);
alter table rfc_feedback_request add CONSTRAINT rfc_feedback_request_fk_feedback_comment_fkey FOREIGN KEY (fk_feedback_comment) REFERENCES issuecomment(id);

commit;
3 changes: 1 addition & 2 deletions src/domain/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ pub struct Issue {
#[table_name = "issuecomment"]
#[changeset_options(treat_none_as_null = "true")]
pub struct IssueComment {
#[serde(serialize_with = "super::unsigned")]
pub id: i32,
pub id: i64,
pub fk_issue: i32,
#[serde(serialize_with = "super::unsigned")]
pub fk_user: i32,
Expand Down
36 changes: 14 additions & 22 deletions src/domain/rfcbot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ use super::schema::*;
pub struct NewPoll<'a> {
pub fk_issue: i32,
pub fk_initiator: i32,
//#[serde(serialize_with = "super::unsigned")]
pub fk_initiating_comment: i32,
//#[serde(serialize_with = "super::unsigned")]
pub fk_bot_tracking_comment: i32,
pub fk_initiating_comment: i64,
pub fk_bot_tracking_comment: i64,
pub poll_question: &'a str,
pub poll_created_at: NaiveDateTime,
pub poll_closed: bool,
Expand All @@ -25,10 +23,8 @@ pub struct Poll {
pub id: i32,
pub fk_issue: i32,
pub fk_initiator: i32,
#[serde(serialize_with = "super::unsigned")]
pub fk_initiating_comment: i32,
#[serde(serialize_with = "super::unsigned")]
pub fk_bot_tracking_comment: i32,
pub fk_initiating_comment: i64,
pub fk_bot_tracking_comment: i64,
pub poll_question: String,
pub poll_created_at: NaiveDateTime,
pub poll_closed: bool,
Expand All @@ -40,11 +36,9 @@ pub struct Poll {
pub struct NewFcpProposal<'a> {
pub fk_issue: i32,
pub fk_initiator: i32,
//#[serde(serialize_with = "super::unsigned")]
pub fk_initiating_comment: i32,
pub fk_initiating_comment: i64,
pub disposition: &'a str,
//#[serde(serialize_with = "super::unsigned")]
pub fk_bot_tracking_comment: i32,
pub fk_bot_tracking_comment: i64,
pub fcp_start: Option<NaiveDateTime>,
pub fcp_closed: bool,
}
Expand Down Expand Up @@ -77,11 +71,9 @@ pub struct FcpProposal {
pub id: i32,
pub fk_issue: i32,
pub fk_initiator: i32,
#[serde(serialize_with = "super::unsigned")]
pub fk_initiating_comment: i32,
pub fk_initiating_comment: i64,
pub disposition: String,
#[serde(serialize_with = "super::unsigned")]
pub fk_bot_tracking_comment: i32,
pub fk_bot_tracking_comment: i64,
pub fcp_start: Option<NaiveDateTime>,
pub fcp_closed: bool,
}
Expand Down Expand Up @@ -110,9 +102,9 @@ pub struct FcpReviewRequest {
pub struct NewFcpConcern<'a> {
pub fk_proposal: i32,
pub fk_initiator: i32,
pub fk_resolved_comment: Option<i32>,
pub fk_resolved_comment: Option<i64>,
pub name: &'a str,
pub fk_initiating_comment: i32,
pub fk_initiating_comment: i64,
}

#[derive(AsChangeset, Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Queryable)]
Expand All @@ -121,9 +113,9 @@ pub struct FcpConcern {
pub id: i32,
pub fk_proposal: i32,
pub fk_initiator: i32,
pub fk_resolved_comment: Option<i32>,
pub fk_resolved_comment: Option<i64>,
pub name: String,
pub fk_initiating_comment: i32,
pub fk_initiating_comment: i64,
}

#[derive(Clone, Debug, Eq, Insertable, Ord, PartialEq, PartialOrd)]
Expand All @@ -132,7 +124,7 @@ pub struct NewFeedbackRequest {
pub fk_initiator: i32,
pub fk_requested: i32,
pub fk_issue: i32,
pub fk_feedback_comment: Option<i32>,
pub fk_feedback_comment: Option<i64>,
}

#[derive(AsChangeset, Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Queryable)]
Expand All @@ -142,5 +134,5 @@ pub struct FeedbackRequest {
pub fk_initiator: i32,
pub fk_requested: i32,
pub fk_issue: i32,
pub fk_feedback_comment: Option<i32>,
pub fk_feedback_comment: Option<i64>,
}
32 changes: 16 additions & 16 deletions src/domain/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ table! {
fk_initiator -> Int4,
/// The `fk_resolved_comment` column of the `fcp_concern` table.
///
/// Its SQL type is `Nullable<Int4>`.
/// Its SQL type is `Nullable<Int8>`.
///
/// (Automatically generated by Diesel.)
fk_resolved_comment -> Nullable<Int4>,
fk_resolved_comment -> Nullable<Int8>,
/// The `name` column of the `fcp_concern` table.
///
/// Its SQL type is `Varchar`.
Expand All @@ -35,10 +35,10 @@ table! {
name -> Varchar,
/// The `fk_initiating_comment` column of the `fcp_concern` table.
///
/// Its SQL type is `Int4`.
/// Its SQL type is `Int8`.
///
/// (Automatically generated by Diesel.)
fk_initiating_comment -> Int4,
fk_initiating_comment -> Int8,
}
}

Expand Down Expand Up @@ -67,10 +67,10 @@ table! {
fk_initiator -> Int4,
/// The `fk_initiating_comment` column of the `fcp_proposal` table.
///
/// Its SQL type is `Int4`.
/// Its SQL type is `Int8`.
///
/// (Automatically generated by Diesel.)
fk_initiating_comment -> Int4,
fk_initiating_comment -> Int8,
/// The `disposition` column of the `fcp_proposal` table.
///
/// Its SQL type is `Varchar`.
Expand All @@ -79,10 +79,10 @@ table! {
disposition -> Varchar,
/// The `fk_bot_tracking_comment` column of the `fcp_proposal` table.
///
/// Its SQL type is `Int4`.
/// Its SQL type is `Int8`.
///
/// (Automatically generated by Diesel.)
fk_bot_tracking_comment -> Int4,
fk_bot_tracking_comment -> Int8,
/// The `fcp_start` column of the `fcp_proposal` table.
///
/// Its SQL type is `Nullable<Timestamp>`.
Expand Down Expand Up @@ -287,10 +287,10 @@ table! {
issuecomment (id) {
/// The `id` column of the `issuecomment` table.
///
/// Its SQL type is `Int4`.
/// Its SQL type is `Int8`.
///
/// (Automatically generated by Diesel.)
id -> Int4,
id -> Int8,
/// The `fk_issue` column of the `issuecomment` table.
///
/// Its SQL type is `Int4`.
Expand Down Expand Up @@ -467,16 +467,16 @@ table! {
fk_initiator -> Int4,
/// The `fk_initiating_comment` column of the `poll` table.
///
/// Its SQL type is `Int4`.
/// Its SQL type is `Int8`.
///
/// (Automatically generated by Diesel.)
fk_initiating_comment -> Int4,
fk_initiating_comment -> Int8,
/// The `fk_bot_tracking_comment` column of the `poll` table.
///
/// Its SQL type is `Int4`.
/// Its SQL type is `Int8`.
///
/// (Automatically generated by Diesel.)
fk_bot_tracking_comment -> Int4,
fk_bot_tracking_comment -> Int8,
/// The `poll_question` column of the `poll` table.
///
/// Its SQL type is `Varchar`.
Expand Down Expand Up @@ -677,10 +677,10 @@ table! {
fk_issue -> Int4,
/// The `fk_feedback_comment` column of the `rfc_feedback_request` table.
///
/// Its SQL type is `Nullable<Int4>`.
/// Its SQL type is `Nullable<Int8>`.
///
/// (Automatically generated by Diesel.)
fk_feedback_comment -> Nullable<Int4>,
fk_feedback_comment -> Nullable<Int8>,
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/github/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ impl Client {
pub fn edit_comment(
&self,
repo: &str,
comment_num: i32,
comment_num: i64,
text: &str,
) -> DashResult<CommentFromJson> {
let url = format!(
"{}/repos/{}/issues/comments/{}",
BASE_URL, repo, comment_num as u32
BASE_URL, repo, comment_num as u64
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As a precaution, would try_from() be better, just in case any negative numbers make it through?

Suggested change
BASE_URL, repo, comment_num as u64
BASE_URL, repo, u64::try_from(comment_num).expect("id is a non-negative i64")

);
let payload = serde_json::to_string(&btreemap!("body" => text))?;
Ok(self.patch(&url, &payload)?.error_for_status()?.json()?)
Expand Down
5 changes: 3 additions & 2 deletions src/github/models.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2016 Adam Perry. Dual-licensed MIT and Apache 2.0 (see LICENSE files for details).

use std::i32;
use std::convert::TryInto;

use chrono::{DateTime, Utc};

Expand Down Expand Up @@ -104,7 +105,7 @@ impl IssueFromJson {

#[derive(Debug, Deserialize)]
pub struct CommentFromJson {
pub id: u32,
pub id: u64,
pub html_url: String,
pub body: String,
pub user: GitHubUser,
Expand Down Expand Up @@ -141,7 +142,7 @@ impl CommentFromJson {
.first::<i32>(&*conn)?;

Ok(IssueComment {
id: self.id as i32,
id: self.id.try_into().expect("id fits into i64"),
fk_issue: issue_id,
fk_user: self.user.id,
body: self.body.replace(0x00 as char, ""),
Expand Down
10 changes: 5 additions & 5 deletions src/github/nag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,12 +1151,12 @@ enum CommentType<'a> {
FcpProposalCancelled(&'a GitHubUser),
FcpAllReviewedNoConcerns {
author: &'a GitHubUser,
status_comment_id: i32,
status_comment_id: i64,
added_label: bool,
},
FcpWeekPassed {
author: &'a GitHubUser,
status_comment_id: i32,
status_comment_id: i64,
added_label: bool,
disposition: FcpDisposition,
},
Expand Down Expand Up @@ -1330,7 +1330,7 @@ impl<'a> RfcBotComment<'a> {
}
}

fn add_comment_url(issue: &Issue, msg: &mut String, comment_id: i32) {
fn add_comment_url(issue: &Issue, msg: &mut String, comment_id: i64) {
let url = format!(
"https://github.com/{repo}/{typ}/{number}#issuecomment-{id}",
repo = issue.repository,
Expand All @@ -1340,7 +1340,7 @@ impl<'a> RfcBotComment<'a> {
"issues"
},
number = issue.number,
id = comment_id as u32,
id = comment_id as u64,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

And here as well?

);
msg.push_str(&url);
}
Expand All @@ -1352,7 +1352,7 @@ impl<'a> RfcBotComment<'a> {
}
}

fn post(&self, existing_comment: Option<i32>) -> DashResult<CommentFromJson> {
fn post(&self, existing_comment: Option<i64>) -> DashResult<CommentFromJson> {
use crate::config::CONFIG;

if CONFIG.post_comments {
Expand Down