Follow-up to #2183231: Make ContentEntityDatabaseStorage generate static database schemas for content entities:
Problem/Motivation
Right, now both the SqlContentEntityStorage and the schema handler have to work together based on a known table mapping, what makes the line between both object blurry.
Proposed resolution
- Make the SqlContentEntityStorage table mapping agnostic and get the table mapping from the schema handler
- As suggested by yched in #2183231: Make ContentEntityDatabaseStorage generate static database schemas for content entities we could create multiple table mapping classes for the different table mapping cases also.
Remaining tasks
- Agree on the exact way forward and do it.
User interface changes
-
API changes
None, only some base classes change a little
| Comment | File | Size | Author |
|---|---|---|---|
| #53 | 2274017-52.patch | 13.99 KB | nikhil_110 |
| #37 | 2274017-37.patch | 38.17 KB | daffie |
| #37 | interdiff-2274017-35-37.txt | 2.7 KB | daffie |
| #37 | interdiff-2274017-27-37.txt | 15.49 KB | daffie |
Comments
Comment #1
fagoComment #2
yched commentedBasically, what differentiates an SQL storage strategy from another is entirely contained in the mapping layout (per field tables, per bundle tables...)
So having switchable mapping classes would allow alternate SQL storage strategies in contrib, while using the same EntityDatabaseStorageController.
Comment #3
yched commentedRelated : crossposting from #2079019-10: Make Views use SqlEntityStorageInterface
#2183231: Make ContentEntityDatabaseStorage generate static database schemas for content entities got in (yay!) and added TableMappingInterface. IMO this isssue here is where we refine what we want to do exactly with that concept, and adjust its APIs accordingly.
Comment #4
fagoagreed. I think I this should be postponed on #1498720: [meta] Make the entity storage system handle changes in the entity and field schema definitions now. It technically isn't, but that issue is going to the touch the same area quite a bit.
Comment #5
yched commentedIs this now a duplicate of #2326719: Move pseudo-private table mapping functions from ContentEntityDatabaseStorage to public API of DefaultTableMapping ?
Comment #6
plachNope, the other issue does not touch the storage class at all. The goal here is implementing the approach you suggested of moving the table mapping initialization logic that currently lives in
CEDB::getTableMapping()to the table mapping instantiation itself (or lazy initialize it, details tbd). This also aims to make CEDB table layout agnostic and make it rely only on the provided table mapping.Comment #7
plach#2183231: Make ContentEntityDatabaseStorage generate static database schemas for content entities landed long ago.
Comment #8
plachComment #9
andypostComment #10
mile23setEntityType()is deprecated for removal before 8.0.0, and references this issue.Comment #11
ianthomas_ukAt this point is doesn't look like this issue is going to make it into the RC, therefore we need to decide what to do with the deprecation. Should we postpone it until 9.x, or can we mark the function as @internal? In core, there are calls to it in Core/Entity/Sql
and the views module(edit: same name, different function), but no where else.setEntityType was introduced in #2337927: SqlContentEntityStorage::onFieldStorageDefinition(Create|Update|Delete)() is broken for base fields.
Edit: A couple of quotes from that issue:
"Adding deprecated functions to get the beta in kind of sucks." -- alexpott
"I agree that's not nice ... Since that method is not part of any public API, although being public, I think the problems implied by going this way are more theoretical than practical." -- plach
plach pointed out that while the method is public, it is not part of the interface.
Comment #12
plachI'd go with @internal: this is an area that will need a lot of clean-up during the D8 lifecycle and at the same time I think most people won't need to fiddle directly with.
Comment #13
effulgentsia commentedI don't know which parts make sense to mark @internal, but +1 to someone figuring that out and opening a new issue for that.
Comment #14
ianthomas_ukI've uploaded a patch to do that to #2565307: Document SqlContentEntityStorage::setEntityType as @internal instead of @deprecated
Comment #15
ianthomas_uk@effulgentsia: My aim at the moment is to close #2205673: [META] Remove all @deprecated functions marked "remove before 8.0" before RC1 and this is a blocker for that. If there's more functions you or someone else wants to add so you maintain the flexibility to resolve this issue then please do. I don't see any big problems with marking too many methods @internal - after RC1 it's much easier to remove an @internal tag than to add one.
Comment #18
amateescu commentedLet's give this a try.
I'm not sure about who should be responsible for generating the default table names and the authority for retrieving this information, I assume
TableMappingInterface? If so, we also need to addgetBaseTable()and friends to that interface.Comment #20
amateescu commentedFixing most of the failing tests means that we have to decide who's the primary source of information about the entity tables, either the storage handler or default table mapping class, so I'm going to hold on with any updates until we decide one way or the other.
Comment #21
tstoecklerPosted this on IRC after a cursory look at the patch, didn't actually do a line-by-line review:
Comment #23
daffie commentedReroll
Comment #25
daffie commentedNext try
Comment #27
daffie commentedAnd an other try
Comment #29
daffie commentedFixed some tests and some code cleanups.
Comment #31
daffie commentedSome code changes and fixed the test class Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.
Comment #32
daffie commentedSomehow some code changes where reverted.
Comment #35
daffie commentedLets see what the testbot thinks.
Comment #37
daffie commentedLets see what the testbot thinks.
Comment #39
amateescu commentedThanks @daffie for getting this patch to a state where it actually passes all the tests!
Sadly, I was too ambitious in my initial patch from #18 and tried to fix too many things at once.
If we want to finally put this issue to rest I think we need to work in smaller steps, so I opened a child issue with the first step: #2916018: Allow the table mapping to be initialized from outside the storage
Comment #41
amateescu commentedThat first step from #39 turned into a huge plan (#2960147: Finalize the entity storage) with the ultimate goal of being able to fix this issue.
Comment #50
smustgrave commentedNW for an updated issue summary.
And reroll for 10.x
Comment #52
nikhil_110 commentedRe-roll patch against 10.x
Comment #53
nikhil_110 commentedRe-roll patch against 10.x