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

diesel cli generate does not create relations for models in different schema when using postgres schema #4476

Open
3 tasks done
thehiddenwaffle opened this issue Feb 9, 2025 · 1 comment
Labels

Comments

@thehiddenwaffle
Copy link

Setup

Versions

  • Rust: 1.84.1
  • Diesel: 2.2.7
  • Database: Postgres 17.1
  • Operating System Ubuntu 24.04.1

Feature Flags

  • diesel: ["postgres_backend", "postgres", "time", "r2d2", "uuid", "serde_json"]

Problem Description

Similar to #2096
I am however using the schema="name" found in the resolution of that issue as follows

[print_schema.game]
file = "src/diesel_schema/game.rs"
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"]
schema = "game"

[print_schema.people]
file = "src/diesel_schema/people.rs"
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"]
schema = "people"

[migrations_directory]
dir = "./migrations"

I also have 2 tables, one in each schema:

CREATE TABLE "people"."api_token"
(
    id       INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    val      UUID NOT NULL DEFAULT gen_random_uuid()
);
CREATE TABLE "game"."game_session"
(
    id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    api_token_id INTEGER REFERENCES "people"."api_token" (id) NOT NULL -- relation
);

The generated diesel schemas do not include the relationship:

pub mod game {
    diesel::table! {
        game.game_session (id) {
            id -> Int4,
            api_token_id -> Int4,
        }
    }
}
pub mod people {
    diesel::table! {
        people.api_token (id) {
            id -> Int4,
            val -> Uuid,
        }
    }
}

What is the expected output?

one of the schema(game.rs I think?) should include:

diesel::joinable!(game_session -> api_token (api_token_id));
diesel::allow_tables_to_appear_in_same_query!(
        api_token,
        game_session
}

Are you seeing any additional errors?

Yes, cli generate --diff-schema produces empty sql files when I manually add the above lines and then call it.

Steps to reproduce

see above

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
@thehiddenwaffle
Copy link
Author

I would like to praise the development team for the patch_file option which is single handedly saving me from having wait till this issue is resolved. A true stroke of genius.

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

No branches or pull requests

1 participant