-
Notifications
You must be signed in to change notification settings - Fork 121
Add seed tracking. #939
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
base: 5.x
Are you sure you want to change the base?
Add seed tracking. #939
Conversation
|
The error will go away with release of bugfix cakephp/cakephp#19032 //EDIT: I merged it from 5.x to 5.next - should already work. |
|
Additionally now seeds can be idempotent, making them untracked. |
Co-authored-by: Kevin Pfeifer <[email protected]>
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.
Pull Request Overview
This PR implements seed execution tracking for CakePHP's Migrations plugin. Seeds now track their execution state in a cake_seeds database table, preventing them from running multiple times by default unless the --force flag is used or they are marked as idempotent.
Key Changes:
- Added seed execution state tracking with a new
cake_seedsdatabase table - Introduced idempotent seed support via
isIdempotent()method - Renamed command from
migrations seedtoseeds runand added new commands:seeds statusandseeds reset
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/TestCase/MigrationsTest.php | Added setup to truncate cake_seeds table and updated tests to use force flag |
| tests/TestCase/Command/SeedCommandTest.php | Updated all tests to use new seeds run command and added tests for state tracking, status, and reset features |
| tests/TestCase/Command/CompletionTest.php | Removed seed from migrations subcommands as it moved to seeds namespace |
| src/SeedInterface.php | Added isIdempotent() interface method |
| src/MigrationsPlugin.php | Reorganized command registration to separate migration and seed commands |
| src/Migration/Manager.php | Added methods for checking seed execution state and managing dependencies |
| src/Migration/Environment.php | Added seed execution recording after seed runs |
| src/Migration/BuiltinBackend.php | Added force parameter support |
| src/Db/Adapter/AdapterWrapper.php | Added wrapper methods for seed schema table operations |
| src/Db/Adapter/AdapterInterface.php | Added interface methods for seed tracking |
| src/Db/Adapter/AbstractAdapter.php | Implemented seed logging and schema table creation |
| src/Command/SeedsEntryCommand.php | New entry point command for seeds namespace |
| src/Command/SeedStatusCommand.php | New command to show seed execution status |
| src/Command/SeedResetCommand.php | New command to reset seed execution logs |
| src/Command/SeedCommand.php | Updated to use new command name and added --force flag |
| src/BaseSeed.php | Implemented default isIdempotent() returning false |
| docs/en/seeding.rst | Updated documentation for new tracking behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@dereuromark I've opened a new pull request, #945, to work on those changes. Once the pull request is ready, I'll request review from you. |
| public function isIdempotent(): bool | ||
| { | ||
| return true; | ||
| } |
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.
What happens if a non-idempotent seed is run with the 'old' command? It seems like the result would be incorrect behavior.
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.
what old command? you mean migrations v4?
this is a new major, so any of this functionality is only available v5+.
PS: Thats already the case anway right now, it blindly runs everything all the time.
| public static function defaultName(): string | ||
| { | ||
| return 'migrations seed'; | ||
| return 'seeds run'; |
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.
What about the old command? How does that continue working?
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.
They dont
It is simple enough to clarify in a migration guide that the API changed.
It is also simple enough IMO to understand. Those are simple commands that people can overwrite locally if they want to retain the old commands.
Thats why we do a major, to improve and clean up the API, that really does need some overhaul, after like 2 decades.
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.
I added a migration guide and a guide on how to easily restore the old way if needed.
| * @param string $seedSchemaTableName Seed Schema Table Name | ||
| * @return $this | ||
| */ | ||
| public function setSeedSchemaTableName(string $seedSchemaTableName) |
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.
How do users interact with this? There doesn't seem to be any way to call this, and if there isn't why does it exist?
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.
Isnt it via options?
public function setOptions(array $options): AdapterInterface
{
$this->options = $options;
if (isset($options['migration_table'])) {
$this->setSchemaTableName($options['migration_table']);
}
if (isset($options['seed_table'])) {
$this->setSeedSchemaTableName($options['seed_table']);
}
if (isset($options['connection']) && $options['connection'] instanceof Connection) {
$this->setConnection($options['connection']);
}
return $this;
}
Completing #935 I want to introduce seed logs.
This makes seeds a bit more useful in everyday dev life:
Proposed API: seeds on its on high level, as this is not necessarily directly linked to migrations, but more to (demo) data.
Details:
seeds status
seeds reset
How It Works
seeds statusshows execution stateseeds resetSeedName removes from log, allowing re-execution without --force