librmo 0.4.4

A library to manage media files and play them
Documentation
use super::m20220101_000001_create_table;
pub use sea_orm_migration::{MigratorTrait, MigrationTrait, prelude::*};
use std::{fs::File, path::Path};
use crate::app::settings::{get_db_connection, get_db_url};
use crate::error::CustomError;
use crate::app::settings::init;

pub struct Migrator;

#[async_trait::async_trait]
impl MigratorTrait for Migrator {
    fn migrations() -> Vec<Box<dyn MigrationTrait>> {
        vec![Box::new(m20220101_000001_create_table::Migration)]
    }
}

#[allow(dead_code)]
pub async fn run() -> Result<(), CustomError> {
    init()?;

    let database_path = get_db_url()
        .unwrap()
        .replace("sqlite:", "");

    if !Path::new(&database_path).exists() {
        File::create(database_path).expect("Failed to create database file");
    }

    let db = get_db_connection().await?;

    Ok(Migrator::up(&db, None).await?)
}