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

"cargo loco generate model" command automatically apply migration and ask user to apply migration. #1295

Open
alokmahor opened this issue Mar 10, 2025 · 1 comment

Comments

@alokmahor
Copy link

Description

When running the command cargo loco generate model, migrations are automatically applied. However, the command output still prompts the user to apply the migration. This behavior is inconsistent. The command should not apply migrations automatically. If it does, then the output should not ask the user to apply the migration again.

To Reproduce

loco new
then select option Rest API (with DB and user auth)
cd myapp
cargo loco generate model article title:string content:text

Expected Behavior

The command should not apply migrations automatically. If it does, then the output should not ask the user to apply the migration again.

Environment:

Additional Context

Here is output of command

cargo loco generate model article title:string content:text
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.66s
     Running `target/debug/myapp-cli generate model article 'title:string' 'content:text'`
added: "migration/src/m20250310_090113_articles.rs"
injected: "migration/src/lib.rs"
injected: "migration/src/lib.rs"
added: "tests/models/articles.rs"
injected: "tests/models/mod.rs"
   Compiling ring v0.17.13
   Compiling rustls v0.23.23
   Compiling rustls-webpki v0.102.8
   Compiling jsonwebtoken v9.3.1
   Compiling sqlx-core v0.8.3
   Compiling tokio-rustls v0.26.2
   Compiling hyper-rustls v0.27.5
   Compiling lettre v0.11.14
   Compiling reqwest v0.12.12
   Compiling opendal v0.50.2
   Compiling sqlx-mysql v0.8.3
   Compiling sqlx-sqlite v0.8.3
   Compiling sqlx-postgres v0.8.3
   Compiling sqlx v0.8.3
   Compiling sea-query-binder v0.7.0
   Compiling sea-orm v1.1.7
   Compiling sea-orm-migration v1.1.7
   Compiling loco-rs v0.14.1
   Compiling migration v0.1.0 (/Users/alok/tmp/test-rust/myapp/migration)
   Compiling myapp v0.1.0 (/Users/alok/tmp/test-rust/myapp)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 23.64s
     Running `target/debug/myapp-cli db migrate`
2025-03-10T09:01:37.837332Z  WARN app: loco_rs::boot: pretty backtraces are enabled (this is great for development but has a runtime cost for production. disable with `logger.pretty_backtrace` in your config yaml) environment=development
2025-03-10T09:01:37.868054Z  WARN app: loco_rs::boot: migrate: environment=development
2025-03-10T09:01:37.876313Z  INFO app: sea_orm_migration::migrator: Applying all pending migrations environment=development
2025-03-10T09:01:37.882400Z  INFO app: sea_orm_migration::migrator: Applying migration 'm20250310_090113_articles' environment=development
2025-03-10T09:01:37.968161Z  INFO app: sea_orm_migration::migrator: Migration 'm20250310_090113_articles' has been applied environment=development
    Blocking waiting for file lock on build directory
   Compiling ring v0.17.13
   Compiling rustls v0.23.23
   Compiling rustls-webpki v0.102.8
   Compiling jsonwebtoken v9.3.1
   Compiling sqlx-core v0.8.3
   Compiling tokio-rustls v0.26.2
   Compiling hyper-rustls v0.27.5
   Compiling lettre v0.11.14
   Compiling reqwest v0.12.12
   Compiling opendal v0.50.2
   Compiling sqlx-postgres v0.8.3
   Compiling sqlx-sqlite v0.8.3
   Compiling sqlx-mysql v0.8.3
   Compiling sqlx v0.8.3
   Compiling sea-query-binder v0.7.0
   Compiling sea-orm v1.1.7
   Compiling sea-orm-migration v1.1.7
   Compiling loco-rs v0.14.1
   Compiling migration v0.1.0 (/Users/alok/tmp/test-rust/myapp/migration)
   Compiling myapp v0.1.0 (/Users/alok/tmp/test-rust/myapp)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 35.61s
     Running `target/debug/myapp-cli db entities`
2025-03-10T09:02:14.769086Z  WARN app: loco_rs::boot: pretty backtraces are enabled (this is great for development but has a runtime cost for production. disable with `logger.pretty_backtrace` in your config yaml) environment=development
2025-03-10T09:02:14.795544Z  WARN app: loco_rs::boot: entities: environment=development
Connecting to MySQL ...
Discovering schema ...
... discovered.
Generating articles.rs
    > Column `created_at`: DateTimeUtc, not_null
    > Column `updated_at`: DateTimeUtc, not_null
    > Column `id`: i32, auto_increment, not_null
    > Column `title`: Option<String>
    > Column `content`: Option<String>
Generating posts.rs
    > Column `created_at`: DateTimeUtc, not_null
    > Column `updated_at`: DateTimeUtc, not_null
    > Column `id`: i32, auto_increment, not_null
    > Column `title`: Option<String>
    > Column `content`: Option<String>
Generating users.rs
    > Column `created_at`: DateTimeUtc, not_null
    > Column `updated_at`: DateTimeUtc, not_null
    > Column `id`: i32, auto_increment, not_null
    > Column `pid`: Vec<u8>, not_null
    > Column `email`: String, not_null, unique
    > Column `password`: String, not_null
    > Column `api_key`: String, not_null, unique
    > Column `name`: String, not_null
    > Column `reset_token`: Option<String>
    > Column `reset_sent_at`: Option<DateTimeUtc>
    > Column `email_verification_token`: Option<String>
    > Column `email_verification_sent_at`: Option<DateTimeUtc>
    > Column `email_verified_at`: Option<DateTimeUtc>
    > Column `magic_link_token`: Option<String>
    > Column `magic_link_expiration`: Option<DateTimeUtc>
Writing src/models/_entities/articles.rs
Writing src/models/_entities/posts.rs
Writing src/models/_entities/users.rs
Writing src/models/_entities/mod.rs
Writing src/models/_entities/prelude.rs
... Done.
2025-03-10T09:02:15.321012Z  WARN app: loco_rs::boot:  environment=development
* Migration for `article` added! You can now apply it with `$ cargo loco db migrate`.
* A test for model `Articles` was added. Run with `cargo test`.
@kaplanelad
Copy link
Contributor

Thanks @alokmahor,
Related discussion: #1283

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