-
Notifications
You must be signed in to change notification settings - Fork 892
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
Supporting namespaces in configuration, Migrations and Seeds. #1070
Conversation
I don't agree with namespaced migrations as this prevents me to have them in different modules. |
@mvrhov, current solution doesn't prevent you use migrations in different modules. Example: return [
'paths' => [
'migrations' => [
'./module_first/migrations',
'./module_second/migrations',
// etc
'./module_other/migrations',
],
'seeds' => [
// ...
]
],
]; If you need Namespace you can add an item with string key to configuration. Example: return [
'paths' => [
'migrations' => [
'./module_first/migrations',
'./module_second/migrations',
// etc
'./module_other/migrations',
'Foo\Bar' => './module_new/migrations',
],
'seeds' => [
// ...
]
],
]; Will work both new and old (without namespace) migrations. |
Oh. Sorry. I've not reviewed the code. I've just read the PR description. If the old way works then I have no objections. |
src/Phinx/Console/Command/Create.php
Outdated
'$className' => $className, | ||
'$version' => Util::getVersionFromFileName($fileName), | ||
'$baseClassName' => $this->getConfig()->getMigrationBaseClassName(true), | ||
'$defineNamespace' => null !== $namespace ? ('namespace ' . $namespace . ';') : '', |
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.
Supply $namespace
separate to $defineNamespace
please.
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'm not sure I understand your proposals.
$namespace variable can contain string like Foo\Bar
$defineNamespace is a result of concatenation: namespace Foo\Bar;
When namespace for path is defined in configuration, then result string injected in template (see ./src/Phinx/Migration/Migration.template.php.dist, ./src/Phinx/Seed/Seed.template.php.dist).
If namespace for path not found, then namespace definition in template is absent ($defineNamespace var is empty).
Please clarify your sentence.
Do you mean to create separate template for migrations with namespace? I suppose it would be more convenient to leave a single template.
Or maybe you suggest rename $defineNamespace var to $namespaceDefinition?
'$useClassName' => 'Phinx\Seed\AbstractSeed', | ||
'$className' => $className, | ||
'$baseClassName' => 'AbstractSeed', | ||
'$defineNamespace' => null !== $namespace ? ('namespace ' . $namespace . ';') : '', |
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.
Supply $namespace
separate to $defineNamespace
please.
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.
Simply add '$namespace' => $namespace,
Basically, I would need to see JUST the namespace in my template. This is independent to the $defineNamespace
value.
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.
And $namespaceDefinition
is a nicer name, so $namespace
and $namespaceDefinition
. I'd have use for both of these in my templates.
Renamed |
@rquadling Do you think, i can add $namespaceBackslash? |
What use case? |
hm, i refuse the idea (namespaceBackslash) |
Hello! Could you please give a cue about this PR. In case of any doubts, I will be happy to offer any assistance. |
Just need to review it and play with it a bit. |
@rquadling Any news on whether or not this is a suitable implementation? It looks solid and good to me. |
@JapSeyz it only needs docs. Would you like to contribute them? |
@lorenzo Yeah sure, I'll take a look at it next weekend when I have some time. Where should I put the PR? Also, in which regard do you need documentation? It seems fairly straight forward to tell the user that namespaces required/enabled? or are you asking for in-depth documentation on how it resolves the path when it's namespaced? |
This looks like it requires configuration in the yaml file. That should be explained, with an example of a namespaced migration file. You can open a pull request to the docs folder in this repository. thanks for the help! |
It has to work with existing migrations that won't be namespaced. If you want to start using namespaces, what's the consequences for existing migrations? Having some documentation for migrating the migrations (that's a bit self referential!) would be useful. That could be in a suitable UPGRADE file. This is assuming that namespaced and non-namespaced migrations cannot be used simultaneously. |
@rquadling Alright, I'll check it out. I'll do a bit of testing and write down my findings a long with documentation for how to use the namespaced migrations. |
@rquadling would you happen to know anything about the below issue? Is it actually an issue, because it discourages the use of namespaced and non-namespaced migrations in the same project. It doesn't seem as if it is possible to have the same classname in different namespaces because Edit: I have not tested this theory, it's just a discovery I made while looking through the commits. |
@lorenzo I have created a draft here: https://github.com/JapSeyz/phinx/blob/master/docs/namespaces.rst In truth, it's a very easy thing to switch to namespaces. The above comment does however highlight a potential trap for users who want's to use namespaced and non-namespaced migrations/seeders in the same project. This has been written into the documentation though. I have not yet tested this, but I presume you shouldn't escape the backslash in the console command? |
Creating migration with command In case if configuration file defines several paths to directories where migrations stored, e.g.: paths:
migrations:
0: ./db/migrations
Foo\Bar: ./db/FooBar command Calling |
@JapSeyz I think the document is good, but misses some examples. When you define the paths for migrations, can you show an example of a file with its path that would be resolved by each of the configuration entries? |
@andrey-mokhov Perfect. The namespace thing did bother me. I'll reflect this in the documentation. @lorenzo I'll add some more examples. |
I have added more examples and reflected the --path flag. Let me know if it's acceptable, as I've found it really difficult to give examples of the path resolving as it's basically just saying what the different parts of the string mean. |
@JapSeyz It looks great! I'll be merging this soon |
@lorenzo Sounds great! I've created a PR for the documentation so it's simply to merge it. Thanks for the quick responses |
Thanks! |
Is this going any further seen as the docs were merged? I really need this as I have a lot of Seeds for different testing scenarios, and namespaces would organise them somewhat. |
Please consider my pull request, in which I made some enhancement.
The pull request fixes following issues:
I implemented an idea of @rquadling (view comment).
So, support of namespaces looks like this:
php like:
yaml like:
json like:
Migrations/Seeds contain namespace just at the beginning of the file.
Migrations/Seeds files without namespace are still working for backward compatibility.
For using namespaces in migrations/seeds make new folders and change configuration.
The solution doesn't fully compatible with PSR-4 (there are versions in file names).
I tryed to covered the code with the unit's tests as full as possible.