Electron100 / butane

An ORM for Rust with a focus on simplicity and on writing Rust, not SQL
Apache License 2.0
83 stars 11 forks source link

Migrations allow new mandatory fields without a default #182

Open jayvdb opened 5 months ago

jayvdb commented 5 months ago

#[default] needs to be added to any mandatory fields added after the initial migration.

Currently this isnt enforced. I expect the place to issue the warning or error is in make-migration.

IMO it should be a warning (initially, at least) as having no default is only critical when updating existing data - while that is an important feature, the majority of database column additions occur before the schema is in production.

Perhaps before it is enforced, there are alternatives, such as using the Default trait as a fallback. Another way to achieve that is to support #[serde(default)] https://serde.rs/attr-default.html , which avoids developing our own syntax when one already exists that should be sufficient, and then perhaps adding #[butane(default)] if there are some database specific "default" behaviours that are needed.