-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
46 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::error::Error; | ||
|
||
use diesel::{r2d2, SqliteConnection, sqlite::Sqlite, Connection}; | ||
use diesel_migrations::{EmbeddedMigrations, embed_migrations, MigrationHarness}; | ||
|
||
|
||
pub type DbPool = r2d2::Pool<r2d2::ConnectionManager<SqliteConnection>>; | ||
|
||
pub fn initialize_db_pool() -> DbPool { | ||
let conn_spec = std::env::var("DATABASE_URL").expect("DATABASE_URL should be set"); | ||
let manager = r2d2::ConnectionManager::<SqliteConnection>::new(conn_spec); | ||
r2d2::Pool::builder() | ||
.build(manager) | ||
.expect("database URL should be valid path to SQLite DB file") | ||
} | ||
|
||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("./migrations"); | ||
|
||
pub fn run_migrations(connection: &mut impl MigrationHarness<Sqlite>) -> Result<(), Box<dyn Error + Send + Sync + 'static>> { | ||
connection.run_pending_migrations(MIGRATIONS)?; | ||
Ok(()) | ||
} | ||
|
||
pub fn initial_migration() { | ||
let sqlite_spec = std::env::var("DATABASE_URL").expect("DATABASE_URL should be set"); | ||
let mut connection = SqliteConnection::establish(&sqlite_spec).expect("Failed to establish connection"); | ||
let _ = run_migrations(&mut connection); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pub mod api; | ||
pub mod actions; | ||
pub mod db; | ||
|
||
pub mod models { | ||
pub mod home; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.