Diesel: Support multiple schemas in diesel.toml

Created on 23 May 2018  路  9Comments  路  Source: diesel-rs/diesel

Versions

  • Diesel: 1.3
  • Database: Postgres

What are you trying to accomplish?

In 1.3, the diesel.toml file has been introduced. In the current form, you can only read tables from one schema. I'd like a way to specify multiple schemas that can all be generated into a single schema.rs file.

Perhaps you could have multiple [print-schema] sections, each one belonging to a different schema, since you may want to apply different filtering depending on the schema. I think all the existing options are good to have available for each schema you want to load from, except probably patch_file since it applies to the whole file.

accepted

Most helpful comment

Something like the following would likely be beneficial

# For documentation on how to configure this file,
# see diesel.rs/guides/configuring-diesel-cli

[print_schema]
include_schemas = ["schema1", "schema2", "schema3"]
exclude_schemas = ["pg_catalog", "information_schema"] # Implicit defaults include xor exclude
patch_file = ""

[print_schema.schema1]
file = "src/models/schema1.rs"
filter = { except_tables = ["spatial_ref_sys"] }

[print_schema.schema2]
file = "src/models/schema2.rs"
filter = { except_tables = ["ignored_system_table"] }

All 9 comments

I'm not sure that multiple print-schema sections is the way to go, but I think we need to support this somehow. Agreed that it would need to support separate filters per schema, and that could definitely lead to the conclusion that duplicating that section is the way to go. However, we could also allow filters to specify the schema in the table name. e.g. filter = { only-tables = ["schema1.table1", "schema2.table1"] }

That sounds better to me because, looking again, patch_file and with_docs are universal options that would apply to all schemas. It would certainly make for a shorter and easier to understand file. I'm not sure if you'd want schema specific import_types (I don't use that feature currently).

I don't think we need import_types be schema specific. There's no harm in having the imports used by schema 2 in the tables from schema 1 99% of the time. I'm sure someone out there has a very specific case where this doesn't work, but... that's what patch_file is for.

I like to keep my structure like /models/table1/model.rs, schema.rs, /models/table2/model.rs,schema.rs. So yes I would also appreciate some scenario, where I can split Large single schema.rs in to multiple ones.

Something like [printschema.whatever] with the usual properties could work if it inherited from the base printschema, I can't think of many other ways to do it & support filtering that isn't kinda messy imo.

Something like the following would likely be beneficial

# For documentation on how to configure this file,
# see diesel.rs/guides/configuring-diesel-cli

[print_schema]
include_schemas = ["schema1", "schema2", "schema3"]
exclude_schemas = ["pg_catalog", "information_schema"] # Implicit defaults include xor exclude
patch_file = ""

[print_schema.schema1]
file = "src/models/schema1.rs"
filter = { except_tables = ["spatial_ref_sys"] }

[print_schema.schema2]
file = "src/models/schema2.rs"
filter = { except_tables = ["ignored_system_table"] }

I would for sure love multiple schema support. If there is an approved direction I'd be happy to try and take it on.

@drusellers Sorry for the late answer. There is currently no approved direction for how this should be implemented. That does not mean you cannot start to work on this issue, as we are just looking for a reasonable way to configure this. We are open for suggestions here and bringing in a implementation is certainly a argument for a certain way of doing this :wink:

@weiznich totally understand. :) I'll start poking around.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kanekv picture kanekv  路  3Comments

gutsle picture gutsle  路  4Comments

astraw picture astraw  路  4Comments

mkroman picture mkroman  路  3Comments

killercup picture killercup  路  4Comments