-
Notifications
You must be signed in to change notification settings - Fork 65
Migrate issuecomment table to i64 ids #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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? | ||
| begin; commit; | ||
| 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. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: (But the difference is unlikely to ever matter.)
Suggested change
|
||||||
|
|
||||||
| 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; | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
| ); | ||||||
| let payload = serde_json::to_string(&btreemap!("body" => text))?; | ||||||
| Ok(self.patch(&url, &payload)?.error_for_status()?.json()?) | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
| }, | ||
|
|
@@ -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, | ||
|
|
@@ -1340,7 +1340,7 @@ impl<'a> RfcBotComment<'a> { | |
| "issues" | ||
| }, | ||
| number = issue.number, | ||
| id = comment_id as u32, | ||
| id = comment_id as u64, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here as well? |
||
| ); | ||
| msg.push_str(&url); | ||
| } | ||
|
|
@@ -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 { | ||
|
|
||
There was a problem hiding this comment.
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.