-
Notifications
You must be signed in to change notification settings - Fork 113
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
Update the Migrations class to support the seeding feature #182
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
use Phinx\Seed\AbstractSeed; | ||
|
||
/** | ||
* NumbersSeed seed. | ||
*/ | ||
class AnotherNumbersSeed extends AbstractSeed | ||
{ | ||
/** | ||
* Run Method. | ||
* | ||
* Write your database seeder using this method. | ||
* | ||
* More information on writing seeders is available here: | ||
* http://docs.phinx.org/en/latest/seeding.html | ||
*/ | ||
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. return void 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. Yes. |
||
public function run() | ||
{ | ||
$data = [ | ||
[ | ||
'number' => '2', | ||
'radix' => '10' | ||
] | ||
]; | ||
|
||
$table = $this->table('numbers'); | ||
$table->insert($data)->save(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ public function run() | |
{ | ||
$data = [ | ||
[ | ||
'id' => '1', | ||
'number' => '5', | ||
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. Can we not include primary keys in seed data? 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. I think it is better to not manually add the primary key. SQL server, for example does not like that, whereas Postgres will not advance the sequence automatically 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. Wow really? Do you have documentation for those two cases? I think it might be important to note for users creating seed data. Note: I've not had that issue on mysql, but mysql is the php of databases so... 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. It is a documented feature of those databases. It is possible to workaround those cases, but it requires specific code and special configuration for each of the drivers 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. We can. Tests pass without problems with the change. 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. I made the change to test the "call the same seeder multiple times" case, because I realized that with the PK defined, the values were not added on top of each other (it did an update). 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. How do we build relational fixtures then? 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. Technically, you can do it. As @josegonzalez said, maybe it would be a good thing to add a paragraph in the README / doc about this as it might confuse users. |
||
'radix' => '10' | ||
] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ public function run() | |
{ | ||
$data = [ | ||
[ | ||
'id' => '1', | ||
'number' => '10', | ||
'radix' => '10' | ||
] | ||
|
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.
So far we have been using $this.
But I would favor if we migrated to
self
for CakePHP in the near future.