Skip to content

Commit

Permalink
feat: migrate DB on app
Browse files Browse the repository at this point in the history
  • Loading branch information
litsynp committed May 23, 2023
1 parent 0bca8e3 commit 6acf5b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/infrastructure/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ pub async fn get_postgres_pool(db_url: &str) -> Result<Pool<Postgres>, sqlx::Err
.connect(db_url)
.await
}

pub async fn migrate(pool: &Pool<Postgres>) {
sqlx::migrate!()
.run(pool)
.await
.expect("Failed to run migrations");
}
2 changes: 2 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub async fn create_server() {
.as_str(),
);

database::migrate(&pool).await;

let router = routes::build_routes(pool);

let addr = SocketAddr::from(([127, 0, 0, 1], 8000));
Expand Down

0 comments on commit 6acf5b1

Please sign in to comment.