Skip to content

Commit

Permalink
fix: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
NewbMiao committed Jun 8, 2023
1 parent 42ac807 commit 870d0a6
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ jobs:
uses: taiki-e/install-action@cargo-llvm-cov
- name: install nextest
uses: taiki-e/install-action@nextest
- name: Install sqlx-cli
run: cargo install sqlx-cli --no-default-features --features native-tls,postgres
- uses: Swatinem/rust-cache@v1
- name: Check code format
run: cargo fmt -- --check
- name: Start DB service
run: docker-compose up -d && sqlx migrate run
- name: Check the package for errors
run: cargo check --all
- name: Lint rust sources
Expand Down
9 changes: 9 additions & 0 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub mod profile;
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};

pub async fn get_db_pool(database_url: String) -> Result<Pool<Postgres>, sqlx::Error> {
PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
.await
}
1 change: 0 additions & 1 deletion src/tables/profile.rs → src/database/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub struct Profile {
created_date: DateTime<Utc>,
updated_date: Option<DateTime<Utc>>,
}

impl Profile {
pub fn new(account_id: String, username: String, email: String, refresh_token: String) -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::Deserialize;
use serde_json::json;
use sqlx::{Pool, Postgres};

use crate::{extensions::google_auth::GoogleAuth, tables::profile::Profile};
use crate::{database::profile::Profile, extensions::google_auth::GoogleAuth};

pub async fn auth_handler(Extension(google_auth): Extension<Arc<GoogleAuth>>) -> impl IntoResponse {
let auth_url = google_auth.auth_url().await;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod database;
pub mod extensions;
pub mod handlers;
pub mod middlewares;
pub mod tables;
8 changes: 2 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use axum::{middleware, routing::get, Extension, Router};
use axum_koans::{
database::get_db_pool,
extensions::{google_auth::GoogleAuth, keycloak_auth::KeycloakAuth},
handlers::{
auth::{auth_callback_handler, auth_handler},
Expand All @@ -8,7 +9,6 @@ use axum_koans::{
middlewares::log,
};
use dotenvy::{self, dotenv};
use sqlx::postgres::PgPoolOptions;
use std::{env, net::SocketAddr, sync::Arc};
use tower::ServiceBuilder;
use tower_http::trace::{self, TraceLayer};
Expand Down Expand Up @@ -36,11 +36,7 @@ async fn main() {
env::var("DATABASE_URL").expect("Missing the DATABASE_URL environment variable.");

// db pool
let db_pool = PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
.await
.unwrap();
let db_pool = get_db_pool(database_url).await.unwrap();
// Start configuring a `fmt` subscriber
let subscriber = tracing_subscriber::fmt()
.compact()
Expand Down
1 change: 0 additions & 1 deletion src/tables/mod.rs

This file was deleted.

0 comments on commit 870d0a6

Please sign in to comment.