Skip to content

Commit 3902cc2

Browse files
Gigitsujosevalim
authored andcommitted
Use :seach_path parameter in the multi tenancy guide (#4677)
1 parent 0bf3fa4 commit 3902cc2

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

guides/howtos/Multi tenancy with query prefixes.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,18 @@ We haven't done anything unusual so far. We created our database instance, made
8282

8383
By default, connections to Postgres' databases run on the "public" prefix. When we run migrations and queries, they are all running against the "public" prefix. However imagine your application has a requirement to run on a particular prefix in production, let's call it "connection_prefix".
8484

85-
Luckily Postgres allows us to change the prefix our database connections run on by setting the "schema search path". The best moment to change the search path is right after we setup the database connection, ensuring all of our queries will run on that particular prefix, throughout the connection life-cycle.
85+
Luckily Postgres allows us to change the prefix our database connections run on by setting the "schema search path". The best moment to change the search path is during the setup of the database connection, ensuring all of our queries will run on that particular prefix, throughout the connection life-cycle.
8686

87-
To do so, let's change our database configuration in "config/config.exs" and specify an `:after_connect` option. `:after_connect` expects a tuple with module, function and arguments it will invoke with the connection process, as soon as a database connection is established:
87+
To do so, let's change our database configuration in "config/config.exs" and set a `:search_path` parameter in the `:parameters` option. The `:search_path` parameter expects a list of strings that define the search path for the connection:
8888

8989
```elixir
90-
query_args = ["SET search_path TO connection_prefix", []]
91-
9290
config :my_app, MyApp.Repo,
9391
username: "postgres",
9492
password: "postgres",
9593
database: "demo_dev",
9694
hostname: "localhost",
9795
pool_size: 10,
98-
after_connect: {Postgrex, :query!, query_args}
96+
parameters: [search_path: ["connection_prefix"]]
9997
```
10098

10199
Now let's try to run the same query as before:

0 commit comments

Comments
 (0)