Skip to content

Commit

Permalink
SQL_URL -> DATABASE_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
hotate29 committed Nov 15, 2022
1 parent 6826963 commit c5ca4f5
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion atcoder-problems-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ docker-compose exec backend-development cargo build
## Run

```bash
export SQL_URL=... # Connection URL of PostgreSQL
export DATABASE_URL=... # Connection URL of PostgreSQL
export CLIENT_ID=... # GitHub client_id, which is required to use the login function.
export CLIENT_SECRET=... # GitHub client_secret, which is required to use the login function.

Expand Down
2 changes: 1 addition & 1 deletion atcoder-problems-backend/scripts/sql-backup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

psql ${SQL_URL} -c "\copy submissions TO './submissions.csv' WITH (FORMAT CSV, HEADER)"
psql ${DATABASE_URL} -c "\copy submissions TO './submissions.csv' WITH (FORMAT CSV, HEADER)"
gzip submissions.csv
aws s3 cp submissions.csv.gz s3://kenkoooo/submissions.csv.gz --acl public-read
2 changes: 1 addition & 1 deletion atcoder-problems-backend/src/bin/batch_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
info!("Started!");

info!("Connecting to SQL ...");
let url = env::var("SQL_URL")?;
let url = env::var("DATABASE_URL")?;
let conn = initialize_pool(&url).await?;

info!("Loading submissions ...");
Expand Down
2 changes: 1 addition & 1 deletion atcoder-problems-backend/src/bin/crawl_all_submissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{env, time::Duration};
async fn main() {
init_log_config().unwrap();
info!("Started");
let url = env::var("SQL_URL").expect("SQL_URL is not set.");
let url = env::var("DATABASE_URL").expect("DATABASE_URL is not set.");

loop {
info!("Start new loop");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async fn crawl<R: Rng>(url: &str, rng: &mut R) -> Result<()> {
#[actix_web::main]
async fn main() {
init_log_config().unwrap();
let url = env::var("SQL_URL").expect("SQL_URL must be set.");
let url = env::var("DATABASE_URL").expect("DATABASE_URL must be set.");
log::info!("Started");

let mut rng = thread_rng();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async fn iteration(url: &str) -> Result<()> {
async fn main() {
init_log_config().unwrap();
info!("Started");
let url = env::var("SQL_URL").expect("SQL_URL is not set.");
let url = env::var("DATABASE_URL").expect("DATABASE_URL is not set.");

loop {
info!("Start new loop");
Expand Down
2 changes: 1 addition & 1 deletion atcoder-problems-backend/src/bin/crawl_problems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::env;
async fn main() {
init_log_config().unwrap();
log::info!("Started");
let url = env::var("SQL_URL").expect("SQL_URL is not set.");
let url = env::var("DATABASE_URL").expect("DATABASE_URL is not set.");

let db = initialize_pool(&url).await.unwrap();
let crawler = ProblemCrawler::new(db, AtCoderClient::default());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async fn crawl(url: &str) -> Result<()> {
async fn main() {
init_log_config().unwrap();
log::info!("Started");
let url = env::var("SQL_URL").expect("SQL_URL must be set.");
let url = env::var("DATABASE_URL").expect("DATABASE_URL must be set.");

loop {
log::info!("Start new loop");
Expand Down
2 changes: 1 addition & 1 deletion atcoder-problems-backend/src/bin/crawl_whole_contest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::env;
async fn main() -> Result<()> {
init_log_config()?;
info!("Started");
let url = env::var("SQL_URL").expect("SQL_URL should be set as environmental variable.");
let url = env::var("DATABASE_URL").expect("DATABASE_URL should be set as environmental variable.");
let contest_id = env::args()
.nth(1)
.expect("contest_id is not set.\nUsage: cargo run --bin crawl_whole_contest <contest_id>");
Expand Down
2 changes: 1 addition & 1 deletion atcoder-problems-backend/src/bin/delta_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
info!("Started!");

info!("Connecting to SQL ...");
let url = env::var("SQL_URL")?;
let url = env::var("DATABASE_URL")?;
let conn = initialize_pool(&url).await?;

info!("Loading submissions ...");
Expand Down
2 changes: 1 addition & 1 deletion atcoder-problems-backend/src/bin/dump_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const LANGUAGE_COUNT_LIMIT: usize = 1000;
async fn main() -> Result<()> {
init_log_config()?;
log::info!("Started!");
let url = env::var("SQL_URL")?;
let url = env::var("DATABASE_URL")?;
let pg_pool = initialize_pool(&url).await?;

let client = s3::S3Client::new()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const ONE_DAY: i64 = 24 * 3600;
async fn main() {
init_log_config().unwrap();
info!("Started");
let url = env::var("SQL_URL").expect("SQL_URL must be set.");
let url = env::var("DATABASE_URL").expect("DATABASE_URL must be set.");
let db = initialize_pool(&url).await.unwrap();
let now = Utc::now().timestamp();
let crawler = FixCrawler::new(db, AtCoderClient::default(), now - ONE_DAY);
Expand Down
2 changes: 1 addition & 1 deletion atcoder-problems-backend/src/bin/run_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use atcoder_problems_backend::utils::init_log_config;
#[actix_web::main]
async fn main() {
init_log_config().unwrap();
let database_url = env::var("SQL_URL").expect("SQL_URL is not set.");
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set.");
let port = 8080;

let client_id = env::var("CLIENT_ID").unwrap_or_else(|_| String::new());
Expand Down
8 changes: 4 additions & 4 deletions atcoder-problems-backend/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use sql_client::{initialize_pool, PgPool};
use std::fs::read_to_string;

const SQL_FILE: &str = "../config/database-definition.sql";
const SQL_URL_ENV_KEY: &str = "SQL_URL";
const DATABASE_URL_ENV_KEY: &str = "DATABASE_URL";

pub fn get_sql_url_from_env() -> String {
std::env::var(SQL_URL_ENV_KEY).unwrap()
pub fn get_database_url_from_env() -> String {
std::env::var(DATABASE_URL_ENV_KEY).unwrap()
}

pub async fn initialize_and_connect_to_test_sql() -> PgPool {
let conn = initialize_pool(get_sql_url_from_env()).await.unwrap();
let conn = initialize_pool(get_database_url_from_env()).await.unwrap();
initialize(&conn).await;
conn
}
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ services:
backend-development:
image: rust:1.63.0
environment:
SQL_URL: postgres://db_user:db_pass@postgresql:5432/test_db
DATABASE_URL: postgres://db_user:db_pass@postgresql:5432/test_db
RUST_LOG: info
ports:
Expand Down

0 comments on commit c5ca4f5

Please sign in to comment.