diff --git a/CHANGELOG.md b/CHANGELOG.md index 127deca..2e7b8ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## 0.1.1 - 2026-09-17 + +### Changed + +- With `key_type` set to `uuid`, both package tables now receive time ordered UUID v7 keys instead of random UUID v4 keys. Existing keys stay valid, the column type does not change. + ## 0.1.0 - 2026-09-08 First public release. diff --git a/README.md b/README.md index 01b5fb9..fa1e99a 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ The package ships English and Italian validation messages under the | --- | --- | --- | | `tables.fields` | `custom_fields` | Table holding the field definitions. | | `tables.values` | `custom_field_values` | Table holding one row per field per record. | -| `key_type` | `id` | Primary key type of both package tables. Accepts `id`, `uuid`, `ulid`. Must be chosen before migrating. | +| `key_type` | `id` | Primary key type of both package tables. Accepts `id`, `uuid`, `ulid`. `uuid` generates UUID v7. Must be chosen before migrating. | | `morph_key_type` | `id` | Key type of the models that own custom fields, used for the `valuable_id` column. Accepts `id`, `uuid`, `ulid`. Must be chosen before migrating. | | `models.custom_field` | `PlinCode\CustomFields\Models\CustomField` | The definition model. Point it at your own subclass to add relations, casts, a global scope or a dedicated connection. | | `models.custom_field_value` | `PlinCode\CustomFields\Models\CustomFieldValue` | The value model. Same rule. | diff --git a/src/Models/CustomField.php b/src/Models/CustomField.php index 2bdfcc3..97f9234 100644 --- a/src/Models/CustomField.php +++ b/src/Models/CustomField.php @@ -44,7 +44,7 @@ protected static function booted(): void $field->setAttribute($field->getKeyName(), config('laravel-custom-fields.key_type') === 'ulid' ? (string) Str::ulid() - : (string) Str::uuid()); + : (string) Str::uuid7()); }); } diff --git a/src/Models/CustomFieldValue.php b/src/Models/CustomFieldValue.php index 9c2c8d3..260aca2 100644 --- a/src/Models/CustomFieldValue.php +++ b/src/Models/CustomFieldValue.php @@ -38,7 +38,7 @@ protected static function booted(): void $value->setAttribute($value->getKeyName(), config('laravel-custom-fields.key_type') === 'ulid' ? (string) Str::ulid() - : (string) Str::uuid()); + : (string) Str::uuid7()); }); } diff --git a/tests/Feature/KeyTypeTest.php b/tests/Feature/KeyTypeTest.php index 66e36a8..90eed94 100644 --- a/tests/Feature/KeyTypeTest.php +++ b/tests/Feature/KeyTypeTest.php @@ -70,6 +70,8 @@ function columnTypesOf(string $kind): array ->and(columnType('custom_field_values', 'valuable_id'))->toBeIn(columnTypesOf('uuid')) ->and(Str::isUuid((string) $field->getKey()))->toBeTrue() ->and(Str::isUuid((string) $row?->getKey()))->toBeTrue() + ->and(substr((string) $field->getKey(), 14, 1))->toBe('7') + ->and(substr((string) $row?->getKey(), 14, 1))->toBe('7') ->and($row?->getAttribute('valuable_id'))->toBe($document->getKey()) ->and($document->getCustomField('rank'))->toBe(7); });