-
Notifications
You must be signed in to change notification settings - Fork 122
[WIP][RFC]sequences support #186
Comments
…yle columns in PostgreSQL
Amendment to how SequenceFeatures are filtered from FeatureSet to match documentation. Since sequence names are not always known + more natural to interact with TableGateway using column names, filter function call by column names. Open to suggestion on how to improve this and filter somehow from FeatureSet *before* attempt to execute method on the feature (challenge to do so that does not break other feature types). Also, since SequenceFeature is more involved and requires long description, can consider moving to own docs page.
Docs SQL alignment
…er than 63 bytes for postgresql, query the actual name.
…quence does not imply primary key.
…ncrement interval.
… to specify schema.
…tform and adapter objects
Trying to consolidate conflicting sequence PRs reported over time in Zend DB. Stuck at deciding how to do platform specific code. Would like opinion of significantly more knowledgeable than I am individuals @froschdesign @Ocramius @weierophinney Original code had switch/case statement per platform. Thats what bug reports focused on so I followed same pattern: https://github.com/zendframework/zend-db/pull/187/files#diff-85fe938f5a6f87443ad2578472eed9e0R166 But I just noticed there is duplication of that lastSequenceId() query in Connection class. Seems like a great benefit because do not need nasty switch($platform), and if anyone relied on similarly broken code in Connection too, all is fixed in one place. https://github.com/zendframework/zend-db/blob/master/src/Adapter/Driver/Pgsql/Connection.php#L267 https://github.com/zendframework/zend-db/blob/master/src/Adapter/Driver/Pdo/Connection.php#L419 There are some concerns, however. What about nextSequenceId()? Connection interface does not have signature for it the way getLastGeneratedValue() is and rightfully so, I believe, should not be added. I could add nextSequenceId() to connection classes without adding to interface and assume dynamic typing will handle it, but that looks dirty. But code duplication looks dirty too, and so does inconsistency of doing switch/case for one, and call to adapter for the other method. Another possible downside of using adapter connection, is getLastGeneratedValue() does not share same syntax for SqlServer 2016 where its one command for IDENTITY column but a different one for SEQUENCE object/column. (not a problem for postgresql or oracle up to 12c because sequence is the only way to do it) Finally, how do I go about deducing implicit sequence names which too is a platform specific action? My getSequenceName() is awefully postgresql specific. I am not sure if decorator is possible to do for TableGateway features. |
oops, link to wrong branch. Corrected: https://github.com/zendframework/zend-db/pull/187/files#diff-85fe938f5a6f87443ad2578472eed9e0R166 |
@ezimuel while you are triaging issues, do you have a minute to give a hint about the last question, please? |
Closing this in favor of keeping TODO and discussion in one place at linked PR. |
SERIAL
pseudo-typeSERIAL
pseudo-type to column creation DDL to compliment idea of implicit sequence at DB creation/migrations level.Insert
andUpdate
statements to filter out or generate values based on the changesSequenceFeature
independent fromTableGateway
since (1) it does not necesseirly tie to a specific table, (2) fixRowGateway
limitationNo BC breaks.
Thought process history
While reviewing #172, helping with #162, and fresh out of a heavy database driven enterprise platform contract, noticed how deficient current sequence support is plus misleading function signatures. This is an important feature because, better than auto_increment in PostgreSQL, the only way to increment Oracle, and now Microsoft brought it in due to popular demand in SQL Server 2016 so I feel it needs detailed look.
Current situation is that:
What I have seen in the field:
Submitted PR #187 where I got around multiple features of same type problem. Intended usage would be (documented of course when settled one one)
Why not always let developers manually handle Sequence objects without attaching them to table gateway? In large schemas, relationships set by architect can be difficult to keep in mind and I caused horrible bugs not being aware of what sequence participates in what business logic transaction. Using tablegateway to group them together helps a lot.
Now undecided on how to deal with preInsert/postInsert and dependence on gateway, how would I optionally mark one of several sequences that is used in TableGateway as responsible for PK? How would lastInsertValue be managed for multiple autoincremented columns?
The text was updated successfully, but these errors were encountered: