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

get connection name in migration file #98

Closed
oskude opened this issue Aug 21, 2014 · 2 comments
Closed

get connection name in migration file #98

oskude opened this issue Aug 21, 2014 · 2 comments

Comments

@oskude
Copy link

oskude commented Aug 21, 2014

we have to use different databases for some entities, depending on some factors. and to not migrate some entities to some databases, we use the following (manually added) in the migration files:

$this->skipIf($this->connection->getDatabase() != "foobar");

but this is suboptiomal as that "foobar" is defined in parameters.yml, that the user is supposed to create (like on local devel system).

what would be nicer if we could do:

$this->skipIf($this->connection->getName() != "barfoo");

where "barfoo" is defined in config.yml, that user is not supposed to edit, like:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                dbname: "%database_name%"
                ...
            barfoo:
                dbname: "%database_name%_barfoo"
                ...

was not sure if i should report this to "dbal" or "migrations" repo, so i reported it to the closest from user perspective.

ps. or if there is an easier way to define "this entity should go only to these connections" or "this entity should never go to these connections", i would love to hear about that!

@stof
Copy link
Member

stof commented Aug 21, 2014

Well, as far as DBAL is concerned, connections don't need to have a name. the name is needed to be able to get the connection from a registry. It is not a property of the connection itself (just like the name of a variable containing the connection is not known by the connection).

This means that a Connection object will not give such way to identify itself, and so this bundle will not be able to rely on them to skip migrations

@giosh94mhz
Copy link

Maybe you can implement ContainerAwareInterface in your migrations as explained in the docs.

This way you can get the EntityManager by name (which is generally a "stable" name) and the get the associated connection.

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

No branches or pull requests

4 participants