Skip to content

Commit 13d87d5

Browse files
erikjohnstonanp
authored andcommitted
Upgrade diesel from 0.16 -> 1.x (#229)
See [diesel changelog](https://github.com/diesel-rs/diesel/blob/master/CHANGELOG.md) for details about the API changes. Admittedly this is mainly motivated because I was getting confused at the old `on_conflict` syntax compared with newer versions of diesel. (I also had to add `#![feature(never_type)]` to make rfcbot compile at all). (I cheekily ran cargo update as well, which I had forgotten about).
1 parent 36ff9b5 commit 13d87d5

File tree

7 files changed

+120
-148
lines changed

7 files changed

+120
-148
lines changed

Cargo.lock

Lines changed: 42 additions & 99 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ hyper = "0.10"
1212
hyper-native-tls = "0.2.1"
1313
lazy_static = "0.2.0"
1414
log = "0.3.6"
15-
r2d2 = "0.7.1"
16-
r2d2-diesel = "0.16"
1715
rocket = "0.3.3"
1816
rocket_codegen = "0.3.3"
1917
rocket_contrib = "0.3.3"
@@ -33,10 +31,5 @@ version = "0.4"
3331

3432
[dependencies.diesel]
3533
default-features = false
36-
features = ["postgres", "chrono", "large-tables"]
37-
version = "0.16"
38-
39-
[dependencies.diesel_codegen]
40-
default-features = false
41-
features = ["dotenv", "postgres"]
42-
version = "0.16"
34+
features = ["postgres", "chrono", "r2d2", "32-column-tables"]
35+
version = "1.3.2"

src/domain/schema.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,23 @@ joinable!(poll -> githubuser (fk_initiator));
170170
joinable!(poll -> issue (fk_issue));
171171
joinable!(poll_response_request -> poll (fk_poll));
172172
joinable!(poll_response_request -> githubuser (fk_respondent));
173+
174+
175+
allow_tables_to_appear_in_same_query!(fcp_concern, githubuser);
176+
allow_tables_to_appear_in_same_query!(fcp_concern, fcp_proposal);
177+
allow_tables_to_appear_in_same_query!(fcp_proposal, githubuser);
178+
allow_tables_to_appear_in_same_query!(fcp_proposal, issue);
179+
allow_tables_to_appear_in_same_query!(fcp_review_request, fcp_proposal);
180+
allow_tables_to_appear_in_same_query!(fcp_review_request, githubuser);
181+
allow_tables_to_appear_in_same_query!(issue, milestone);
182+
allow_tables_to_appear_in_same_query!(issuecomment, issue);
183+
allow_tables_to_appear_in_same_query!(issuecomment, githubuser);
184+
allow_tables_to_appear_in_same_query!(milestone, githubuser);
185+
allow_tables_to_appear_in_same_query!(pullrequest, githubuser);
186+
allow_tables_to_appear_in_same_query!(pullrequest, milestone);
187+
allow_tables_to_appear_in_same_query!(rfc_feedback_request, issuecomment);
188+
allow_tables_to_appear_in_same_query!(rfc_feedback_request, issue);
189+
allow_tables_to_appear_in_same_query!(poll, githubuser);
190+
allow_tables_to_appear_in_same_query!(poll, issue);
191+
allow_tables_to_appear_in_same_query!(poll_response_request, poll);
192+
allow_tables_to_appear_in_same_query!(poll_response_request, githubuser);

src/error.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::io;
77
use diesel;
88
use handlebars;
99
use hyper;
10-
use r2d2;
1110
use serde_json;
1211

1312
pub type DashResult<T> = std::result::Result<T, DashError>;
@@ -17,7 +16,7 @@ pub enum DashError {
1716
Hyper(hyper::error::Error),
1817
Io(io::Error),
1918
Serde(serde_json::error::Error),
20-
R2d2Timeout(r2d2::GetTimeout),
19+
R2d2(diesel::r2d2::PoolError),
2120
DieselError(diesel::result::Error),
2221
Template(handlebars::RenderError),
2322
Misc(Option<String>),
@@ -39,8 +38,8 @@ impl From<serde_json::error::Error> for DashError {
3938
fn from(e: serde_json::error::Error) -> Self { DashError::Serde(e) }
4039
}
4140

42-
impl From<r2d2::GetTimeout> for DashError {
43-
fn from(e: r2d2::GetTimeout) -> Self { DashError::R2d2Timeout(e) }
41+
impl From<diesel::r2d2::PoolError> for DashError {
42+
fn from(e: diesel::r2d2::PoolError) -> Self { DashError::R2d2(e) }
4443
}
4544

4645
impl From<diesel::result::Error> for DashError {

src/github/mod.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub mod webhooks;
1010
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};
1111
use diesel::prelude::*;
1212
use diesel::pg::PgConnection;
13-
use diesel::pg::upsert::*;
1413
use diesel;
1514

1615
use DB_POOL;
@@ -56,7 +55,7 @@ pub fn record_successful_update(ingest_start: NaiveDateTime) -> DashResult<()> {
5655
message: None,
5756
};
5857

59-
diesel::insert(&sync_record).into(githubsync).execute(conn)?;
58+
diesel::insert_into(githubsync).values(&sync_record).execute(conn)?;
6059
Ok(())
6160
}
6261

@@ -123,9 +122,14 @@ pub fn handle_pr(conn: &PgConnection, pr: PullRequestFromJson, repo: &str) -> Da
123122
}
124123

125124
let pr: PullRequest = pr.with_repo(repo);
126-
diesel::insert(&pr.on_conflict((repository, number), do_update().set(&pr)))
127-
.into(pullrequest)
125+
126+
diesel::insert_into(pullrequest)
127+
.values(&pr)
128+
.on_conflict((repository, number))
129+
.do_update()
130+
.set(&pr)
128131
.execute(conn)?;
132+
129133
Ok(())
130134
}
131135

@@ -144,8 +148,8 @@ pub fn handle_comment(conn: &PgConnection, comment: CommentFromJson, repo: &str)
144148
.set(&comment)
145149
.execute(conn)?;
146150
} else {
147-
diesel::insert(&comment)
148-
.into(issuecomment::table)
151+
diesel::insert_into(issuecomment::table)
152+
.values(&comment)
149153
.execute(conn)?;
150154

151155
ok_or!(nag::update_nags(&comment), why => {
@@ -170,25 +174,35 @@ pub fn handle_issue(conn: &PgConnection, issue: IssueFromJson, repo: &str) -> Da
170174
let (i, milestone) = issue.with_repo(repo);
171175

172176
if let Some(milestone) = milestone {
173-
diesel::insert(&milestone.on_conflict(milestone::id, do_update().set(&milestone)))
174-
.into(milestone::table)
177+
diesel::insert_into(milestone::table)
178+
.values(&milestone)
179+
.on_conflict(milestone::id)
180+
.do_update()
181+
.set(&milestone)
175182
.execute(conn)?;
176183
}
177184

178185
// handle issue itself
179186
{
180187
use domain::schema::issue::dsl::*;
181-
diesel::insert(&i.on_conflict((repository, number), do_update().set(&i)))
182-
.into(issue)
188+
189+
diesel::insert_into(issue)
190+
.values(&i)
191+
.on_conflict((repository, number))
192+
.do_update()
193+
.set(&i)
183194
.execute(conn)?;
184195
}
185196

186197
Ok(())
187198
}
188199

189200
pub fn handle_user(conn: &PgConnection, user: &GitHubUser) -> DashResult<()> {
190-
diesel::insert(&user.on_conflict(githubuser::id, do_update().set(user)))
191-
.into(githubuser::table)
201+
diesel::insert_into(githubuser::table)
202+
.values(user)
203+
.on_conflict(githubuser::id)
204+
.do_update()
205+
.set(user)
192206
.execute(conn)?;
193207
Ok(())
194208
}

src/github/nag.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,9 @@ fn post_insert_comment(issue: &Issue, comment: CommentType) -> DashResult<IssueC
699699
// we need to insert it
700700
let comment = comment.with_repo(&issue.repository)?;
701701
if let Err(why) =
702-
diesel::insert(&comment)
703-
.into(issuecomment::table)
704-
.execute(conn)
702+
diesel::insert_into(issuecomment::table)
703+
.values(&comment)
704+
.execute(conn)
705705
{
706706
warn!("issue inserting new record, maybe received webhook for it: {:?}",
707707
why);
@@ -775,7 +775,9 @@ fn process_poll
775775
poll_closed: false,
776776
poll_teams: &*teams_str,
777777
};
778-
let new_poll = diesel::insert(&new_poll).into(poll).get_result::<Poll>(conn)?;
778+
let new_poll = diesel::insert_into(poll)
779+
.values(&new_poll)
780+
.get_result::<Poll>(conn)?;
779781

780782
debug!("poll inserted into the database");
781783

@@ -791,8 +793,8 @@ fn process_poll
791793
})
792794
.collect::<Vec<_>>();
793795

794-
diesel::insert(&response_requests)
795-
.into(poll_response_request::table)
796+
diesel::insert_into(poll_response_request::table)
797+
.values(&response_requests)
796798
.execute(conn)?;
797799

798800
// they're in the database, but now we need them paired with githubuser
@@ -843,8 +845,8 @@ fn process_fcp_propose
843845
fcp_start: None,
844846
fcp_closed: false,
845847
};
846-
let proposal = diesel::insert(&proposal)
847-
.into(fcp_proposal)
848+
let proposal = diesel::insert_into(fcp_proposal)
849+
.values(&proposal)
848850
.get_result::<FcpProposal>(conn)?;
849851

850852
debug!("proposal inserted into the database");
@@ -861,8 +863,8 @@ fn process_fcp_propose
861863
})
862864
.collect::<Vec<_>>();
863865

864-
diesel::insert(&review_requests)
865-
.into(fcp_review_request::table)
866+
diesel::insert_into(fcp_review_request::table)
867+
.values(&review_requests)
866868
.execute(conn)?;
867869

868870
// they're in the database, but now we need them paired with githubuser
@@ -940,7 +942,9 @@ fn process_new_concern
940942
name: concern_name,
941943
fk_initiating_comment: comment.id,
942944
};
943-
diesel::insert(&new_concern).into(fcp_concern).execute(conn)?;
945+
diesel::insert_into(fcp_concern)
946+
.values(&new_concern)
947+
.execute(conn)?;
944948

945949
// Take us out of FCP and back into PFCP if need be:
946950
if proposal.fcp_start.is_some() {
@@ -1025,7 +1029,9 @@ fn process_feedback_request(author: &GitHubUser, issue: &Issue, username: &str)
10251029
fk_issue: issue.id,
10261030
fk_feedback_comment: None,
10271031
};
1028-
diesel::insert(&new_request).into(rfc_feedback_request).execute(conn)?;
1032+
diesel::insert_into(rfc_feedback_request)
1033+
.values(&new_request)
1034+
.execute(conn)?;
10291035
}
10301036

10311037
Ok(())
@@ -1222,7 +1228,7 @@ impl<'a> RfcBotComment<'a> {
12221228
if let Some(comment_id) = existing_comment {
12231229
self.maybe_add_pfcp_label();
12241230
GH.edit_comment(&self.issue.repository, comment_id, &self.body)
1225-
} else {
1231+
} else {
12261232
GH.new_comment(&self.issue.repository, self.issue.number, &self.body)
12271233
}
12281234
} else {

src/main.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#![feature(never_type)]
22

33
#![feature(plugin)]
4+
#![feature(never_type)]
45
#![plugin(rocket_codegen)]
56

67
extern crate chrono;
78
extern crate crypto;
89
#[macro_use]
910
extern crate diesel;
10-
#[macro_use]
11-
extern crate diesel_codegen;
1211
extern crate dotenv;
1312
extern crate env_logger;
1413
extern crate handlebars;
@@ -20,8 +19,6 @@ extern crate hyper_native_tls;
2019
extern crate lazy_static;
2120
#[macro_use]
2221
extern crate log;
23-
extern crate r2d2;
24-
extern crate r2d2_diesel;
2522
extern crate rocket;
2623
extern crate rocket_contrib;
2724
extern crate serde;
@@ -50,10 +47,10 @@ mod teams;
5047

5148
use chrono::Local;
5249
use diesel::pg::PgConnection;
50+
use diesel::r2d2::Pool;
51+
use diesel::r2d2::ConnectionManager;
5352
use env_logger::LogBuilder;
5453
use log::LogRecord;
55-
use r2d2::Pool;
56-
use r2d2_diesel::ConnectionManager;
5754

5855
use config::CONFIG;
5956

@@ -96,12 +93,12 @@ lazy_static! {
9693
pub static ref DB_POOL: Pool<ConnectionManager<PgConnection>> = {
9794
info!("Initializing database connection pool.");
9895

99-
let config = r2d2::Config::builder()
100-
.pool_size(CONFIG.db_pool_size)
101-
.build();
102-
10396
let manager = ConnectionManager::<PgConnection>::new(CONFIG.db_url.clone());
104-
match Pool::new(config, manager) {
97+
98+
match Pool::builder()
99+
.max_size(CONFIG.db_pool_size)
100+
.build(manager)
101+
{
105102
Ok(p) => {
106103
info!("DB connection pool established.");
107104
p

0 commit comments

Comments
 (0)