From e284833b53b757407bcca65f840389cf760d3ce8 Mon Sep 17 00:00:00 2001 From: "Dotan J. Nahum" Date: Sat, 23 Nov 2024 00:41:47 +0200 Subject: [PATCH 1/2] fix: db naming --- loco-new/base_template/config/development.yaml.t | 2 +- loco-new/base_template/config/test.yaml.t | 2 +- loco-new/devnew.sh | 2 +- loco-new/src/wizard.rs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/loco-new/base_template/config/development.yaml.t b/loco-new/base_template/config/development.yaml.t index 44ba73f03..cd1bf250d 100644 --- a/loco-new/base_template/config/development.yaml.t +++ b/loco-new/base_template/config/development.yaml.t @@ -97,7 +97,7 @@ mailer: # Database Configuration database: # Database connection URI - uri: {% raw %}{{{% endraw %} get_env(name="DATABASE_URL", default="{{settings.db.endpoint}}") {% raw %}}}{% endraw %} + uri: {% raw %}{{{% endraw %} get_env(name="DATABASE_URL", default="{{settings.db.endpoint | replace(from='NAME', to=settings.package_name) | replace(from='ENV', to='development')}}") {% raw %}}}{% endraw %} # When enabled, the sql query will be logged. enable_logging: false # Set the timeout duration when acquiring a connection. diff --git a/loco-new/base_template/config/test.yaml.t b/loco-new/base_template/config/test.yaml.t index dcc902fc7..b1d1ed535 100644 --- a/loco-new/base_template/config/test.yaml.t +++ b/loco-new/base_template/config/test.yaml.t @@ -97,7 +97,7 @@ mailer: # Database Configuration database: # Database connection URI - uri: {% raw %}{{{% endraw %} get_env(name="DATABASE_URL", default="{{settings.db.endpoint}}") {% raw %}}}{% endraw %} + uri: {% raw %}{{{% endraw %} get_env(name="DATABASE_URL", default="{{settings.db.endpoint | replace(from='NAME', to=settings.package_name) | replace(from='ENV', to='test')}}") {% raw %}}}{% endraw %} # When enabled, the sql query will be logged. enable_logging: false # Set the timeout duration when acquiring a connection. diff --git a/loco-new/devnew.sh b/loco-new/devnew.sh index 6a331a3ac..a2fb298da 100755 --- a/loco-new/devnew.sh +++ b/loco-new/devnew.sh @@ -1 +1 @@ -LOCO_DEV_MODE_PATH=../../ loco new +LOCO_DEV_MODE_PATH=../../ cargo run -- new diff --git a/loco-new/src/wizard.rs b/loco-new/src/wizard.rs index d25938497..61971e100 100644 --- a/loco-new/src/wizard.rs +++ b/loco-new/src/wizard.rs @@ -71,8 +71,8 @@ impl DBOption { #[must_use] pub const fn endpoint_config(&self) -> &str { match self { - Self::Sqlite => "sqlite://loco_app.sqlite?mode=rwc", - Self::Postgres => "postgres://loco:loco@localhost:5432/loco_app", + Self::Sqlite => "sqlite://NAME_ENV.sqlite?mode=rwc", + Self::Postgres => "postgres://loco:loco@localhost:5432/NAME_ENV", Self::None => "", } } From 2d94ff2d5b8d773e4e72830008d4f53cfd185f54 Mon Sep 17 00:00:00 2001 From: "Dotan J. Nahum" Date: Sat, 23 Nov 2024 01:21:03 +0200 Subject: [PATCH 2/2] test: snapshots --- .../r#mod__templates__auth__src_app_rs_auth_false.snap | 4 +++- .../r#mod__templates__auth__src_app_rs_auth_true.snap | 4 +++- .../r#mod__templates__background__src_app_rs_Async.snap | 4 +++- .../r#mod__templates__background__src_app_rs_Blocking.snap | 4 +++- .../r#mod__templates__background__src_app_rs_None.snap | 4 +++- .../r#mod__templates__background__src_app_rs_Queue.snap | 4 +++- ...__config_development_yaml_config_database_Postgres.snap | 7 ++++--- ...db__config_development_yaml_config_database_Sqlite.snap | 7 ++++--- ...tes__db__config_test_yaml_config_database_Postgres.snap | 7 ++++--- ...lates__db__config_test_yaml_config_database_Sqlite.snap | 7 ++++--- .../snapshots/r#mod__templates__db__src_app_rs_None.snap | 4 +++- .../r#mod__templates__db__src_app_rs_Postgres.snap | 4 +++- .../snapshots/r#mod__templates__db__src_app_rs_Sqlite.snap | 4 +++- ...plates__initializers__src_app_rs_with_initializers.snap | 4 +++- ...tes__initializers__src_app_rs_without_initializers.snap | 4 +++- 15 files changed, 49 insertions(+), 23 deletions(-) diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_false.snap b/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_false.snap index e2bd75359..b494ba3f4 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_false.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_false.snap @@ -1,6 +1,7 @@ --- -source: loco-new/tests/templates/auth.rs +source: tests/templates/auth.rs expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")" +snapshot_kind: text --- use async_trait::async_trait; use loco_rs::{ @@ -51,5 +52,6 @@ impl Hooks for App { Ok(()) } fn register_tasks(_tasks: &mut Tasks) { + // tasks-inject (do not remove) } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_true.snap b/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_true.snap index 04fb5b701..dd01ffebc 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_true.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_true.snap @@ -1,6 +1,7 @@ --- -source: loco-new/tests/templates/auth.rs +source: tests/templates/auth.rs expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")" +snapshot_kind: text --- use async_trait::async_trait; use loco_rs::{ @@ -51,5 +52,6 @@ impl Hooks for App { Ok(()) } fn register_tasks(_tasks: &mut Tasks) { + // tasks-inject (do not remove) } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_Async.snap b/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_Async.snap index c25b37010..9214507af 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_Async.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_Async.snap @@ -1,6 +1,7 @@ --- -source: loco-new/tests/templates/background.rs +source: tests/templates/background.rs expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")" +snapshot_kind: text --- use async_trait::async_trait; use loco_rs::{ @@ -54,5 +55,6 @@ impl Hooks for App { Ok(()) } fn register_tasks(_tasks: &mut Tasks) { + // tasks-inject (do not remove) } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_Blocking.snap b/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_Blocking.snap index c25b37010..9214507af 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_Blocking.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_Blocking.snap @@ -1,6 +1,7 @@ --- -source: loco-new/tests/templates/background.rs +source: tests/templates/background.rs expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")" +snapshot_kind: text --- use async_trait::async_trait; use loco_rs::{ @@ -54,5 +55,6 @@ impl Hooks for App { Ok(()) } fn register_tasks(_tasks: &mut Tasks) { + // tasks-inject (do not remove) } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_None.snap b/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_None.snap index 0cc81dc7f..f9f09ab44 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_None.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_None.snap @@ -1,6 +1,7 @@ --- -source: loco-new/tests/templates/background.rs +source: tests/templates/background.rs expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")" +snapshot_kind: text --- use async_trait::async_trait; use loco_rs::{ @@ -51,5 +52,6 @@ impl Hooks for App { Ok(()) } fn register_tasks(_tasks: &mut Tasks) { + // tasks-inject (do not remove) } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_Queue.snap b/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_Queue.snap index c25b37010..9214507af 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_Queue.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__background__src_app_rs_Queue.snap @@ -1,6 +1,7 @@ --- -source: loco-new/tests/templates/background.rs +source: tests/templates/background.rs expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")" +snapshot_kind: text --- use async_trait::async_trait; use loco_rs::{ @@ -54,5 +55,6 @@ impl Hooks for App { Ok(()) } fn register_tasks(_tasks: &mut Tasks) { + // tasks-inject (do not remove) } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__db__config_development_yaml_config_database_Postgres.snap b/loco-new/tests/templates/snapshots/r#mod__templates__db__config_development_yaml_config_database_Postgres.snap index 19250776b..6059fdd70 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__db__config_development_yaml_config_database_Postgres.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__db__config_development_yaml_config_database_Postgres.snap @@ -1,12 +1,13 @@ --- -source: loco-new/tests/templates/db.rs -expression: "format!(\"{:#?}\",\n assertion::yaml::get_value_at_path(&content, &[\"database\"]).unwrap())" +source: tests/templates/db.rs +expression: "format!(\"{:#?}\",\nassertion::yaml::get_value_at_path(&content, &[\"database\"]).unwrap())" +snapshot_kind: text --- Mapping { "uri": Mapping { Mapping { "get_env(name=\"DATABASE_URL\"": Null, - "default=\"postgres://loco:loco@localhost:5432/loco_app\")": Null, + "default=\"postgres://loco:loco@localhost:5432/loco-app-test_development\")": Null, }: Null, }, "enable_logging": Bool(false), diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__db__config_development_yaml_config_database_Sqlite.snap b/loco-new/tests/templates/snapshots/r#mod__templates__db__config_development_yaml_config_database_Sqlite.snap index 96f4bc240..661165bf7 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__db__config_development_yaml_config_database_Sqlite.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__db__config_development_yaml_config_database_Sqlite.snap @@ -1,12 +1,13 @@ --- -source: loco-new/tests/templates/db.rs -expression: "format!(\"{:#?}\",\n assertion::yaml::get_value_at_path(&content, &[\"database\"]).unwrap())" +source: tests/templates/db.rs +expression: "format!(\"{:#?}\",\nassertion::yaml::get_value_at_path(&content, &[\"database\"]).unwrap())" +snapshot_kind: text --- Mapping { "uri": Mapping { Mapping { "get_env(name=\"DATABASE_URL\"": Null, - "default=\"sqlite://loco_app.sqlite?mode=rwc\")": Null, + "default=\"sqlite://loco-app-test_development.sqlite?mode=rwc\")": Null, }: Null, }, "enable_logging": Bool(false), diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__db__config_test_yaml_config_database_Postgres.snap b/loco-new/tests/templates/snapshots/r#mod__templates__db__config_test_yaml_config_database_Postgres.snap index 757ac0205..fc133c568 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__db__config_test_yaml_config_database_Postgres.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__db__config_test_yaml_config_database_Postgres.snap @@ -1,12 +1,13 @@ --- -source: loco-new/tests/templates/db.rs -expression: "format!(\"{:#?}\",\n assertion::yaml::get_value_at_path(&content, &[\"database\"]).unwrap())" +source: tests/templates/db.rs +expression: "format!(\"{:#?}\",\nassertion::yaml::get_value_at_path(&content, &[\"database\"]).unwrap())" +snapshot_kind: text --- Mapping { "uri": Mapping { Mapping { "get_env(name=\"DATABASE_URL\"": Null, - "default=\"postgres://loco:loco@localhost:5432/loco_app\")": Null, + "default=\"postgres://loco:loco@localhost:5432/loco-app-test_test\")": Null, }: Null, }, "enable_logging": Bool(false), diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__db__config_test_yaml_config_database_Sqlite.snap b/loco-new/tests/templates/snapshots/r#mod__templates__db__config_test_yaml_config_database_Sqlite.snap index 117d7e173..b45b01b9f 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__db__config_test_yaml_config_database_Sqlite.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__db__config_test_yaml_config_database_Sqlite.snap @@ -1,12 +1,13 @@ --- -source: loco-new/tests/templates/db.rs -expression: "format!(\"{:#?}\",\n assertion::yaml::get_value_at_path(&content, &[\"database\"]).unwrap())" +source: tests/templates/db.rs +expression: "format!(\"{:#?}\",\nassertion::yaml::get_value_at_path(&content, &[\"database\"]).unwrap())" +snapshot_kind: text --- Mapping { "uri": Mapping { Mapping { "get_env(name=\"DATABASE_URL\"": Null, - "default=\"sqlite://loco_app.sqlite?mode=rwc\")": Null, + "default=\"sqlite://loco-app-test_test.sqlite?mode=rwc\")": Null, }: Null, }, "enable_logging": Bool(false), diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_None.snap b/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_None.snap index 8a600e650..38583c7e8 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_None.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_None.snap @@ -1,6 +1,7 @@ --- -source: loco-new/tests/templates/db.rs +source: tests/templates/db.rs expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")" +snapshot_kind: text --- use async_trait::async_trait; use loco_rs::{ @@ -51,5 +52,6 @@ impl Hooks for App { Ok(()) } fn register_tasks(_tasks: &mut Tasks) { + // tasks-inject (do not remove) } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Postgres.snap b/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Postgres.snap index b28d56da5..d886efa19 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Postgres.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Postgres.snap @@ -1,6 +1,7 @@ --- -source: loco-new/tests/templates/db.rs +source: tests/templates/db.rs expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")" +snapshot_kind: text --- use std::path::Path; use async_trait::async_trait; @@ -59,6 +60,7 @@ impl Hooks for App { } fn register_tasks(tasks: &mut Tasks) { tasks.register(tasks::seed::SeedData); + // tasks-inject (do not remove) } async fn truncate(db: &DatabaseConnection) -> Result<()> { truncate_table(db, users::Entity).await?; diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Sqlite.snap b/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Sqlite.snap index b28d56da5..d886efa19 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Sqlite.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Sqlite.snap @@ -1,6 +1,7 @@ --- -source: loco-new/tests/templates/db.rs +source: tests/templates/db.rs expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")" +snapshot_kind: text --- use std::path::Path; use async_trait::async_trait; @@ -59,6 +60,7 @@ impl Hooks for App { } fn register_tasks(tasks: &mut Tasks) { tasks.register(tasks::seed::SeedData); + // tasks-inject (do not remove) } async fn truncate(db: &DatabaseConnection) -> Result<()> { truncate_table(db, users::Entity).await?; diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__initializers__src_app_rs_with_initializers.snap b/loco-new/tests/templates/snapshots/r#mod__templates__initializers__src_app_rs_with_initializers.snap index 0c24a44cd..d6238c8b3 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__initializers__src_app_rs_with_initializers.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__initializers__src_app_rs_with_initializers.snap @@ -1,6 +1,7 @@ --- -source: loco-new/tests/templates/initializers.rs +source: tests/templates/initializers.rs expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")" +snapshot_kind: text --- use async_trait::async_trait; use loco_rs::{ @@ -51,5 +52,6 @@ impl Hooks for App { Ok(()) } fn register_tasks(_tasks: &mut Tasks) { + // tasks-inject (do not remove) } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__initializers__src_app_rs_without_initializers.snap b/loco-new/tests/templates/snapshots/r#mod__templates__initializers__src_app_rs_without_initializers.snap index e97f3c0a1..dc206c63f 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__initializers__src_app_rs_without_initializers.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__initializers__src_app_rs_without_initializers.snap @@ -1,6 +1,7 @@ --- -source: loco-new/tests/templates/initializers.rs +source: tests/templates/initializers.rs expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")" +snapshot_kind: text --- use async_trait::async_trait; use loco_rs::{ @@ -51,5 +52,6 @@ impl Hooks for App { Ok(()) } fn register_tasks(_tasks: &mut Tasks) { + // tasks-inject (do not remove) } }