Open parsonsmatt opened 5 years ago
Sounds sensible to me; it's hard to think of a case where the current behaviour is desirable.
I guess if the Haskell program using persistent
is only an observer of the table and just doesn't want to observe ALL columns, it can use MigrationOnly
to shrink the amount of fields in the resulting data type, but this isn't really why you'd do migrations with persistent
IMHO.
I'd say it makes a lot of sense that anything marked as MigrationOnly
should imply Maybe
. So I'd second this change.
Has this been changed already, or is this still a to-do?
This has not been done yet, as far as I know.
On second thoughts, I think it is possible/reasonable to genuinely want a NOT NULL field which Persistent isn't aware of, and the insertion issue can be addressed with a default, right? If I write myField Int MigrationOnly default='0'
then I think I will still be able to do everything I need to do from Persistent as if that field didn't exist. So perhaps we should leave things as they are and instead emit a warning if all of the following are true? (Can we do that?)
@hdgarrood Yeah that sounds like the best solution to me. A column being NULL
or Maybe
really is just an implied default=NULL
.
Currently, using
MigrationOnly
on a column will omit the field from the Haskell datatype but the resulting SQL is still intact.This means if you do an
insert
on a record with a non-nullable (and no default)MigrationOnly
column that it will fail at runtime with a "missing value" error.You can fix this by doing
field FieldType Maybe MigrationOnly
. ShouldMigrationOnly
implyMaybe
?