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(diesel_cli): use separate lines for multiple annotations #3681

Merged
merged 2 commits into from
Jul 6, 2023

Conversation

DannyGoldberg
Copy link
Contributor

@DannyGoldberg DannyGoldberg commented Jul 6, 2023

We were running into a compilation error from diesel-derives where we had both a sql_name and max_length annotation for the same property, which would generate something like this:

diesel::table! {
    example (id) {
        id -> Uuid,
        #[sql_name = "type", max_length = 200]
        type_ -> Nullable<Varchar>,
    }
}

and would throw a compilation error like this:

error: Invalid `table!` syntax. Please see the `table!` macro docs for more info.
       Docs available at: `https://docs.diesel.rs/master/diesel/macro.table.html`

note: this isn't yet tested locally, as I've had trouble getting this repo running locally

This should result in something like the following, which wouldn't fail to compile:

diesel::table! {
    example (id) {
        id -> Uuid,
        #[sql_name = "type"]
        #[max_length = 200]
        type_ -> Nullable<Varchar>,
    }
}

We were running into a compilation error from diesel-derives where we had both a sql_name and max_length annotation for the same property

```
error: Invalid `table!` syntax. Please see the `table!` macro docs for more info.
       Docs available at: `https://docs.diesel.rs/master/diesel/macro.table.html`
```
@DannyGoldberg DannyGoldberg marked this pull request as ready for review July 6, 2023 17:59
if column.rust_name != column.sql_name {
writeln!(out, r#"#[sql_name = "{}"]"#, column.sql_name)?;
}
if let Some(max_length) = column.ty.max_length {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ten0 this intends to fix an issue I ran into from #3552, where multiple comma-separated annotations would cause compilation errors -- github actions tests pass, although I am having some trouble testing it locally

@DannyGoldberg DannyGoldberg changed the title fix: use separate lines for multiple annotations fix(diesel_cli): use separate lines for multiple annotations Jul 6, 2023
@weiznich weiznich requested a review from a team July 6, 2023 18:39
@weiznich
Copy link
Member

weiznich commented Jul 6, 2023

Thanks for opening this PR. Can you add a test for that in diesel_cli/tests/print_schema.rs (see the print_schema dir there for examples of existing test cases.)

@weiznich weiznich enabled auto-merge July 6, 2023 19:36
@weiznich weiznich added this pull request to the merge queue Jul 6, 2023
Merged via the queue into diesel-rs:master with commit 0f64912 Jul 6, 2023
31 checks passed
@weiznich weiznich added the maybe backport Maybe backport this pr to the latest diesel release label Jul 7, 2023
weiznich added a commit to weiznich/diesel that referenced this pull request Aug 18, 2023
fix(diesel_cli): use separate lines for multiple annotations
@weiznich weiznich mentioned this pull request Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maybe backport Maybe backport this pr to the latest diesel release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants