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

Ability to define a multi-schema search_path for PostgreSQL lost after changes in #8394 #8639

Closed
dcro opened this issue May 6, 2015 · 4 comments

Comments

@dcro
Copy link
Contributor

dcro commented May 6, 2015

Up until the changes from #8394 were made, it was possible to define a multi-schema search path when defining a database configuration (in database.php):

'connections' => [
    'db1' => [
        'driver'   => 'pgsql',
        /* ... */
        'schema'   => 'schema1,schema2,schema3',
    ]
],

This translated in the following query that was executed immediately after the connection was established:

SET search_path TO schema1,schema2,schema3;

After the changes in #8394, this now translates to the following SQL query:

SET search_path TO "schema1,schema2,schema3";

which basically breaks the previous functionality.

Is it possible to get multi-schema support back?

A couple of potential solutions that I see:

  • leave the current functionality unchanged, but allow the database config to include a list of SQL commands that would be executed immediately after the connection is established.
  • allow a comma separated list of schemas (or possibly an array of schema names) and escape each schema name individually for connection adapters that do support multiple schemas.
@GrahamCampbell
Copy link
Member

We're open to PRs.

@DrummerKH
Copy link

Hi, may we know about status of this issue please?

@elynnaie
Copy link

@dcro @DrummerKH

Since it doesn't seem like this will get official support, I came up with a fairly simple workaround. I'm using 5.3.

  1. Set the config.database.connections.pgsql.schema config variable to your main schema (e.g. the one that holds the migrations table).

  2. Add a new config value to the config.database.connections.pgsql array: 'search_path' => 'my,desired,search,path'

  3. Create a service provider (e.g. php artisan make:provider SearchPathServiceProvider)

  4. Edit the provider and add to the boot method:

    $searchPath = config('database.connections.pgsql.search_path');
    \DB::statement("SET search_path TO $searchPath");
  5. Register your custom provider in config/app.php

The migrate command now works properly (because it relies on finding the migrations table from the schema defined by database.connections.pgsql.schema), but the rest of the app works as well, because we manually reset the search_path to what we want. I have not extensively tested this, and it may break in testing if you use a different database (e.g. sqlite), but that ought to be easy to work around.

@mattisdada
Copy link

@denaje Thanks, that helped a lot. Was using Heroku Connect and it requires multi-search path. This helped a lot!

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

5 participants