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

style: schema.rs doesn't comply with rustfmt #4405

Closed
3 tasks done
AndreCostaaa opened this issue Dec 23, 2024 · 4 comments · Fixed by #4407
Closed
3 tasks done

style: schema.rs doesn't comply with rustfmt #4405

AndreCostaaa opened this issue Dec 23, 2024 · 4 comments · Fixed by #4407

Comments

@AndreCostaaa
Copy link
Contributor

Setup

Versions

  • Rust: 1.80.1
  • Diesel: 2.2.4 (cli)
  • Database: Postgresql
  • Operating System Linux

Feature Flags

  • diesel: N/A

Problem Description

The schema.rs file created by diesel-cli when running a migration doesn't always comply with rustfmt

What are you trying to accomplish?

I'm trying to use the diesel-cli to generate the migrations and the schema.rs file

What is the expected output?

Running cargo fmt -- --check should produce no errors.

What is the actual output?

Depending on the number of tables, the schema.rs file is not formatted properly and thus resulting in an error when running cargo fmt

Are you seeing any additional errors?

No

Steps to reproduce

  1. Setup a basic diesel and cargo project

  2. Generate a migration

diesel migration generate migration1

Put the following into your `migrations/XXX_migration1/up.sql

CREATE TABLE t0 (id SERIAL PRIMARY KEY);
CREATE TABLE t1 (id SERIAL PRIMARY KEY, t0_id INTEGER NOT NULL REFERENCES t0);
  1. Run the diesel migration
diesel migration run
  1. Add this on top of your main.rs
mod schema;
  1. Run cargo fmt
cargo fmt -- --check 

Output:

Diff in XXX/src/schema.rs at line 15:
 
 diesel::joinable!(t1 -> t0 (t0_id));
 
-diesel::allow_tables_to_appear_in_same_query!(
-    t0,
-    t1,
-);
+diesel::allow_tables_to_appear_in_same_query!(t0, t1,);

You can checkout a test repository here

Checklist

  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
  • This issue can be reproduced without requiring a third party crate
@weiznich
Copy link
Member

Thanks for opening this issue. Diesel cli emits a @generated which should instruct rustfmt to ignore this file. If that doesn't work this seems to be more a rustfmt issue and should be reported there.

That written: I'm open to accept a PR that emits the correct formatting in this case. For larger schemas that already works but for only a few tables that doesn't seem to be perfect.

@AndreCostaaa
Copy link
Contributor Author

I'm open to accept a PR that emits the correct formatting in this case

Would spawning a rustfmt process from the diesel-cli after writting the schema.rs file be acceptable for you?

@weiznich
Copy link
Member

If that works reliably with the patching mechanism it would be acceptable to just use rustfmt for this as long as its failure tolerant if rustfmt is not installed.

@AndreCostaaa
Copy link
Contributor Author

Exactly what I had in mind. Will send a PR soon

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

Successfully merging a pull request may close this issue.

2 participants