Skip to content

Creating indexes concurrently fails for schema-driven multi-tenancy #610

@smt116

Description

@smt116

Code of Conduct

  • I agree to follow this project's Code of Conduct

AI Policy

  • I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.

Versions

Elixir 1.18.3-otp-27
Erlang 27.3.3

ash: "3.5.37
ash_admin: "0.13.18
ash_ai: "0.2.12
ash_appsignal: "0.1.3"
ash_archival: "2.0.1"
ash_authentication_phoenix: "2.10.5"
ash_cloak: "0.1.7"
ash_json_api: "1.4.42
ash_oban: "0.4.12
ash_paper_trail: "0.5.6"
ash_phoenix: "2.3.16
ash_postgres: "2.6.17
ash_sql: "0.2.92
ash_state_machine: "0.2.12

Operating system

macOS

Current Behavior

Creating index concurrently with @disable_ddl_transaction true and @disable_migration_lock true fails with the following exception if using schema-driven tenancy:

* ** (Postgrex.Error) ERROR 25001 (active_sql_transaction) CREATE INDEX CONCURRENTLY cannot run inside a transaction block
  (ecto_sql 3.13.2) lib/ecto/adapters/sql.ex:1098: Ecto.Adapters.SQL.raise_sql_call_error/1
  (elixir 1.18.3) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
  (ecto_sql 3.13.2) lib/ecto/adapters/sql.ex:1219: Ecto.Adapters.SQL.execute_ddl/4
  (ecto_sql 3.13.2) lib/ecto/migration/runner.ex:348: Ecto.Migration.Runner.log_and_execute_ddl/3
  (elixir 1.18.3) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
  (elixir 1.18.3) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
  (ecto_sql 3.13.2) lib/ecto/migration/runner.ex:311: Ecto.Migration.Runner.perform_operation/3
  (stdlib 6.2.2) timer.erl:595: :timer.tc/2
  (ecto_sql 3.13.2) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/8
  (ash_postgres 2.6.17) lib/multitenancy.ex:45: anonymous fn/3 in AshPostgres.MultiTenancy.migrate_tenant/4
  (elixir 1.18.3) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
  (ash_postgres 2.6.17) lib/data_layer.ex:2034: AshPostgres.DataLayer.bulk_create/3
  (ash_postgres 2.6.17) lib/data_layer.ex:2212: AshPostgres.DataLayer.create/2
  (ash 3.5.37) lib/ash/actions/create/create.ex:429: anonymous fn/6 in Ash.Actions.Create.commit/3
  (ash 3.5.37) lib/ash/changeset/changeset.ex:4642: Ash.Changeset.run_around_actions/2
  (ash 3.5.37) lib/ash/changeset/changeset.ex:4178: anonymous fn/3 in Ash.Changeset.with_hooks/3
  (eden 1.0.0-test+987998d3c) lib/eden/repo.ex:2: anonymous fn/1 in Eden.Repo."transaction (overridable 1)"/2
  (ecto 3.13.2) lib/ecto/repo/transaction.ex:7: anonymous fn/2 in Ecto.Repo.Transaction.transact/4
  (ecto_sql 3.13.2) lib/ecto/adapters/sql.ex:1458: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
  (db_connection 2.8.0) lib/db_connection.ex:1753: DBConnection.run_transaction/4
  (ash 3.5.37) lib/ash/changeset/changeset.ex:4176: anonymous fn/3 in Ash.Changeset.with_hooks/3
  (ash 3.5.37) lib/ash/changeset/changeset.ex:4320: anonymous fn/2 in Ash.Changeset.transaction_hooks/2
  (ash 3.5.37) lib/ash/changeset/changeset.ex:4163: Ash.Changeset.with_hooks/3
  (ash 3.5.37) lib/ash/actions/create/create.ex:261: Ash.Actions.Create.commit/3
  (ash 3.5.37) lib/ash/actions/create/create.ex:132: Ash.Actions.Create.do_run/4
  (ash 3.5.37) lib/ash/actions/create/create.ex:50: Ash.Actions.Create.run/4
  (ash 3.5.37) lib/ash.ex:3054: Ash.create!/3
  priv/repo/test_seeds.exs:7: anonymous fn/0 in :elixir_compiler_681.__FILE__/1
  (ecto_sql 3.13.2) lib/ecto/adapters/sql/sandbox.ex:624: Ecto.Adapters.SQL.Sandbox.unboxed_run/2
  priv/repo/test_seeds.exs:1: (file)
  (elixir 1.18.3) src/elixir_compiler.erl:77: :elixir_compiler.dispatch/4
  (elixir 1.18.3) src/elixir_compiler.erl:52: :elixir_compiler.compile/4
  (elixir 1.18.3) src/elixir_compiler.erl:39: :elixir_compiler.maybe_fast_compile/2
  (elixir 1.18.3) src/elixir_lexical.erl:13: :elixir_lexical.run/3
  (elixir 1.18.3) src/elixir_compiler.erl:17: :elixir_compiler.quoted/3
  (elixir 1.18.3) lib/module/parallel_checker.ex:120: Module.ParallelChecker.verify/1
  (elixir 1.18.3) lib/code.ex:1525: Code.require_file/2
  (mix 1.18.3) lib/mix/tasks/run.ex:146: Mix.Tasks.Run.run/5
  (mix 1.18.3) lib/mix/tasks/run.ex:85: Mix.Tasks.Run.run/1
  (mix 1.18.3) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5
  (mix 1.18.3) lib/mix/task.ex:561: Mix.Task.run_alias/6
  (mix 1.18.3) lib/mix/cli.ex:107: Mix.CLI.run_task/2
  /home/runner/work/_temp/.setup-beam/elixir/bin/mix:2: (file)
  (elixir 1.18.3) src/elixir_compiler.erl:77: :elixir_compiler.dispatch/4
  (elixir 1.18.3) src/elixir_compiler.erl:52: :elixir_compiler.compile/4
  (elixir 1.18.3) src/elixir_compiler.erl:39: :elixir_compiler.maybe_fast_compile/2
  (elixir 1.18.3) src/elixir_lexical.erl:13: :elixir_lexical.run/3
  (elixir 1.18.3) src/elixir_compiler.erl:17: :elixir_compiler.quoted/3
  (elixir 1.18.3) lib/module/parallel_checker.ex:120: Module.ParallelChecker.verify/1
  (elixir 1.18.3) lib/code.ex:1525: Code.require_file/2
  (elixir 1.18.3) lib/kernel/cli.ex:553: Kernel.CLI.wrapper/1
  (elixir 1.18.3) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
  (elixir 1.18.3) lib/kernel/cli.ex:89: Kernel.CLI.process_commands/1
  (elixir 1.18.3) lib/kernel/cli.ex:35: anonymous fn/2 in Kernel.CLI.main/1
  (elixir 1.18.3) lib/kernel/cli.ex:137: anonymous fn/3 in Kernel.CLI.exec_fun/2
    (ash 3.5.37) lib/ash/error/unknown.ex:3: Ash.Error.Unknown."exception (overridable 2)"/1
    (ash 3.5.37) /home/runner/work/eden-platform/eden-platform/deps/splode/lib/splode.ex:264: Ash.Error.to_class/2
    (ash 3.5.37) lib/ash/error/error.ex:108: Ash.Error.to_error_class/2
    (ash 3.5.37) lib/ash/actions/create/create.ex:161: Ash.Actions.Create.do_run/4
    (ash 3.5.37) lib/ash/actions/create/create.ex:50: Ash.Actions.Create.run/4
    (ash 3.5.37) lib/ash.ex:3054: Ash.create!/3
    priv/repo/test_seeds.exs:7: anonymous fn/0 in :elixir_compiler_681.__FILE__/1
    (ecto_sql 3.13.2) lib/ecto/adapters/sql/sandbox.ex:624: Ecto.Adapters.SQL.Sandbox.unboxed_run/2
    priv/repo/test_seeds.exs:1: (file)
    (elixir 1.18.3) lib/code.ex:1525: Code.require_file/2
    (mix 1.18.3) lib/mix/tasks/run.ex:146: Mix.Tasks.Run.run/5
    (mix 1.18.3) lib/mix/tasks/run.ex:85: Mix.Tasks.Run.run/1
    (mix 1.18.3) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.18.3) lib/mix/task.ex:561: Mix.Task.run_alias/6
    (mix 1.18.3) lib/mix/cli.ex:107: Mix.CLI.run_task/2
    /home/runner/work/_temp/.setup-beam/elixir/bin/mix:2: (file)
    (elixir 1.18.3) lib/code.ex:1525: Code.require_file/2

Reproduction

Create Ash project where resource uses PostgreSQL database and:

multitenancy do
  strategy :context
end

Then, generate a migration that creates an index with concurrently: true.

Expected Behavior

Allow creating indexes concurrently when using multi-tenancy

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    Projects

    Status

    Soon

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions