Multi-tenancy: Phx.gen.auth, Ecto.Migration.execute/1 specifying the schema

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.

FYI I do believe this to be a correct form:

  def change do
    Enum.each(~w{schema_1 schema_2 schema_3}, fn
      prefix ->
        execute "CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA #{prefix}", ""

        create table(:users, primary_key: false, prefix: prefix) do
          add :id, :binary_id, primary_key: true
          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, primary_key: false, prefix: prefix) do
          add :id, :binary_id, primary_key: true
          add :user_id, references(:users, type: :binary_id, 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

I’m using it and it’s working.