-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
9b6a715
commit 44f8fa9
Showing
2 changed files
with
27 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use diesel::{ | ||
migration::{Migration, MigrationSource}, | ||
pg::Pg, | ||
r2d2::{ConnectionManager, ManageConnection}, | ||
PgConnection, | ||
}; | ||
use diesel_migrations::{embed_migrations, EmbeddedMigrations}; | ||
|
||
const MIGRATIONS: EmbeddedMigrations = embed_migrations!("../v-model/migrations"); | ||
|
||
pub fn run_migrations(url: &str) { | ||
let mut conn = db_conn(&url); | ||
|
||
let migrations: Vec<Box<dyn Migration<Pg>>> = MIGRATIONS.migrations().unwrap(); | ||
|
||
for migration in migrations { | ||
migration.run(&mut conn).unwrap(); | ||
} | ||
} | ||
|
||
fn db_conn(url: &str) -> PgConnection { | ||
let conn: ConnectionManager<PgConnection> = ConnectionManager::new(url); | ||
conn.connect().unwrap() | ||
} |
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