Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run DB migrations on start #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 2 additions & 7 deletions src/bin/server/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ use crate::attestations::{
get_aggregate_price_interval_attestations, get_price_aggregate,
get_price_interval_attestations, get_price_value_attestations, post_oracle_message,
};
use crate::db::{get_db_pool, DbPool};
use crate::db::DbPool;
use crate::state::AppState;
use axum::{
routing::{get, post},
Router,
};
use std::sync::Arc;

pub async fn get_router() -> Router {
let db_pool = get_db_pool().await;
get_router_with_db_pool(db_pool)
}

fn get_router_with_db_pool(db_pool: DbPool) -> Router {
pub fn get_router_with_db_pool(db_pool: DbPool) -> Router {
let shared_state = Arc::new(AppState { db_pool });
Router::new()
.route(
Expand Down
5 changes: 4 additions & 1 deletion src/bin/server/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::net::SocketAddr;

mod app;
mod attestations;
mod db;
Expand All @@ -8,7 +9,9 @@ mod state;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let app = app::get_router().await;
let db_pool = db::get_db_pool().await;
sqlx::migrate!().run(&db_pool).await.unwrap();
let app = app::get_router_with_db_pool(db_pool);
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
tracing::info!("Listening on {}", addr);
axum::Server::bind(&addr)
Expand Down