Fix migration

This commit is contained in:
eraden 2023-12-31 06:01:38 +01:00
parent 2ea0003158
commit a246b203c6
6 changed files with 43 additions and 15 deletions

View File

@ -4,7 +4,9 @@ fn main() {
let event_bus = events::Bus::new(
"identity-agent",
std::env::var("EVENT_BUS_BIND").ok().as_deref(),
std::env::var("EVENT_BUS_PORT").ok().and_then(|s| s.parse().ok()),
move |topic, event| async {
});
std::env::var("EVENT_BUS_PORT")
.ok()
.and_then(|s| s.parse().ok()),
move |topic, event| async {},
);
}

View File

@ -1,3 +1,2 @@
#[actix::main]
async fn main() {
}
async fn main() {}

View File

@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"
[features]
default = ["with-events", "with-database", "with-web"]
with-web = ["web"]
with-database = ["database"]
with-events = ["events"]

View File

@ -4,6 +4,7 @@ pub use sea_orm_migration;
pub use chrono;
pub use sea_orm::prelude::*;
pub use uuid;
pub use sea_orm::DatabaseConnection;
fn sqlite_file_path() -> String {
let file = std::env::current_dir()
@ -25,15 +26,14 @@ pub trait DatabaseUrl {
fn provided_url(&self) -> Option<&String>;
}
pub async fn run_migration<Migrator: sea_orm_migration::prelude::MigrationTrait + Default>(
pub async fn run_migration<Migrator>(
opts: &impl DatabaseUrl,
) {
let _connection = db_connect(&opts.database_url())
.await
.expect("Failed to connect to database");
// Migrator ::default().up(&connection)
// .await
// .expect("Failed to run migration");
) where Migrator: Default + sea_orm_migration::MigratorTrait {
let connection = db_connect(opts)
.await;
Migrator ::up(&connection, None)
.await
.expect("Failed to run migration");
}
pub async fn db_connect(opts: &impl DatabaseUrl) -> DatabaseConnection {

View File

@ -1,4 +1,31 @@
pub struct Web {}
pub struct Web;
impl Web {
pub fn new<Config>(bind: &'static str, port: u16, configure: Config) -> Self
where
Config: Fn(&mut actix_web::web::ServiceConfig) + Clone + Send + 'static,
{
tokio::spawn(async move {
start_server(bind, port, configure.clone()).await;
});
Self
}
}
async fn start_server<Config>(bind: &'static str, port: u16, configure: Config)
where
Config: Fn(&mut actix_web::web::ServiceConfig) + Clone + Send + 'static,
{
use actix_web::{App, HttpServer};
let config = configure.clone();
HttpServer::new(move || {
let config = config.clone();
App::new().configure(config)
})
.bind((bind, port))
.unwrap_or_else(|e| panic!("Failed to bind server at {bind}:{port} : {e}"))
.run()
.await
.expect("Failed to run web server");
}

View File

@ -131,7 +131,6 @@ impl RunCmd for NewCmd {
}
}
#[derive(Debug, Options)]
pub struct NewOpts {
help: bool,