Skip to content

Replaced name generator for versioning for revisions - #24

Merged
thijskok merged 3 commits into
mainfrom
replaced-version-name-generator
Jul 16, 2026
Merged

Replaced name generator for versioning for revisions#24
thijskok merged 3 commits into
mainfrom
replaced-version-name-generator

Conversation

@thijskok

Copy link
Copy Markdown
Contributor

No description provided.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 version column to revisions and assigns it during revision creation.
  • Removes the name-generator API (contract, factory, generator, config, and related tests) so name is 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.

Comment thread src/Revisioner.php
Comment on lines +210 to 213
protected function resolveVersion(): int
{
if ($this->name !== null) {
return $this->name;
}

return $this->nameGenerator?->generate($this->model);
return $this->model->revisions()->count() + 1;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 15 to 18
$table->morphs('revisionable');
$table->string('name')->nullable();
$table->unsignedInteger('version');
$table->json('metadata')->nullable();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 90 to 93
$table->morphs('revisionable');
$table->string('name')->nullable();
$table->unsignedInteger('version');
$table->json('metadata')->nullable();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread README.md
Comment on lines +292 to 295
#### 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:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No release yet, so no worries there.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.

Comment thread tests/RevisionVersioningTest.php Outdated
Comment thread tests/RevisionVersioningTest.php Outdated
Comment thread tests/RevisionVersioningTest.php Outdated
Comment thread src/Revisioner.php
Comment on lines 110 to 114
$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);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 as max(version) + 1 inside 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 make version reliably 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;
        });

@thijskok
thijskok requested review from Frankisgek and stefanius July 16, 2026 15:07
@thijskok
thijskok merged commit e8355ed into main Jul 16, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants