cakephp / phinx

PHP Database Migrations for Everyone
https://phinx.org
MIT License
4.46k stars 890 forks source link

Move migrations under the Phinx\Migration namespace #168

Open robmorgan opened 10 years ago

robmorgan commented 10 years ago

In order to stop polluting the global namespace we will move migration classes under the Phinx\Migration namespace. This also conforms to PSR-2.

robmorgan commented 10 years ago

Need to do a much better job of this.

Tasks

ferodss commented 10 years ago

Maybe in 1.0 tag?! We broken compatibility in 1.0 release, no need much code to still work....

robmorgan commented 10 years ago

@felipedjinn yes I think it will need to wait until 1.0 or 1.5. will break too much BC.

cyrusboadway commented 10 years ago

@robmorgan In my mind, the ideal would allow arbitrary namespaces, either specified in the config and imported into the default template, or defined on a migration-by-migration basis, so that we can arrange the migrations in whichever directory/namespace structure makes sense for our application.

evought commented 9 years ago

If you go as @cyrusboadway suggests and allow a namespace to be specified in the config, then that will allow each project to put the migrations in their own vendor namespace and still preserve existing projects using the global namespace. New projects could default to Phinx\Migration . It would then become a backwards-compatible change.

Basically:

t1gor commented 9 years ago

That's exactly what I'm looking for. Any update on the issue?

arogachev commented 8 years ago

I switched to Phinx from native framework migrations (I'm using Yii2) just to give it a try and see it in action. But this is for now is one of the biggest disadvantages for me. Any update on this?

I want namespace to be console\migrations\phinx. Maybe some workarounds exist? If I try to specify namespace, during migrate / rollback "No class found" expection is thrown.

rquadling commented 8 years ago

Some random thoughts.

The namespace will have to be added as a PSR-4 surely?

'Phinx\\Migration' => '%%PHINX_CONFIG_DIR%%/migrations'

The namespace will also need to be injected into the template so that custom templates and custom template generators will have the option of using the default namespace or not.

wandersonwhcr commented 8 years ago

@rquadling +1

josegonzalez commented 8 years ago

Would be great to do the same for Seeds :)

garex commented 8 years ago

Also namespaces should be different per path.

Currently we have single path and it's possible to use single namespace per this path in future.

But if we will use glob in path then we force to use same namespace everywhere.

May be implement class loading in another way? Let it parse migration and use class name from parsed file. I think https://github.com/nikic/PHP-Parser will do the job easily. And it will not be backward breaker.

glensc commented 7 years ago

https://github.com/robmorgan/phinx/issues/168#issuecomment-69807486 makes most sense, https://github.com/robmorgan/phinx/issues/168#issuecomment-242325250 the parser solution is way overkill, it's like using tank to kill a fly.

dereuromark commented 7 years ago

Is this ticket still valid? What is the plan of attack?

dereuromark commented 6 years ago

Looks like this has been done.

glensc commented 6 years ago

@dereuromark to me it seems it was commited and then reverted:

so what exactly is done? please point to pull-request or commit.

chrisharrison commented 6 years ago

@rquadling It's a PSR-2 issue because a PHP file without a namespace is not PSR-2 compliant. My deployment script checks my codebase for conformance to PSR-2. The migrations are currently breaking that.

dereuromark commented 6 years ago

Maybe we should allow for project namespaces here A project Foo could have Foo\Migration... per class then at least.

dereuromark commented 6 years ago

For proper psr2 we also need to make the class names match the filenames.

// file M20170112080706OptionalSuffix.php
class M20170112080706OptionalSuffix ...

instead of

// file 20170112080706_optional_suffix.php
class OptionalSuffix ...
EvilBMP commented 6 years ago

Please allow custom namespaces like Vendor\Migrations and use class names like in doctrine migrations: class Version20180202110355 extends AbstractMigration with the corresponding filename Version20180202110355.php

Everything should be fine then. Even a migration suffix should be possible then - like @dereuromark suggested.

dereuromark commented 4 years ago

We should check this for next major - 0.13 release.