andrewb
Ecto migrations: is it possible to pass a variable value
Hi,
I have a multi-tenant system and I use Postgres Schemas to isolate data for each tenant. When a tenant signs up I run a set of migrations using the Migrator. I would like to create a MATERIALIZED VIEW for each Tenant that joins a table from the tenant’s schema with a public schema table.
defmodule Migrations.AddUserView do
use Ecto.Migration
def up do
execute """
CREATE MATERIALIZED VIEW users
AS SELECT fullname, email, email_verified, mobile, mobile_verified, roles.display
FROM PUBLIC.users, TENANT.tenant_users, TENANT.roles WHERE PUBLIC. users.id =
TENANT.tenant_users.user_id
AND PUBLIC.roles.id =TENANT.tenant_users.role_id;
"""
end
def down do
execute "DROP MATERIALIZED VIEW users;"
end
end
To create the VIEW I need to pass the schema name to the migration so it can access the correct tables. Does anyone know if this is possible?
Regards,
Andrew
Marked As Solved
l00ker
The prefix() function is probably what you’re looking for. Have a look at this forum thread.
3
Also Liked
andrewb
Fantastic, exactly what I needed. Thanks
1
Popular in Questions
can someone please explain to me how Enum.reduce works with maps
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it.
I’m very interested in Elixir,...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
Hello,
I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these
buyer = %{
id: ...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
Other popular topics
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New







