Skip to content

Commit 399c8bb

Browse files
committed
accept the database config instead of the server config
1 parent 6ae40c3 commit 399c8bb

File tree

14 files changed

+47
-29
lines changed

14 files changed

+47
-29
lines changed

src/admin/delete_crate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct Opts {
1414
}
1515

1616
pub fn run(opts: Opts) {
17-
let conn = db::connect_now(&Default::default()).unwrap();
17+
let conn = db::oneoff_connection().unwrap();
1818
conn.transaction::<_, diesel::result::Error, _>(|| {
1919
delete(opts, &conn);
2020
Ok(())

src/admin/delete_version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct Opts {
2121
}
2222

2323
pub fn run(opts: Opts) {
24-
let conn = db::connect_now(&Default::default()).unwrap();
24+
let conn = db::oneoff_connection().unwrap();
2525
conn.transaction::<_, diesel::result::Error, _>(|| {
2626
delete(opts, &conn);
2727
Ok(())

src/admin/migrate.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ diesel_migrations::embed_migrations!("./migrations");
1111
pub struct Opts;
1212

1313
pub fn run(_opts: Opts) -> Result<(), Error> {
14-
let config = crate::config::Server::default();
14+
let config = crate::config::DatabasePools::full_from_environment(
15+
&crate::config::Base::from_environment(),
16+
);
1517

1618
// TODO: Refactor logic so that we can also check things from App::new() here.
1719
// If the app will panic due to bad configuration, it is better to error in the release phase
1820
// to avoid launching dynos that will fail.
1921

20-
if config.db.are_all_read_only() {
22+
if config.are_all_read_only() {
2123
// TODO: Check `any_pending_migrations()` with a read-only connection and error if true.
2224
// It looks like this requires changes upstream to make this pub in `migration_macros`.
2325

@@ -30,7 +32,7 @@ pub fn run(_opts: Opts) -> Result<(), Error> {
3032
}
3133

3234
// The primary is online, access directly via `DATABASE_URL`.
33-
let conn = crate::db::connect_now(&config)?;
35+
let conn = crate::db::oneoff_connection_with_config(&config)?;
3436

3537
println!("==> migrating the database");
3638
embedded_migrations::run_with_output(&conn, &mut std::io::stdout())?;

src/admin/populate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct Opts {
1414
}
1515

1616
pub fn run(opts: Opts) {
17-
let conn = db::connect_now(&Default::default()).unwrap();
17+
let conn = db::oneoff_connection().unwrap();
1818
conn.transaction(|| update(opts, &conn)).unwrap();
1919
}
2020

src/admin/render_readmes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct Opts {
4040

4141
pub fn run(opts: Opts) -> anyhow::Result<()> {
4242
let base_config = Arc::new(config::Base::from_environment());
43-
let conn = db::connect_now(&Default::default()).unwrap();
43+
let conn = db::oneoff_connection().unwrap();
4444

4545
let start_time = Utc::now();
4646

src/admin/transfer_crates.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct Opts {
2121
}
2222

2323
pub fn run(opts: Opts) {
24-
let conn = db::connect_now(&Default::default()).unwrap();
24+
let conn = db::oneoff_connection().unwrap();
2525
conn.transaction::<_, diesel::result::Error, _>(|| {
2626
transfer(opts, &conn);
2727
Ok(())

src/admin/verify_token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct Opts {
1313
}
1414

1515
pub fn run(opts: Opts) -> AppResult<()> {
16-
let conn = db::connect_now(&Default::default())?;
16+
let conn = db::oneoff_connection()?;
1717
let user = User::find_by_api_token(&conn, &opts.api_token)?;
1818
println!("The token belongs to user {}", user.gh_login);
1919
Ok(())

src/app.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl App {
100100
let thread_pool = Arc::new(ScheduledThreadPool::new(db_helper_threads));
101101

102102
let primary_database = if config.use_test_database_pool {
103-
DieselPool::new_test(&config, &config.db.primary.url)
103+
DieselPool::new_test(&config.db, &config.db.primary.url)
104104
} else {
105105
let primary_db_connection_config = ConnectionConfig {
106106
statement_timeout: db_connection_timeout,
@@ -116,7 +116,7 @@ impl App {
116116

117117
DieselPool::new(
118118
&config.db.primary.url,
119-
&config,
119+
&config.db,
120120
primary_db_config,
121121
instance_metrics
122122
.database_time_to_obtain_connection
@@ -127,7 +127,7 @@ impl App {
127127

128128
let replica_database = if let Some(pool_config) = config.db.replica.as_ref() {
129129
if config.use_test_database_pool {
130-
Some(DieselPool::new_test(&config, &pool_config.url))
130+
Some(DieselPool::new_test(&config.db, &pool_config.url))
131131
} else {
132132
let replica_db_connection_config = ConnectionConfig {
133133
statement_timeout: db_connection_timeout,
@@ -144,7 +144,7 @@ impl App {
144144
Some(
145145
DieselPool::new(
146146
&pool_config.url,
147-
&config,
147+
&config.db,
148148
replica_db_config,
149149
instance_metrics
150150
.database_time_to_obtain_connection

src/bin/background-worker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn main() {
3737
}
3838
}
3939

40-
let db_url = db::connection_url(&config, &config.db.primary.url);
40+
let db_url = db::connection_url(&config.db, &config.db.primary.url);
4141

4242
let job_start_timeout = dotenv::var("BACKGROUND_JOB_TIMEOUT")
4343
.unwrap_or_else(|_| "30".into())

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::connect_now(&Default::default())?;
10+
let conn = db::oneoff_connection()?;
1111
let mut args = std::env::args().skip(1);
1212

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

0 commit comments

Comments
 (0)