You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a follow-up to #467. I've had a use case now where I wanted to create a primary key constraint with a comment, and it's not easily possible. For foreign keys we now have the referencesConstraintComment, but adding more options in this scheme would be quite ugly. Also I noticed that constraint options like deferrable and deferred are placed next to the constraints, not related to the constraint itself.
I would recommend a complete redesign, with one object per constraint definition following the SQL data model. My idea:
(maybe more detailed wrt exclude constraints - but for now a simple string should suffice)
I will ignore NOT NULL, NULL, DEFAULT and IDENTITY constraints as these seem more like column options, and although technically they seem to be constraints and could be named, that seems to be ignored anyway, and they have their own ALTER COLUMN syntax.
So each column definition would simply get a constraints array property similar to what table options already have.
For ease of use, we'd get the following shorthands:
{check: expression} becomes {type: 'CHECK', expression}, same for exclude.
{unique: columns} becomes {type: 'UNIQUE', columns}, same for primaryKey
If any of these shorthand expansions collides with an already-existing type, an error is thrown - any constraint object can only represent a single constraint
For backwards compatibility (and ease of use), the column definition current format is interpreted as a shorthand as well:
check, unique, references, primaryKey properties that contain Constraint objects automatically get their type set
check, unique, references, primaryKey properties that contain primitives, arrays or Names will get expanded into the respective Constraint object
options like deferrable/deferred and the RefConstraint ones get propagated down to all generated/expanded constraint objects
the foreignKeys array would become deprecated, it would be interpreted just like the constraints array.
What do you think about this? Does it sound reasonable? Are there any backward-compatibility concerns?
The text was updated successfully, but these errors were encountered:
This is a follow-up to #467. I've had a use case now where I wanted to create a primary key constraint with a comment, and it's not easily possible. For foreign keys we now have the
referencesConstraintComment
, but adding more options in this scheme would be quite ugly. Also I noticed that constraint options likedeferrable
anddeferred
are placed next to the constraints, not related to the constraint itself.I would recommend a complete redesign, with one object per constraint definition following the SQL data model. My idea:
(maybe more detailed wrt exclude constraints - but for now a simple string should suffice)
I will ignore
NOT NULL
,NULL
,DEFAULT
andIDENTITY
constraints as these seem more like column options, and although technically they seem to be constraints and could be named, that seems to be ignored anyway, and they have their ownALTER COLUMN
syntax.So each column definition would simply get a
constraints
array property similar to what table options already have.For ease of use, we'd get the following shorthands:
{check: expression}
becomes{type: 'CHECK', expression}
, same forexclude
.{unique: columns}
becomes{type: 'UNIQUE', columns}
, same forprimaryKey
{references}
becomes{type: 'FOREIGN', references}
type
, an error is thrown - any constraint object can only represent a single constraintFor backwards compatibility (and ease of use), the column definition current format is interpreted as a shorthand as well:
check
,unique
,references
,primaryKey
properties that containConstraint
objects automatically get theirtype
setcheck
,unique
,references
,primaryKey
properties that contain primitives, arrays or Names will get expanded into the respectiveConstraint
objectdeferrable
/deferred
and theRefConstraint
ones get propagated down to all generated/expanded constraint objectsforeignKeys
array would become deprecated, it would be interpreted just like theconstraints
array.What do you think about this? Does it sound reasonable? Are there any backward-compatibility concerns?
The text was updated successfully, but these errors were encountered: