From 4e5315b8e1ce0eecd023c8df5b1f025a58fc1d48 Mon Sep 17 00:00:00 2001 From: "Dotan J. Nahum" Date: Sun, 20 Oct 2024 12:25:03 +0300 Subject: [PATCH] fix: improve migration generator when a single or no migration exists --- CHANGELOG.md | 6 ++++++ examples/demo/migration/src/lib.rs | 1 + src/gen/templates/migration.t | 2 +- src/gen/templates/model.t | 2 +- starters/rest-api/migration/src/lib.rs | 1 + starters/saas/migration/src/lib.rs | 1 + 6 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76878913f..1c0b43b70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +* **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: +```rust + fn migrations() -> Vec> { + vec![ + // inject-below (do not remove this comment) +``` ## v0.11.0 diff --git a/examples/demo/migration/src/lib.rs b/examples/demo/migration/src/lib.rs index 0efc11a32..6db70a3c5 100644 --- a/examples/demo/migration/src/lib.rs +++ b/examples/demo/migration/src/lib.rs @@ -12,6 +12,7 @@ pub struct Migrator; impl MigratorTrait for Migrator { fn migrations() -> Vec> { vec![ + // inject-below (do not remove this comment) Box::new(m20220101_000001_users::Migration), Box::new(m20231103_114510_notes::Migration), Box::new(m20240416_071825_roles::Migration), diff --git a/src/gen/templates/migration.t b/src/gen/templates/migration.t index b7bd2d50a..dfc760758 100644 --- a/src/gen/templates/migration.t +++ b/src/gen/templates/migration.t @@ -6,7 +6,7 @@ skip_glob: "migration/src/*_{{mig_name}}.rs" message: "Migration for `{{name}}` added! You can now apply it with `$ cargo loco db migrate`." injections: - into: "migration/src/lib.rs" - before_last: "\\]" + after: "inject-below" content: " Box::new({{module_name}}::Migration)," - into: "migration/src/lib.rs" before: "pub struct Migrator" diff --git a/src/gen/templates/model.t b/src/gen/templates/model.t index c97952831..8f9fe24c8 100644 --- a/src/gen/templates/model.t +++ b/src/gen/templates/model.t @@ -7,7 +7,7 @@ skip_glob: "migration/src/*_{{plural_snake}}.rs" message: "Migration for `{{name}}` added! You can now apply it with `$ cargo loco db migrate`." injections: - into: "migration/src/lib.rs" - before_last: "\\]" + after: "inject-below" content: " Box::new({{module_name}}::Migration)," - into: "migration/src/lib.rs" before: "pub struct Migrator" diff --git a/starters/rest-api/migration/src/lib.rs b/starters/rest-api/migration/src/lib.rs index 3352f5c57..cdf5ebc7b 100644 --- a/starters/rest-api/migration/src/lib.rs +++ b/starters/rest-api/migration/src/lib.rs @@ -11,6 +11,7 @@ pub struct Migrator; impl MigratorTrait for Migrator { fn migrations() -> Vec> { vec![ + // inject-below (do not remove this comment) Box::new(m20220101_000001_users::Migration), Box::new(m20231103_114510_notes::Migration), ] diff --git a/starters/saas/migration/src/lib.rs b/starters/saas/migration/src/lib.rs index 3352f5c57..cdf5ebc7b 100644 --- a/starters/saas/migration/src/lib.rs +++ b/starters/saas/migration/src/lib.rs @@ -11,6 +11,7 @@ pub struct Migrator; impl MigratorTrait for Migrator { fn migrations() -> Vec> { vec![ + // inject-below (do not remove this comment) Box::new(m20220101_000001_users::Migration), Box::new(m20231103_114510_notes::Migration), ]