Replaced name generator for versioning for revisions - #24
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR replaces the prior “auto-generated revision name” mechanism with a dedicated, sequential integer version stored on each revision record, and removes the name generator contract/factory/config hooks accordingly.
Changes:
- Adds a
versioncolumn to revisions and assigns it during revision creation. - Removes the name-generator API (contract, factory, generator, config, and related tests) so
nameis now only caller-provided. - Updates documentation and tests to reflect version-based sequencing.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/RevisionVersioningTest.php | Adds coverage for sequential versioning, replace behavior, and rollback continuation. |
| tests/RevisionNamingTest.php | Updates naming tests to reflect “no auto-name by default” and manual naming behavior. |
| tests/Database/Migrations/0000_00_00_000000_create_testing_tables.php | Adds version column to the test revisions table. |
| tests/CreatingRevisionsTest.php | Updates direct DB inserts to include version. |
| tests/ConfigurationTest.php | Removes name-generator configuration tests. |
| src/Revisioner.php | Stops resolving names via generator; assigns version on build. |
| src/RevisableOptions.php | Removes name-generator option and factory initialization. |
| src/Models/Revision.php | Adds version to $fillable and $casts. |
| src/Generators/VersionNameGenerator.php | Removed (no longer used). |
| src/Generators/NameGeneratorFactory.php | Removed (no longer used). |
| src/Exceptions/InvalidConfiguration.php | Removes invalid-name-generator exception helper. |
| src/Contracts/NameGenerator.php | Removed (no longer used). |
| src/Concerns/HasRevisions.php | Removes wiring of options-based name generator into the revisioner. |
| README.md | Replaces “custom revision naming” docs with “version numbers”. |
| database/migrations/create_revisions_table.php.stub | Adds version column to published migration stub. |
| config/revisionable.php | Removes name_generator config option. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| protected function resolveVersion(): int | ||
| { | ||
| if ($this->name !== null) { | ||
| return $this->name; | ||
| } | ||
|
|
||
| return $this->nameGenerator?->generate($this->model); | ||
| return $this->model->revisions()->count() + 1; | ||
| } |
| $table->morphs('revisionable'); | ||
| $table->string('name')->nullable(); | ||
| $table->unsignedInteger('version'); | ||
| $table->json('metadata')->nullable(); |
| $table->morphs('revisionable'); | ||
| $table->string('name')->nullable(); | ||
| $table->unsignedInteger('version'); | ||
| $table->json('metadata')->nullable(); |
| #### Version numbers | ||
|
|
||
| The default `VersionNameGenerator` names revisions sequentially (v1, v2, …). You can provide your own generator by implementing the `NameGenerator` contract and registering it in the options: | ||
| Every revision automatically gets a sequential `version` number (1, 2, 3, …), scoped to its model instance. Unlike a generated name, the version is a plain integer, so it carries no language or formatting choices — prefix it with whatever translated string fits your application: | ||
|
|
There was a problem hiding this comment.
No release yet, so no worries there.
…unique constraints for revisions
| $revision->user_id = $this->userResolver->resolve(); | ||
| $revision->name = $this->resolveName(); | ||
| $revision->name = $this->name; | ||
| $revision->version = $this->resolveVersion(); | ||
| $revision->metadata = $this->buildData(); | ||
| $revision->changed = $this->buildChanges($revision); |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/Revisioner.php:134
resolveVersion()is computed asmax(version) + 1inside the transaction, but without any locking this is still vulnerable to concurrent saves on the same model: two transactions can read the same max and then one will fail on the unique constraint. If the intent is to makeversionreliably sequential, consider serializing per-model revision creation by taking a row lock on the revisionable model before computing the next version (SQLite will ignore the lock, MySQL/Postgres will enforce it).
public function save(): Revision
{
return DB::transaction(function () {
$revision = $this->build();
$revision->version = $this->resolveVersion();
$this->model->revisions()->save($revision);
$this->prune();
return $revision;
});
No description provided.