Conversation
64d0b97 to
8ca55a4
Compare
8ca55a4 to
907b503
Compare
Do you mean that |
No, I mean that "set", "add" and "drop" methods/verbs express different semantics. Let's say your application has some logic that builds or doesn't build the primary key definition, so this value is nullable. When you build a table from this definition, you can use this value as is. This method doesn't validate the current state of the table (i.e. whether the PK already exists or not), it just sets the PK definition to the new value. If you're altering an existing table, you will use "add" (similar to |
Currently, the API of
TableEditoris quite rudimentary and is primarily aimed at replacing theTableconstructor. This PR introduces the methods for actually editing tables.Object Collections
Unlike all other objects for which we have feature-complete editors,
Tableis the only one that internally containscollections of other objects (columns, indexes, and so on). To manage them efficiently, I'm introducing an internal
Schema\Collectionsnamespace with the following classes and interfaces:ObjectSet– a common interface for the following two classes.NamedObjectSet– will be used for representing table columns and indexes.OptionallyNamedObjectSet– will be used for representing table unique and foreign key constraints.Currently, the key of an element in the above sets is derived from the lower-case element name. Therefore, these collections, for example, cannot represent a pair of columns
idandID. This limitation is temporary and mimics the current logic of theTableclass. Later, it will be possible to parameterize a collection with one or moreUnquotedIdentifierFoldings, and the current case-insensitive behavior will be deprecated.Editor Operations
Column operations:
Index operations:
Constraint operations:
Other operations:
API design considerations
setColumns()), and there are also methods for adding or removing elements (e.g.addColumn()anddropColumn()).The first one is handy when creating new tables (e.g. during schema introspection or in unit tests), the other two
are good for editing an existing table.
setPrimaryKeyConstraint(?PrimaryKeyConstraint $primaryKeyConstraint)method, I'm addingaddPrimaryKeyConstraint(PrimaryKeyConstraint $primaryKeyConstraint)anddropPrimaryKeyConstraint(). They share the same implementation but express different intents.modifyColumn(UnqualifiedName $columnName)) is accompanied by a method with the "ByUnquotedName" suffix that accepts the name as string (e.g.modifyColumnByUnquotedName(string $columnName)). Currently, there are no "ByQuotedName" methods, because the collections do not respect the semantics of quoted identifiers, so their behavior would be identical to the one of the "ByUnquotedName" methods. We will introduce these methods once we add the support forUnquotedIdentifierFoldings to the collections.Next steps
TableEditorand its new methods. BesidesTableEditorTest, the editor will be covered by the existing tests.Column::$_platformOptions.