是否有可能使柴油机处理多数据库?

is it possible to make diesel to handle multi database?

我使用 diesel 作为我的 rust orm 查询库,现在当我使用新数据库时,diesel migration run 命令将覆盖最后一个 scheme.rs 文件。如何使柴油机可以处理多个数据库。例如,每个数据库使用不同的 schema.rs 文件,数据库 A 不会覆盖数据库 B shema.rs 的内容。我应该怎么做才能让它按预期工作?这是我的柴油依赖配置:

diesel = { version = "1.4.7", features = ["postgres","32-column-tables"] }

我从这个 issue:

[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"] }

但请给我提示:

$ diesel migration run                                  ‹ruby-2.7.2›
unknown field `include_schemas`, expected one of `file`, `with_docs`, `filter`, `schema`, `patch_file`, `import_types` for key `print_schema`
(base)

我应该怎么做才能让它发挥作用?

您可以使用单独的配置文件,并在 运行 迁移时使用 --config-file 选择一个:

diesel1.toml:

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

diesel2.toml:

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

用作:

diesel migration run --config-file=diesel1.toml
diesel migration run --config-file=diesel2.toml