mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2026-03-03 07:00:51 +01:00
Add DB migrations and run them on startup
Enable sqlx "migrate" feature and add SQL migrations to create the database schema: pg_trgm extension, sources, genres, authors, sequences, books, junction tables, annotations, and supporting indexes
This commit is contained in:
12
src/db.rs
12
src/db.rs
@@ -12,10 +12,18 @@ pub async fn get_postgres_pool() -> PgPool {
|
||||
CONFIG.postgres_db
|
||||
);
|
||||
|
||||
PgPoolOptions::new()
|
||||
let pool = PgPoolOptions::new()
|
||||
.max_connections(10)
|
||||
.acquire_timeout(std::time::Duration::from_secs(300))
|
||||
.connect(&database_url)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
// Run migrations
|
||||
sqlx::migrate!("./migrations")
|
||||
.run(&pool)
|
||||
.await
|
||||
.expect("Failed to run migrations");
|
||||
|
||||
pool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user