-
Notifications
You must be signed in to change notification settings - Fork 1
Replaced name generator for versioning for revisions #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ return new class extends Migration | |
|
|
||
| $table->morphs('revisionable'); | ||
| $table->string('name')->nullable(); | ||
| $table->unsignedInteger('version'); | ||
| $table->json('metadata')->nullable(); | ||
|
Comment on lines
15
to
18
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
| $table->json('properties')->nullable(); | ||
| $table->json('changed')->nullable(); | ||
|
|
@@ -23,6 +24,8 @@ return new class extends Migration | |
| $table->foreign('user_id')->references('id')->on('users')->onDelete('set null')->onUpdate('cascade'); | ||
|
|
||
| $table->timestamps(); | ||
|
|
||
| $table->unique(['revisionable_type', 'revisionable_id', 'version']); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ | |
| use Illuminate\Support\Arr; | ||
| use Illuminate\Support\Facades\DB; | ||
| use Illuminate\Support\Traits\Conditionable; | ||
| use TestMonitor\Revisable\Contracts\NameGenerator; | ||
| use TestMonitor\Revisable\Contracts\Revision as RevisionContract; | ||
| use TestMonitor\Revisable\Enums\RevisionType; | ||
| use TestMonitor\Revisable\Models\Revision; | ||
|
|
@@ -34,8 +33,6 @@ class Revisioner | |
|
|
||
| protected ?array $exceptRestoringRelations = []; | ||
|
|
||
| protected ?NameGenerator $nameGenerator = null; | ||
|
|
||
| protected RevisionType $revisionType = RevisionType::Default; | ||
|
|
||
| public function __construct(protected UserResolver $userResolver) {} | ||
|
|
@@ -68,13 +65,6 @@ public function name(?string $name): static | |
| return $this; | ||
| } | ||
|
|
||
| public function nameUsing(?NameGenerator $generator): static | ||
| { | ||
| $this->nameGenerator = $generator; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function onlyFields(array $fields): static | ||
| { | ||
| $this->fields = $fields; | ||
|
|
@@ -118,7 +108,7 @@ public function build(): Revision | |
| $revision = new Revision; | ||
|
|
||
| $revision->user_id = $this->userResolver->resolve(); | ||
| $revision->name = $this->resolveName(); | ||
| $revision->name = $this->name; | ||
| $revision->metadata = $this->buildData(); | ||
| $revision->changed = $this->buildChanges($revision); | ||
|
Comment on lines
110
to
113
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
| $revision->properties = $this->properties ?: null; | ||
|
|
@@ -134,6 +124,7 @@ public function save(): Revision | |
| { | ||
| return DB::transaction(function () { | ||
| $revision = $this->build(); | ||
| $revision->version = $this->resolveVersion(); | ||
|
|
||
| $this->model->revisions()->save($revision); | ||
|
|
||
|
|
@@ -213,13 +204,13 @@ public function prune(): void | |
| } | ||
| } | ||
|
|
||
| protected function resolveName(): ?string | ||
| /** | ||
| * Resolve the sequential version number for the new revision. | ||
| * Uses the max version rather than the row count, so pruning never reuses a number. | ||
| */ | ||
| protected function resolveVersion(): int | ||
| { | ||
| if ($this->name !== null) { | ||
| return $this->name; | ||
| } | ||
|
|
||
| return $this->nameGenerator?->generate($this->model); | ||
| return ($this->model->revisions()->max('version') ?? 0) + 1; | ||
| } | ||
|
Comment on lines
+211
to
214
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
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.