Skip to content

Commit

Permalink
Merge branch 'master' into xp-embed-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
kaplanelad authored Nov 5, 2024
2 parents d6c4312 + d05ebb1 commit 2373296
Show file tree
Hide file tree
Showing 130 changed files with 1,022 additions and 1,297 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ jobs:
toolchain: ${{ env.RUST_TOOLCHAIN }}
- run: cargo install snipdoc --features exec
- run: snipdoc check
continue-on-error: true
env:
SNIPDOC_SKIP_EXEC_COMMANDS: true
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@

## Unreleased

* `loco doctor` now checks for app-specific minimum dependency versions. This should help in upgrades. `doctor` also supports "production only" checks which you can run in production with `loco doctor --production`. This, for example, will check your connections but will not check dependencies.
*

## v0.12.0

This release have been primarily about cleanups and simplification.

Please update:

* `loco-rs`
* `loco-cli`

Changes:

* **generators (BREAKING)**: all prefixes in starters (e.g. `/api`) are now _local to each controller_, and generators will be prefix-aware (`--api` generator will add an `/api` prefix to controllers) [https://github.com/loco-rs/loco/pull/818](https://github.com/loco-rs/loco/pull/818)

To migrate, please move prefixes from `app.rs` to each controller you use in `controllers/`, for example in `notes` controller:

```rust
Routes::new()
.prefix("api/notes")
.add("/", get(list))
```

* **starters**: removed `.devcontainer` which can now be found in [loco-devcontainer](https://github.com/loco-rs/loco-devcontainer)
* **starters**: removed example `notes` scaffold (model, controllers, etc), and unified `user` and `auth` into a single file: `auth.rs`
* **generators**: `scaffold` generator will now generate a CRUD with `PUT` and `PATCH` semantics for updating an entity [https://github.com/loco-rs/loco/issues/896](https://github.com/loco-rs/loco/issues/896)
* **cleanup**: `loco-extras` was moved out of the repo, but we've incorporated `MultiDB` and `ExtraDB` from `extras` into `loco-rs` [https://github.com/loco-rs/loco/pull/917](https://github.com/loco-rs/loco/pull/917)

* `cargo loco doctor` now checks for minimal required SeaORM CLI version
* **BREAKING** Improved migration generator. If you have an existing migration project, add the following comment indicator to the top of the `vec` statement and right below the opening bracked like so in `migration/src/lib.rs`:
```rust
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "Apache-2.0"

[package]
name = "loco-rs"
version = "0.11.2"
version = "0.12.0"
description = "The one-person framework for Rust"
homepage = "https://loco.rs/"
documentation = "https://docs.rs/loco-rs"
Expand Down Expand Up @@ -39,7 +39,7 @@ bg_redis = ["dep:rusty-sidekiq", "dep:bb8"]
bg_pg = ["dep:sqlx", "dep:ulid"]

[dependencies]
loco-gen = { version = "0.11.2", path = "./loco-gen" }
loco-gen = { version = "0.12.0", path = "./loco-gen" }
backtrace_printer = { version = "1.3.0" }

# cli
Expand All @@ -55,20 +55,21 @@ sea-orm = { version = "1.1.0", features = [
], optional = true }

tokio = { version = "1.33.0", default-features = false }
tokio-util = "0.7.10"
# the rest

serde = { workspace = true }
serde_json = { workspace = true }
serde_yaml = "0.9"
serde_variant = "0.1.2"
toml = "0.8"


async-trait = { workspace = true }

axum = { workspace = true }
axum-extra = { version = "0.9", features = ["cookie"] }
regex = { workspace = true }
lazy_static = { workspace = true }
fs-err = "2.11.0"
# mailer
tera = "1.19.1"
Expand Down Expand Up @@ -142,7 +143,6 @@ regex = "1"
thiserror = "1"
serde = "1"
serde_json = "1"
lazy_static = "1.4.0"
async-trait = { version = "0.1.74" }
axum = { version = "0.7.5", features = ["macros", "multipart"] }
tower = "0.4"
Expand Down
18 changes: 18 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## Blessed depdenencies maintenance and `loco doctor`

Loco contain a few major and "blessed" dependencies, these appear **both** in an app that was generated at the surface level in their `Cargo.toml` and in the core Loco framework.

If stale, may require an upgrade as a must.

Example for such dependencies:

* The `sea-orm-cli` - while Loco uses `SeaORM`, it uses the `SeaORM` CLI to generate entities, and so there may be an incompatibility if `SeaORM` has a too large breaking change between their CLI (which ships separately) and their framework.
* `axum`
* etc.

This is why we are checking these automatically as part of `loco doctor`.

We keep minimal version requirements for these. As a maintainer, you can update these **minimal** versions, only if required in [`doctor.rs`](src/doctor.rs).



## Running Tests

Before running tests make sure that:
Expand Down
11 changes: 2 additions & 9 deletions docs-site/content/docs/extras/pluggability.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,13 @@ After you've implemented your own initializer, you should implement the `initial

<!-- <snip id="app-initializers" inject_from="code" template="rust"> -->
```rust
async fn initializers(ctx: &AppContext) -> Result<Vec<Box<dyn Initializer>>> {
let mut initializers: Vec<Box<dyn Initializer>> = vec![
async fn initializers(_ctx: &AppContext) -> Result<Vec<Box<dyn Initializer>>> {
let initializers: Vec<Box<dyn Initializer>> = vec![
Box::new(initializers::axum_session::AxumSessionInitializer),
Box::new(initializers::view_engine::ViewEngineInitializer),
Box::new(initializers::hello_view_engine::HelloViewEngineInitializer),
Box::new(loco_extras::initializers::normalize_path::NormalizePathInitializer),
];

if ctx.environment != Environment::Test {
initializers.push(Box::new(
loco_extras::initializers::prometheus::AxumPrometheusInitializer,
));
}

Ok(initializers)
}
```
Expand Down
6 changes: 0 additions & 6 deletions docs-site/content/docs/getting-started/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ impl Hooks for App {
fn routes() -> AppRoutes {
AppRoutes::with_default_routes()
.add_route(controllers::guide::routes())
.add_route(controllers::notes::routes())
.add_route(controllers::auth::routes())
.add_route(controllers::user::routes())
.add_route(controllers::home::routes()) // <--- add this
}
```
Expand Down Expand Up @@ -277,8 +275,6 @@ $ cargo loco routes
[POST] /api/auth/reset
[POST] /api/auth/verify
[GET] /home/hello <---- this is our new route!
[GET] /api/notes
[POST] /api/notes
..
..
$
Expand Down Expand Up @@ -388,12 +384,10 @@ src/models/
├── _entities
│   ├── articles.rs <-- sync'd from db schema, do not edit
│   ├── mod.rs
│   ├── notes.rs
│   ├── prelude.rs
│   └── users.rs
├── articles.rs <-- generated for you, your logic goes here.
├── mod.rs
├── notes.rs
└── users.rs
```

Expand Down
7 changes: 7 additions & 0 deletions docs-site/content/docs/infrastructure/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ auth:
```
<!-- </snip>-->
## Running `loco doctor`

You can run `loco doctor` in your server to check the connection health of your environment.

```sh
$ myapp doctor --production
```

## Generate

Expand Down
2 changes: 1 addition & 1 deletion docs-site/content/docs/processing/scheduler.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ After setting up your jobs, you can verify the configuration to ensure everythin
Run the following command to list the jobs from your scheduler file:
<!-- <snip id="scheduler-list-from-file-command" inject_from="yaml" template="sh"> -->
```sh
cargo loco scheduler --path config/scheduler.yaml --list
cargo loco scheduler --config config/scheduler.yaml --list
```
<!-- </snip> -->

Expand Down
9 changes: 3 additions & 6 deletions docs-site/content/docs/the-app/controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ $ cargo loco routes
[POST] /auth/register
[POST] /auth/reset
[POST] /auth/verify
[GET] /notes/
[POST] /notes/
[GET] /notes/:id
[DELETE] /notes/:id
[POST] /notes/:id
[GET] /user/current
[GET] /auth/current
```

This command will provide you with a comprehensive overview of the controllers currently registered in your system.
Expand Down Expand Up @@ -768,6 +763,8 @@ impl Hooks for App {

In many scenarios, when querying data and returning responses to users, pagination is crucial. In `Loco`, we provide a straightforward method to paginate your data and maintain a consistent pagination response schema for your API responses.

We assume you have a `notes` entity and/or scaffold (replace this with any entity you like).

## Using pagination

```rust
Expand Down
24 changes: 7 additions & 17 deletions docs-site/content/docs/the-app/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ $ cargo loco generate model --link users_votes user:references movie:references
..
..
Writing src/models/_entities/movies.rs
Writing src/models/_entities/notes.rs
Writing src/models/_entities/users.rs
Writing src/models/_entities/mod.rs
Writing src/models/_entities/prelude.rs
Expand Down Expand Up @@ -584,6 +583,8 @@ async fn handle_create_with_password_with_duplicate() {

`Loco` enables you to work with more than one database and share instances across your application.

## Extra DB

To set up an additional database, begin with database connections and configuration. The recommended approach is to navigate to your configuration file and add the following under [settings](@/docs/the-app/your-project.md#settings):

```yaml
Expand All @@ -601,17 +602,13 @@ settings:
```


After configuring the database, import [loco-extras](https://crates.io/crates/loco-extras) and enable the `initializer-extra-db` feature in your Cargo.toml:
```toml
loco-extras = { version = "*", features = ["initializer-extra-db"] }
```

Next load this [initializer](@/docs/extras/pluggability.md#initializers) into `initializers` hook like this example
Load this [initializer](@/docs/extras/pluggability.md#initializers) into `initializers` hook like this example

```rs
async fn initializers(ctx: &AppContext) -> Result<Vec<Box<dyn Initializer>>> {
let initializers: Vec<Box<dyn Initializer>> = vec![
Box::new(loco_extras::initializers::extra_db::ExtraDbInitializer),
Box::new(loco_rs::initializers::extra_db::ExtraDbInitializer),
];
Ok(initializers)
Expand All @@ -632,14 +629,9 @@ pub async fn list(
}
```

## Configuring

To connect more than two different databases, load the feature `initializer-multi-db` in [loco-extras](https://crates.io/crates/loco-extras):
```toml
loco-extras = { version = "*", features = ["initializer-multi-db"] }
```
## Multi-DB (multi-tenant)

The database configuration should look like this:
To connect more than two different databases, the database configuration should look like this:
```yaml
settings:
multi_db:
Expand Down Expand Up @@ -670,14 +662,13 @@ Next load this [initializer](@/docs/extras/pluggability.md#initializers) into `i
```rs
async fn initializers(ctx: &AppContext) -> Result<Vec<Box<dyn Initializer>>> {
let initializers: Vec<Box<dyn Initializer>> = vec![
Box::new(loco_extras::initializers::multi_db::MultiDbInitializer),
Box::new(loco_rs::initializers::multi_db::MultiDbInitializer),
];
Ok(initializers)
}
```

## Using in controllers
Now, you can use the multiple databases in your controller:

```rust
Expand Down Expand Up @@ -744,7 +735,6 @@ impl Hooks for App {
//...
async fn truncate(db: &DatabaseConnection) -> Result<()> {
// truncate_table(db, users::Entity).await?;
// truncate_table(db, notes::Entity).await?;
Ok(())
}
Expand Down
9 changes: 1 addition & 8 deletions docs-site/content/docs/the-app/views.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ impl Hooks for App {

fn routes(_ctx: &AppContext) -> AppRoutes {
AppRoutes::with_default_routes()
.add_route(controllers::notes::routes())
.add_route(controllers::auth::routes())
.add_route(controllers::user::routes())
// include your controller's routes here
.add_route(controllers::dashboard::routes())
}
Expand All @@ -198,12 +196,7 @@ $ cargo loco routes
[POST] /api/auth/register
[POST] /api/auth/reset
[POST] /api/auth/verify
[GET] /api/notes
[POST] /api/notes
[GET] /api/notes/:id
[DELETE] /api/notes/:id
[POST] /api/notes/:id
[GET] /api/user/current
[GET] /api/auth/current
[GET] /home <-- the corresponding URL for our new view
```

Expand Down
25 changes: 18 additions & 7 deletions examples/demo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2373296

Please sign in to comment.