Skip to content

Commit

Permalink
fix: Ignore module conflict when compiling migration file (#482)
Browse files Browse the repository at this point in the history
This fixes the problem of logging "redefining module" entries when
using context-driven multitenancy (where each tenant tries to compile
the migration module).

Fixes #480
  • Loading branch information
smt116 authored Feb 12, 2025
1 parent a84358c commit d21f06c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/migration_compile_cache.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ defmodule AshPostgres.MigrationCompileCache do
defp ensure_compiled(state, file) do
case Map.get(state, file) do
nil ->
Code.put_compiler_option(:ignore_module_conflict, true)
compiled = Code.compile_file(file)
Map.put(state, file, compiled)

_ ->
state
end
after
Code.put_compiler_option(:ignore_module_conflict, false)
end
end
4 changes: 0 additions & 4 deletions lib/multitenancy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ defmodule AshPostgres.MultiTenancy do
migrations_path ||
repo.config()[:tenant_migrations_path] || default_tenant_migration_path(repo)

Code.compiler_options(ignore_module_conflict: true)

Ecto.Migration.SchemaMigration.ensure_schema_migrations_table!(
repo,
repo.config(),
Expand Down Expand Up @@ -44,8 +42,6 @@ defmodule AshPostgres.MultiTenancy do

Ecto.Migration.SchemaMigration.up(repo, repo.config(), version, prefix: tenant_name)
end)
after
Code.compiler_options(ignore_module_conflict: false)
end

# sobelow_skip ["SQL"]
Expand Down

0 comments on commit d21f06c

Please sign in to comment.