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

Adding a new migration when there is only one present results in broken code #879

Closed
darricheng opened this issue Oct 20, 2024 · 3 comments

Comments

@darricheng
Copy link
Contributor

darricheng commented Oct 20, 2024

Description

When there is only one migration in the /migration/src/lib.rs file, adding a new migration via CLI results in broken code.

Before:

#![allow(elided_lifetimes_in_paths)]
#![allow(clippy::wildcard_imports)]
pub use sea_orm_migration::prelude::*;

mod m20220101_000001_users;

pub struct Migrator;

#[async_trait::async_trait]
impl MigratorTrait for Migrator {
    fn migrations() -> Vec<Box<dyn MigrationTrait>> {
        vec![Box::new(m20220101_000001_users::Migration)]
    }
}

After:

#![allow(elided_lifetimes_in_paths)]
#![allow(clippy::wildcard_imports)]
pub use sea_orm_migration::prelude::*;

mod m20220101_000001_users;

mod m20241020_051916_tests;
pub struct Migrator;

#[async_trait::async_trait]
impl MigratorTrait for Migrator {
    fn migrations() -> Vec<Box<dyn MigrationTrait>> {
            Box::new(m20241020_051916_tests::Migration),
        vec![Box::new(m20220101_000001_users::Migration)]
    }
}

To Reproduce

  1. Remove all but one migration in the /migration/src/lib.rs file as shown above.
  2. Run a command that generates a migration, e.g.cargo loco generate model test name:string

Expected Behavior

The new migration should be added into the vec![] macro correctly.

Misc

I'm willing to contribute a fix, though I'll need some guidance to find the source of the issue because I'm still unfamiliar with the codebase.

@jondot
Copy link
Contributor

jondot commented Oct 20, 2024

Thanks! looks like something we should fix.
I'm wondering how did you get a single migration? (most of the starters have multiple)

@jondot
Copy link
Contributor

jondot commented Oct 20, 2024

Look here: 26f0069
This should give you a sense for how to fix generator related issues in the future :)
Thanks for catching this!

@jondot jondot closed this as completed Oct 20, 2024
@darricheng
Copy link
Contributor Author

I was following the file changes in #846 on what files and code to edit, so that I could remove the notes model and related code from the saas starter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants