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

Migration generation via cli #34

Merged
merged 57 commits into from
Feb 21, 2015
Merged

Migration generation via cli #34

merged 57 commits into from
Feb 21, 2015

Conversation

josegonzalez
Copy link
Member

This is my first pass at making migration baking a little easier to use.

  • Moved the existing bake behavior to a --snapshot option
  • Moved the template to migration.ctp to snapshot.ctp
  • Cleaned up the actual bake task a bit
  • Added a MigrationHelper class to handle data output for migration files

This PR handles the signed/unsigned bug, and adds support for more phinx-supported attributes.

TODO:

  • Update docs
  • Rails-style migration generation
  • Test bake output the same way that the core does
  • Add tests for the MigrationHelper class

protected function getMigrationName($name = null)
{
if (empty($name)) {
return $this->error('Choose a migration name to bake in underscore format');
Copy link
Member

Choose a reason for hiding this comment

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

Phenix uses a camel case format for migrations names in the command line, we should follow that decision

Copy link
Member Author

Choose a reason for hiding this comment

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

The name of the class is UpperCamelCase though.

@lorenzo
Copy link
Member

lorenzo commented Dec 7, 2014

I really like the direction this is going

@markstory markstory added this to the 1.0.0 milestone Dec 8, 2014
@@ -121,7 +121,7 @@ public function bake($filename)

$this->Template->set($data);

$out = $this->Template->generate('Migrations.config/migration');
$out = $this->Template->generate('Migrations.config/initial');
Copy link
Member

Choose a reason for hiding this comment

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

Migrations.config/snapshot instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I thought I fixed this...

@markstory
Copy link
Member

I too like the direction. Nice work @josegonzalez 👍

* @return void
*/
public function main($name = null)
public function main()
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove that? I thought the passed param here in 3.x is a little bit nicer than running through $this->args via array_shift, effectively modifying $this->args in the process.

Copy link
Member Author

Choose a reason for hiding this comment

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

If you specify arguments in the ConsoleOptionParser, you cannot use arbitrary args (which are necessary for rails-style migration generation).

Copy link
Member

Choose a reason for hiding this comment

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

I see, but then $this->args[0] would still be better IMO to not modify the args.

Copy link
Member Author

Choose a reason for hiding this comment

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

Feel free to update the PR 💃

$validTypes = array_values($collection->filter(function ($_, $constant) {
$_;
return substr($constant, 0, strlen('PHINX_TYPE_')) === 'PHINX_TYPE_';
})->toArray());
Copy link
Member

Choose a reason for hiding this comment

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

toArray(false) Will do save you the call to array_values()

@josegonzalez
Copy link
Member Author

I'm having a bit of troubling getting fixtures to run. I'm going to push my current code in the hopes that someone can figure out why fixtures aren't being inserted into the db...

@jadb jadb self-assigned this Jan 29, 2015
@jadb
Copy link
Contributor

jadb commented Jan 29, 2015

@josegonzalez I'll try it some time today or tomorrow and share what I find.

@josegonzalez
Copy link
Member Author

I ended up splitting out the snapshot generation and generation from the cli into two different tasks. I might still consolidate them to keep the interface the same, but I like how it came out :)

- php: hhvm-nightly
- env: DB=pgsql db_dsn='postgres://postgres@127.0.0.1/cakephp_test'
Copy link
Member

Choose a reason for hiding this comment

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

why?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why what?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, thats related to a bug in the schema generation in CakePHP. See this commit for more details.

@lorenzo
Copy link
Member

lorenzo commented Feb 19, 2015

This looks great! 👍

'limit' => 11,
],
],
], $this->columnParser->parseFields(['id:primary']));
Copy link
Member

Choose a reason for hiding this comment

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

Some troll is going to want : in their column names.

Copy link
Member Author

Choose a reason for hiding this comment

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

That troll can write his own migrations sans the cli-based generator.

Copy link
Contributor

Choose a reason for hiding this comment

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

💯

@markstory
Copy link
Member

Looks great 👍

markstory added a commit that referenced this pull request Feb 21, 2015
@markstory markstory merged commit b4f5a77 into master Feb 21, 2015
@markstory markstory deleted the migration-generation branch February 21, 2015 00:47
@josegonzalez josegonzalez changed the title Migration generation Migration generation via cli Nov 14, 2016
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.

None yet

6 participants