Problem/Motivation

Split from #2232465: Deprecate table names from entity definitions

We want to move towards making the actual table names an (internal) implementation detail. It should not be required to specify them on the entity type, the only thing that is required is defining if it should be revisionable and/or translatable.

Proposed resolution

In ContentEntityType, set default values if they are not already set. Remove it from all test entity types as a start to make sure it works.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Berdir created an issue. See original summary.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new83.61 KB
new6.32 KB

Fixed test fails and removed a few more tables.

Did not yet remove any non-test entity types or entity types from entity_test_revlog as I'm not quite sure how this is affects updates.

berdir’s picture

StatusFileSize
new67.76 KB

Messed up and mixed this with a datetime patch, hopefully removed all unrelated changes.

+++ b/core/modules/content_translation/tests/modules/content_translation_test/src/Entity/EntityTestTranslatableUISkip.php
@@ -8,10 +8,8 @@
  * @ContentEntityType(
- *   id = "entity_test_translatable_UI_skip",
+ *   id = "entity_test_translatable_ui_skip",
  *   label = @Translation("Test entity - Translatable skip UI check"),
- *   base_table = "entity_test_mul",
- *   data_table = "entity_test_mul_property_data",
  *   entity_keys = {
  *     "id" = "id",

+++ b/core/modules/path/tests/src/Kernel/PathNoCanonicalLinkTest.php
@@ -25,6 +25,7 @@ protected function setUp() {
 
     $this->installEntitySchema('entity_test');
     $this->installEntitySchema('entity_test_mul');
+    $this->installEntitySchema('entity_test_translatable_ui_skip');

This was a good one.

Those test entity types didn't have unique entity tables before and we still silently skip already existing tables when installing entity types, so the test here worked even though it didn't create the entity schema for that entity type.

amateescu’s picture

I'm aiming for the nitpick of the month award, so..

+++ b/core/lib/Drupal/Core/Entity/ContentEntityType.php
@@ -54,6 +54,21 @@ public function __construct($definition) {
+    }
+
   }

Extra empty line here :)

Also, I would add a @todo that points to #2232465: Deprecate table names from entity definitions because the default table names will most likely be generated by the default table mapping, not by ContentEntityType.

chanderbhushan’s picture

StatusFileSize
new7.38 KB

Hi, tested #3 patch is working fine. thanks

berdir’s picture

Status: Needs review » Needs work

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Status: Needs work » Needs review
Issue tags: +Needs change record
StatusFileSize
new1.1 KB
new66.7 KB

Reroll & removed table name generation cos table mapping already does the same

Status: Needs review » Needs work

The last submitted patch, 8: 2958963-8.patch, failed testing. View results

andypost’s picture

Status: Needs work » Needs review

@amateescu Does #4 means that $entityType->getBaseTable() should proxy call to table mapping?

berdir’s picture

As you can see with the amount of fails you get, we can't remove this yet., I don't think we can proxy to the table mapping, as that's a) storage specific and b) would most likely result in a recursion.

I discussed this with @amateescu a while ago but don't sure if I remember correctly, but IMHO doing this would b a step forward towards consistent table names (those test entity types are really bad examples right now). Then we'll have to move those method calls to the table mapping, deprecate them on the entity type and eventually remove.

hchonov’s picture

Re#3:
I like that, a lot!

Those test entity types didn't have unique entity tables before and we still silently skip already existing tables when installing entity types, so the test here worked even though it didn't create the entity schema for that entity type.

For this we still need a dedicated issue, right?

Status: Needs review » Needs work

The last submitted patch, 8: 2958963-8.patch, failed testing. View results

tstoeckler’s picture

I think we should proceed with #3 as a step forward. It both allows to clean up some lines in the test modules, fixes a bug in the entity test classes and more importantly allows contrib to remove some more boilerplate from their entity types which is always nice. Consolidating this code with the respective one in the table mapping is then only internal cleanup which is transparent to contrib.

Re #12: Since it's only a problem in test modules and not a functional bug for any actual Drupal site out there, I think it is fine to fix this bug as part of this task. I see it as validation that the patch works as intended. Speaking of validation I was wondering whether we need unit test coverage of this, but we currently don't have a unit test for ContentEntityType and it's arguable whether there should be one because it's mostly just a value-object (but for little niceties like the one introduced here), so I think we're good. By removing the annotation entries from the various test entities we already have ample functional test coverage.

I have one remaining question and one tiny nitpick when looking at #3.

  1. +++ b/core/lib/Drupal/Core/Entity/ContentEntityType.php
    @@ -54,6 +54,21 @@ public function __construct($definition) {
    +      $this->revision_table = $this->id() . '_revision';
    ...
    +      $this->data_table = $this->id() . '_field_data';
    ...
    +      $this->revision_data_table = $this->id() . '_revision_data';
    

    It has always bothered me that we - when we initially introduced those defaults in the storage (which are now in the table mapping) that we fall back to the entity type ID as the prefix instead of the base table. If you don't specify any tables it ends up being the same, but it would be nice if - if you were unhappy with the entity type ID as the base table name - could specify an alternate base table and all the other table names would follow suit and use the same prefix. Right now this leads to a very confusing table list. We have a similar issue with dedicated field tables, which always use the entity type ID as the prefix, and which is why I became aware of this issue because that latter point leads to the annoying prefix difference in the user entity tables. Because the user entity uses "users" instead of "user" as a prefix (because USER is a reserved word in MySQL) we have a "users_field_data" table but a user__roles table even though they both belong to the same entity type.

    The question is whether this would somehow affect backwards-compatibility in which case it would make sense to just live with the way it currently is, but I'm not sure, because this is entirely new code at least in this class, so I thought I'd bring it up.

  2. +++ b/core/lib/Drupal/Core/Entity/ContentEntityType.php
    @@ -54,6 +54,21 @@ public function __construct($definition) {
    +
    

    Unnecessary newline

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.