Skip to content
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

Merged
merged 1 commit into from Jan 10, 2016

Conversation

HavokInspiration
Copy link
Member

This gives the ability to run seed from a non-shell context, using the Migrations\Migrations class.

Follow up to #179 and #181

This gives the ability to run seed from a non-shell context, using the Migrations\Migrations class.
@@ -18,7 +18,6 @@ public function run()
{
$data = [
[
'id' => '1',
Copy link
Member

Choose a reason for hiding this comment

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

Can we not include primary keys in seed data?

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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...

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

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

We can. Tests pass without problems with the change.
How it will behave is tied to the schema of your database : it will be no problem if you have this column defined as autoincrement (which is the case here).
All examples of seed in phinx doc doesn't include a value for the PK fields (well, I suppose there is a PK since there's no schema provided)

Copy link
Member Author

Choose a reason for hiding this comment

The 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).

Copy link
Member

Choose a reason for hiding this comment

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

How do we build relational fixtures then?

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically, you can do it.
The tests from PR #181 passed with the PK hard-coded for all db drivers (however, we do not test against SQLServer).
But according to @lorenzo, you are probably going to need some special code depending on the db driver you are using.
Apparently for Postgres, you will have to manually update the sequence index to the next value - something postgres does automatically if you do not provide a value for a PK sequence in an INSERT.

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.
For instance, I did not even know about this limitation for SQL Server and Postgres. From my experience, it does not cause any trouble with MySQL, so I thought it would not with the others...

@lorenzo
Copy link
Member

lorenzo commented Jan 10, 2016

good job again @HavokInspiration :)

lorenzo added a commit that referenced this pull request Jan 10, 2016
Update the Migrations class to support the seeding feature
@lorenzo lorenzo merged commit dc814e3 into master Jan 10, 2016
@lorenzo lorenzo deleted the migrations-class-seed branch January 10, 2016 19:08
@lorenzo
Copy link
Member

lorenzo commented Jan 10, 2016

@HavokInspiration Are we ready to tag a new release?

* Sets the command
*
* @param string $command Command name to store.
* @return self
Copy link
Member

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.

@HavokInspiration
Copy link
Member Author

@lorenzo Yes, the seed feature is ready as far as I'm concerned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants