-
Notifications
You must be signed in to change notification settings - Fork 5
Add uniqueKeys
property to Table Schema
#30
Conversation
Deploying with Cloudflare Pages
|
This is a useful property. As far as I understand, it replaces the functionality of I think that we should actually remove |
@peterdesmet BTW, we have an option of requiring @khughitt |
That could be a useful restriction to have so that singular uniqueness is reserved for |
Yea it might be not perfect but I think it's pragmatic, for example, it's the same in SQL DDL:
To make it simple for users there are two ways of achieving the same thing |
This looks good to me. It's an important feature, and fits well as a schema-level prop alongside "primaryKey" and "foreignKeys".
I agree.
I could go either way on this, but I lean towards @roll's pragmatic argument of allowing both ways to specify a single field key. SQL sets a good precedent. Another reason to allow 1+ field keys is it keeps implementations simple. This way, an empty list of keys is a no-op, and 1+ field names defines a uniqueness constraint. But if we require 2+ keys in the spec then we have to specifically check for the 1 element list case and throw an error there. ("Error: only one key in uniqueKeys, please add another key or instead use fields.constraints.unique")... not as simple/elegant/zen.
If we were designing the spec from scratch I think I would support this, but I actually consider removing fields.constraints.unique at this point to be a breaking change. Yes, it doesn't break schema parsing on existing packages, but it does break a schema feature for existing packages. I could be convinced otherwise, because this is a major version increment and it would help us avoid carrying "vestigial" features forward. But this is a nuance we should definitely further clarify in the v2 rules... |
Great! So let's keep it simple, as this PR exactly mimics the SQL semantics (I realized just during the discussion 😄 ). |
ACCEPTED by WG (6/9) |
Rationale
Requiring multiple field uniqueness is a vital part of data modeling. This proposal is based on the Unique Constraints pattern but updated to be compatible with the SQL standard.