-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow schema fields to be set to read only #4335
Allow schema fields to be set to read only #4335
Conversation
Do you think it makes sense to have write only fields? I am asking because we already use |
I actually started with To me it's a strange idea though and I never really encountered that behaviour anywhere. I'm happy to change back to read_only if you also think it's ok. |
The implementation looks clean and concise. The addition of For now, I would prefer to call them I also wonder if there is a relationship between the following options:
I am not saying there is, just wondering. Any other option we may have missed? |
The other one is
The other field options are completely unrelated: :default,
:source,
:autogenerate,
:read_after_writes,
:virtual,
:primary_key,
:load_in_query,
:redact,
:foreign_key,
:on_replace,
:defaults,
:type,
:where,
:references,
:skip_default_validation,
:mode |
Virtual is pretty close because you could select an existing database field into it if you're explicit. But you would not be able to retrieve it by selecting something like |
Yeah,
There is at least the argument that Similarly, we could have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one tiny comment and ship it!
I forgot about embeds btw. Do you think we should raise if I was thinking yes because we cannot really merge the new stuff into the old value. We can only do a complete overwrite. |
Yes, it is a perfectly fine starting point. |
@josevalim thanks for all the feedback. i think this is the cleanest iteration so far. let me know what you think! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beauitiful, just minor nits!
Co-authored-by: José Valim <[email protected]>
Motivation
The
:mode
option will allow users to choose if a field should be read only or read-write. It is basically the same as adding a:read_only
option only having a single field will let us add write only fields in the same place later on instead of creating a new field, if we want to add it.Read only fields are useful for a few reasons:
generated
option to migrations. This allows users to put them into their schemas and have them just work™.Changes
There were a lot of cases to consider. I will list them below:
Casting
Insert
returning: true
is specifiedon_conflict
. They will be silently ignored forreplace_all
because the user is not specifying them. For{:replace, fields}
and conflict queries an error will be raised because the user is going out of their way to specify them.Insert All
returning
andon conflict
applies here as it did forinsert
Update
insert
, we silently ignore read only fields in the changeset. It might make sense to raise here but we don't do so for virtual fields. If we want to change one I think there's a case to change both.insert
forreturning
. There is noon_conflict
to worry about.Update All
:update
key in the query.Select
Delete
Delete All