Updated: Comment #0

Problem/Motivation

Fields can specify indexes and foreign keys in their schema, but not unique keys. Specifically UUID fields should specify a unique key for their column.

Proposed resolution

Allow fields to specify unique keys.

Remaining tasks

User interface changes

-

API changes

Comments

tstoeckler’s picture

Status: Active » Needs review
StatusFileSize
new4.76 KB

Here we go. Let's see how badly this breaks.

Status: Needs review » Needs work

The last submitted patch, 1: 2209049-1-field-unique-keys.patch, failed testing.

The last submitted patch, 1: 2209049-1-field-unique-keys.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
StatusFileSize
new617 bytes
new5.36 KB

Nice, that looks solvable...

tstoeckler’s picture

tstoeckler’s picture

Status: Needs review » Needs work

The last submitted patch, 4: 2209049-4-field-unique-keys.patch, failed testing.

tstoeckler’s picture

No merge conflict, so must have been a context change.

tstoeckler’s picture

Status: Needs review » Needs work

The last submitted patch, 8: 2209049-8-field-schema-unique-keys.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new5.08 KB

Status: Needs review » Needs work

The last submitted patch, 11: 2209049-11.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new5.08 KB

Status: Needs review » Needs work

The last submitted patch, 13: 2209049-13.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new5.09 KB
lokapujya’s picture

StatusFileSize
new931 bytes

interdiff from last patch.

tstoeckler’s picture

Awesome @lokapujya, thanks a lot!

Anyone want to RTBC?

blueminds’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php
@@ -1207,6 +1207,14 @@ public static function _fieldSqlSchema(FieldConfigInterface $field, array $schem
+    foreach ($schema['unique keys'] as $unique_keý_name => $columns) {

$unique_key_name has accent mark on the "y" letter.

Otherwise looks fine.

tstoeckler’s picture

Status: Needs work » Needs review
StatusFileSize
new876 bytes
new11.91 KB
new16.12 KB

Wow @blueminds, nice catch!

Now that #2183231: Make ContentEntityDatabaseStorage generate static database schemas for content entities is in, we can also remove the hardcoded adding of the UUID unique key from ContentEntitySchemaHandler. Also added test coverage for field unique keys now, completing the test coverage of ContentEntitySchemaHandler.

That revealed a small bug of sorts where defaults weren't applied correctly to the table schema.

Status: Needs review » Needs work

The last submitted patch, 19: 2209049-19-field-schema-unique-keys.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
StatusFileSize
new1.36 KB
new17.14 KB

Let's see if this is green.

blueminds’s picture

Status: Needs review » Reviewed & tested by the community

Went through the code, applied, tested, works, looks good.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed c63692f and pushed to 8.x. Thanks!

  • Commit c63692f on 8.x by alexpott:
    Issue #2209049 by tstoeckler, lokapujya: Allow field schemas to contain...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.