I’m currently handling auth on multi-tenancy, is this approach to migration warranted? TLWR; I’m schema targeting everything including the execute function that resolves case sensitivity issues.
defmodule AuthTest.Repo.Migrations.CreateUsersAuthTables do
use Ecto.Migration
def change do
Enum.each(~w{client_1 client_2 client_3}, fn
prefix ->
execute "CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA #{prefix}", ""
create table(:users, prefix: prefix) do
add :email, :citext, null: false
add :hashed_password, :string, null: false
add :confirmed_at, :utc_datetime
timestamps(type: :utc_datetime)
end
create unique_index(:users, [:email], prefix: prefix)
create table(:users_tokens, prefix: prefix) do
add :user_id, references(:users, on_delete: :delete_all), null: false
add :token, :binary, null: false
add :context, :string, null: false
add :sent_to, :string
timestamps(type: :utc_datetime, updated_at: false)
end
create index(:users_tokens, [:user_id], prefix: prefix)
create unique_index(:users_tokens, [:context, :token], prefix: prefix)
end
)
end
end
Oops, apologies, I’ve amended the code above. Forgot to add the rest of the prefix key value pairs.