-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
We would like to improve the way Diesel supports enums.
Backends
- PostgreSQL
- MySQL
Idea
Diesel ships a CLI tool that inspects the database and generates a schema.rs file based on that database. For any "custom" type that we encounter we already generate a custom type mapping via our #[derive(SqlTye)]. This includes enum types. We would like to extend this functionality to not only generate the SQL side type, but also a matching Rust enum definition if the user has opted into this behavior. This would be only supported for the following narrow use-cases:
For both variants we would like to generate the matching field less rust enum if the user enabled a corresponding opt-in setting for diesel-cli.
To make this happen we need to:
- Implement a custom derive implementing
FromSqlandToSqlfor the generated enum for this narrow use-case - Extend the schema inference code in diesel-cli to also include information about the fields of these enums
- Generate the enums + the relevant derive as part of the print-schema process
- Make sure to also handle this in generate-migration.
Each of these steps should be implemented as separate PR to keep the changes as small as possible. Each of the steps should have documentation and some tests to verify that everything works as expected.
Metadata
Metadata
Assignees
Type
Projects
Status