diff --git a/.env.example b/.env.example index 30d6624..8688237 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,3 @@ DATABASE_URL="libsql://..." LIBSQL_AUTH_TOKEN="" +RUN_MIGRATIONS="true" diff --git a/Cargo.lock b/Cargo.lock index 39fe995..7a2edc0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2195,7 +2195,6 @@ dependencies = [ "libsql", "minify-html", "minijinja", - "rand", "serde", "time", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 656b28b..dc261b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ axum = { version = "0.7.4", features = ["form", "macros"] } tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] } tower-http = { version = "0.5", features = ["fs","set-header"] } serde = { version = "1.0.197", features = ["derive"] } -rand = "0.8" chrono = "0.4.35" dotenv = "0.15.0" tower = "0.4.13" diff --git a/README.md b/README.md index 7f9b7b3..3136a0b 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,6 @@ npm run tailwind - [x] Improve code for render_html.rs - [x] Setup build via GH actions - [x] Migrate from SQLX/PostgreSQL to Libsql/Turso (sqlx doesn't support turso yet... such a shame) -- [ ] Use minijinja autoreload https://docs.rs/minijinja-autoreload/latest/minijinja_autoreload/ - [ ] Rename to RATH stack, Rust Axum Turso Hhtmx ## Handy commands diff --git a/src/main.rs b/src/main.rs index c275e85..8730766 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,6 +37,7 @@ async fn main() { // Connect to DB let db_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set"); let db_token = env::var("LIBSQL_AUTH_TOKEN").expect("TOKEN must be set"); + let db_run_migrations = env::var("RUN_MIGRATIONS").unwrap_or("true".to_string()); // Setup database let db = Builder::new_remote_replica("local.db", db_url, db_token) @@ -45,22 +46,26 @@ async fn main() { .await .expect("Could not connect to database"); let conn = db.connect().unwrap(); - db.sync().await.unwrap(); + // db.sync().await.unwrap(); // Loop over all files in dir migrations and run them - let migrations = std::fs::read_dir("migrations").unwrap(); - for migration in migrations { - let path = migration.unwrap().path(); - if path.is_file() { - let content = std::fs::read_to_string(path.clone()).unwrap(); - conn.execute(&content, ()).await.unwrap(); - println!("Ran migration: {}", path.display()); + if db_run_migrations == "true" { + let migrations = std::fs::read_dir("migrations").unwrap(); + for migration in migrations { + let path = migration.unwrap().path(); + if path.is_file() { + let content = std::fs::read_to_string(path.clone()).unwrap(); + conn.execute(&content, ()).await.unwrap(); + println!("Ran migration: {}", path.display()); + } } } // Setup session store let session_store = LibsqlStore::new(conn.clone()); - session_store.migrate().await.expect("Could not migrate session store"); + if db_run_migrations == "true" { + session_store.migrate().await.expect("Could not migrate session store"); + } let _deletion_task = tokio::task::spawn( session_store .clone()