Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve migration generator when a single or no migration exists #880

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn MigrationTrait>> {
vec![
// inject-below (do not remove this comment)
```

## v0.11.0

Expand Down
1 change: 1 addition & 0 deletions examples/demo/migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Migrator;
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
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),
Expand Down
2 changes: 1 addition & 1 deletion src/gen/templates/migration.t
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/gen/templates/model.t
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions starters/rest-api/migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Migrator;
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
// inject-below (do not remove this comment)
Box::new(m20220101_000001_users::Migration),
Box::new(m20231103_114510_notes::Migration),
]
Expand Down
1 change: 1 addition & 0 deletions starters/saas/migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Migrator;
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
// inject-below (do not remove this comment)
Box::new(m20220101_000001_users::Migration),
Box::new(m20231103_114510_notes::Migration),
]
Expand Down
Loading