:neocat_woozy: It works nyow

This commit is contained in:
Bananentürkis 2023-12-31 19:01:38 +01:00
parent fd06408962
commit 180a4a7771

View file

@ -15,21 +15,12 @@ use std::error::Error;
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations"); pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");
pub fn establish_connection(db_url: &str) -> PgConnection { pub fn establish_connection(db_url: &str) -> Result<PgConnection, Error> {
//SqliteConnection::establish(db_url).unwrap_or_else(|e| panic!("Error connecting to {}: {}", db_url, e)) //SqliteConnection::establish(db_url).unwrap_or_else(|e| panic!("Error connecting to {}: {}", db_url, e))
let mut conn = PgConnection::establish(db_url) let mut conn = PgConnection::establish(db_url)
.unwrap_or_else(|e| panic!("Error connecting to {}: {}", db_url, e)); .unwrap_or_else(|e| panic!("Error connecting to {}: {}", db_url, e));
// TODO: Add migrations here // TODO: Add migrations here
conn let c: MigrationHarness<PgConnection> = &mut conn;
} c.run_pending_migrations(MIGRATIONS)?;
Ok(conn)
fn run_migrations_sqlite(connection: &mut impl MigrationHarness<Sqlite>) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
// This will run the necessary migrations.
//
// See the documentation for `MigrationHarness` for
// all available methods.
connection.run_pending_migrations(MIGRATIONS)?;
Ok(())
} }