Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/run_sql_updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ jobs:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
MYSQL_USER: root
MYSQL_PWD: password
MYSQL_TCP_PORT: 13306
MYSQL_DATABASE: f1db

outputs:
Expand All @@ -55,7 +57,7 @@ jobs:
MYSQL_DATABASE: ${{ env.MYSQL_DATABASE }}
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_PWD }}
ports:
- 13306:3306
- ${{ env.MYSQL_TCP_PORT }}:3306
options: --health-cmd="mysqladmin ping -u root" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
Expand All @@ -66,7 +68,7 @@ jobs:
mkdir f1-sql-updater

- name: Verify f1db exists
run: mysql --host 127.0.0.1 --port 13306 -uroot -e "SHOW DATABASES LIKE '${{ env.MYSQL_DATABASE }}'"
run: mysql --host 127.0.0.1 -uroot -e "SHOW DATABASES LIKE '${{ env.MYSQL_DATABASE }}'"

- name: Retrieve latest binary
run: gh release download -R race-tech/f1-sql-updater --pattern 'f1-sql-updater'
Expand All @@ -87,7 +89,7 @@ jobs:

- name: Create sql dump
run: |
mysqldump --host 127.0.0.1 --port 13306 -uroot ${{ env.MYSQL_DATABASE }}> f1db.sql
mysqldump --host 127.0.0.1 -uroot ${{ env.MYSQL_DATABASE }}> f1db.sql
gzip f1db.sql

- name: Upload sql dump
Expand Down
16 changes: 14 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,20 @@ fn main() -> anyhow::Result<()> {
let is_sprint = env::args().nth(2).unwrap().parse::<bool>()?;
let year = chrono::Utc::now().year();

let url = "mysql://user:password@localhost:13306/f1db";
let mut conn = mysql::Conn::new(url)?;
let user = env::var("MYSQL_USER").unwrap_or("user".into());
let password = env::var("MYSQL_PWD").unwrap_or("password".into());
let port = env::var("MYSQL_TCP_PORT")
.map(|port| port.parse().unwrap_or(3306))
.unwrap_or(3306);
let db_name = env::var("MYSQL_DATABASE").unwrap_or("f1db".into());
let mut conn = mysql::Conn::new(
mysql::OptsBuilder::new()
.ip_or_hostname("localhost".into())
.tcp_port(port)
.user(Some(user))
.pass(Some(password))
.db_name(Some(db_name)),
)?;

let race_id = *conn
.query_map(
Expand Down