Skip to content

Commit 480c6d1

Browse files
committed
More fixes
1 parent 62e009c commit 480c6d1

File tree

12 files changed

+26
-27
lines changed

12 files changed

+26
-27
lines changed

src/admin/migrate.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ pub fn run(_opts: Opts) -> Result<(), Error> {
4242
// let migrations = ;
4343
let mut stdout = std::io::stdout();
4444
let mut harness = HarnessWithOutput::new(conn, &mut stdout);
45-
harness.run_pending_migrations(MIGRATIONS);
45+
harness
46+
.run_pending_migrations(MIGRATIONS)
47+
.expect("failed to run migrations");
4648

4749
println!("==> synchronizing crate categories");
4850
crate::boot::categories::sync_with_connection(CATEGORIES_TOML, conn).unwrap();

src/bin/enqueue-job.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use swirl::schema::background_jobs::dsl::*;
77
use swirl::Job;
88

99
fn main() -> Result<()> {
10-
let conn = db::oneoff_connection()?;
10+
let conn = &mut db::oneoff_connection()?;
1111
let mut args = std::env::args().skip(1);
1212

1313
let job = args.next().unwrap_or_default();

src/bin/monitor.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use cargo_registry::{admin::on_call, db, schema::*};
1111
use diesel::prelude::*;
1212

1313
fn main() -> Result<()> {
14-
let conn = db::oneoff_connection()?;
14+
let conn = &mut db::oneoff_connection()?;
1515

1616
check_failing_background_jobs(conn)?;
1717
check_stalled_update_downloads(conn)?;
@@ -108,7 +108,6 @@ fn check_stalled_update_downloads(conn: &mut PgConnection) -> Result<()> {
108108
/// Check for known spam patterns
109109
fn check_spam_attack(conn: &mut PgConnection) -> Result<()> {
110110
use cargo_registry::sql::canon_crate_name;
111-
use diesel::dsl::*;
112111

113112
const EVENT_KEY: &str = "spam_attack";
114113

@@ -123,7 +122,7 @@ fn check_spam_attack(conn: &mut PgConnection) -> Result<()> {
123122
let mut event_description = None;
124123

125124
let bad_crate: Option<String> = crates::table
126-
.filter(canon_crate_name(crates::name).eq(any(bad_crate_names)))
125+
.filter(canon_crate_name(crates::name).eq_any(bad_crate_names))
127126
.select(crates::name)
128127
.first(conn)
129128
.optional()?;

src/controllers/category.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ pub fn index(req: &mut dyn RequestExt) -> EndpointResult {
1616
let sort = query.get("sort").map_or("alpha", String::as_str);
1717

1818
let conn = &mut req.db_read()?;
19-
let categories =
20-
Category::toplevel(conn, sort, i64::from(options.per_page), i64::from(offset))?;
19+
let categories = Category::toplevel(conn, sort, options.per_page, offset)?;
2120
let categories = categories
2221
.into_iter()
2322
.map(Category::into)

src/models/krate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ impl Crate {
434434
let rows: Vec<WithCount<ReverseDependency>> =
435435
sql_query(include_str!("krate_reverse_dependencies.sql"))
436436
.bind::<Integer, _>(self.id)
437-
.bind::<BigInt, _>(i64::from(offset))
438-
.bind::<BigInt, _>(i64::from(options.per_page))
437+
.bind::<BigInt, _>(offset)
438+
.bind::<BigInt, _>(options.per_page)
439439
.load(conn)?;
440440

441441
Ok(rows.records_and_total())

src/tests/all.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#[macro_use]
44
extern crate claim;
55
#[macro_use]
6-
extern crate diesel;
7-
#[macro_use]
86
extern crate lazy_static;
97
#[macro_use]
108
extern crate serde;

src/tests/builders/krate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'a> CrateBuilder<'a> {
111111
self
112112
}
113113

114-
pub fn build(mut self, connection: &PgConnection) -> AppResult<Crate> {
114+
pub fn build(mut self, connection: &mut PgConnection) -> AppResult<Crate> {
115115
use diesel::{insert_into, select, update};
116116

117117
let mut krate = self
@@ -147,8 +147,8 @@ impl<'a> CrateBuilder<'a> {
147147
))
148148
.execute(connection)?;
149149

150-
no_arg_sql_function!(refresh_recent_crate_downloads, ());
151-
select(refresh_recent_crate_downloads).execute(connection)?;
150+
sql_function!(fn refresh_recent_crate_downloads());
151+
select(refresh_recent_crate_downloads()).execute(connection)?;
152152
}
153153

154154
if !self.categories.is_empty() {
@@ -175,7 +175,7 @@ impl<'a> CrateBuilder<'a> {
175175
///
176176
/// Panics (and fails the test) if any part of inserting the crate record fails.
177177
#[track_caller]
178-
pub fn expect_build(self, connection: &PgConnection) -> Crate {
178+
pub fn expect_build(self, connection: &mut PgConnection) -> Crate {
179179
let name = self.krate.name;
180180
self.build(connection).unwrap_or_else(|e| {
181181
panic!("Unable to create crate {}: {:?}", name, e);

src/tests/builders/version.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'a> VersionBuilder<'a> {
7777
self,
7878
crate_id: i32,
7979
published_by: i32,
80-
connection: &PgConnection,
80+
connection: &mut PgConnection,
8181
) -> AppResult<Version> {
8282
use diesel::{insert_into, update};
8383

@@ -138,7 +138,7 @@ impl<'a> VersionBuilder<'a> {
138138
self,
139139
crate_id: i32,
140140
published_by: i32,
141-
connection: &PgConnection,
141+
connection: &mut PgConnection,
142142
) -> Version {
143143
self.build(crate_id, published_by, connection)
144144
.unwrap_or_else(|e| {

src/tests/categories.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ description = "Another category ho hum"
4040
fn pg_connection() -> PgConnection {
4141
let database_url =
4242
dotenv::var("TEST_DATABASE_URL").expect("TEST_DATABASE_URL must be set to run tests");
43-
let conn = PgConnection::establish(&database_url).unwrap();
43+
let mut conn = PgConnection::establish(&database_url).unwrap();
4444
conn.begin_test_transaction().unwrap();
4545
conn
4646
}

src/tests/server_binary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const SERVER_BOOT_TIMEOUT_SECONDS: u64 = 30;
1616
#[test]
1717
fn normal_startup() -> Result<(), Error> {
1818
let server_bin = ServerBin::prepare()?;
19-
initialize_dummy_crate(&server_bin.db()?);
19+
initialize_dummy_crate(&mut server_bin.db()?);
2020

2121
let running_server = server_bin.start()?;
2222

@@ -36,7 +36,7 @@ fn normal_startup() -> Result<(), Error> {
3636
#[test]
3737
fn startup_without_database() -> Result<(), Error> {
3838
let server_bin = ServerBin::prepare()?;
39-
initialize_dummy_crate(&server_bin.db()?);
39+
initialize_dummy_crate(&mut server_bin.db()?);
4040

4141
// Break the networking *before* starting the binary, to ensure the binary can fully startup
4242
// without a database connection. Most of crates.io should not work when started without a

src/tests/util/fresh_schema.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use diesel::connection::SimpleConnection;
22
use diesel::prelude::*;
3-
use diesel_migrations::{find_migrations_directory, run_pending_migrations_in_directory};
3+
use diesel_migrations::{FileBasedMigrations, MigrationHarness};
44
use rand::Rng;
55

66
pub(crate) struct FreshSchema {
@@ -13,7 +13,7 @@ impl FreshSchema {
1313
pub(crate) fn new(database_url: &str) -> Self {
1414
let schema_name = generate_schema_name();
1515

16-
let conn = PgConnection::establish(database_url).expect("can't connect to the test db");
16+
let mut conn = PgConnection::establish(database_url).expect("can't connect to the test db");
1717
conn.batch_execute(&format!(
1818
"
1919
DROP SCHEMA IF EXISTS {schema_name} CASCADE;
@@ -23,8 +23,9 @@ impl FreshSchema {
2323
))
2424
.expect("failed to initialize schema");
2525

26-
let migrations_dir = find_migrations_directory().unwrap();
27-
run_pending_migrations_in_directory(conn, &migrations_dir, &mut std::io::sink())
26+
let migrations =
27+
FileBasedMigrations::find_migrations_directory().expect("Could not find migrations");
28+
conn.run_pending_migrations(migrations)
2829
.expect("failed to run migrations on the test schema");
2930

3031
let database_url = url::Url::parse_with_params(

src/tests/util/test_app.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Drop for TestAppInner {
4646

4747
// Manually verify that all jobs have completed successfully
4848
// This will catch any tests that enqueued a job but forgot to initialize the runner
49-
let conn = self.app.primary_database.get().unwrap();
49+
let conn = &mut *self.app.primary_database.get().unwrap();
5050
let job_count: i64 = background_jobs.count().get_result(conn).unwrap();
5151
assert_eq!(
5252
0, job_count,
@@ -92,8 +92,8 @@ impl TestApp {
9292
/// connection before making any API calls. Once the closure returns, the connection is
9393
/// dropped, ensuring it is returned to the pool and available for any future API calls.
9494
pub fn db<T, F: FnOnce(&mut PgConnection) -> T>(&self, f: F) -> T {
95-
let conn = self.0.app.primary_database.get().unwrap();
96-
f(&mut conn)
95+
let conn = &mut self.0.app.primary_database.get().unwrap();
96+
f(conn)
9797
}
9898

9999
/// Create a new user with a verified email address in the database and return a mock user

0 commit comments

Comments
 (0)