Current section

20 Versions

Jump to

Compare versions

8 files changed
+66 additions
-30 deletions
  @@ -1,5 +1,11 @@
1 1 # Changelog
2 2
3 + ## v0.7.1 (2026-02-17)
4 +
5 + ### Bug fixes
6 +
7 + * (#83): Fixed re-entrancy problem when running a migration on a single tenant repo
8 +
3 9 ## v0.7.0 (2026-02-16)
4 10
5 11 ### Enhancements
  @@ -51,7 +51,7 @@ Include `:ecto_foundationdb` in your list of dependencies in `mix.exs`:
51 51 ```elixir
52 52 defp deps do
53 53 [
54 - {:ecto_foundationdb, "~> 0.6"}
54 + {:ecto_foundationdb, "~> 0.7"}
55 55 ]
56 56 end
57 57 ```
  @@ -2,7 +2,7 @@
2 2 [{<<"GitHub">>,
3 3 <<"https://github.com/foundationdb-beam/ecto_foundationdb">>}]}.
4 4 {<<"name">>,<<"ecto_foundationdb">>}.
5 - {<<"version">>,<<"0.7.0">>}.
5 + {<<"version">>,<<"0.7.1">>}.
6 6 {<<"description">>,<<"FoundationDB adapter for Ecto">>}.
7 7 {<<"elixir">>,<<"~> 1.15">>}.
8 8 {<<"app">>,<<"ecto_foundationdb">>}.
  @@ -30,6 +30,8 @@ defmodule EctoFoundationDB.Layer.Metadata do
30 30 }
31 31 }
32 32
33 + def builtin_metadata(source), do: struct(__MODULE__, @builtin_metadata[source])
34 +
33 35 defstruct indexes: [], partial_indexes: [], other: []
34 36
35 37 @type t() :: %__MODULE__{}
  @@ -12,15 +12,13 @@ defmodule EctoFoundationDB.MigrationsPJ do
12 12 alias EctoFoundationDB.Schema
13 13 alias EctoFoundationDB.Tenant
14 14
15 - import Ecto.Query
16 -
17 15 require Logger
18 16
19 17 @behaviour EctoFoundationDB.ProgressiveJob
20 18
21 19 defmodule State do
22 20 @moduledoc false
23 - defstruct [:tenant, :repo, :final_version, :limit, :options]
21 + defstruct [:tenant, :final_version, :limit, :options]
24 22 end
25 23
26 24 alias __MODULE__.State
  @@ -45,14 +43,13 @@ defmodule EctoFoundationDB.MigrationsPJ do
45 43 def claim_key(tenant, source),
46 44 do: Pack.namespaced_pack(tenant, SchemaMigration.source(), "claim", ["#{source}"])
47 45
48 - def transactional(repo, tenant, migrator, limit, options) do
49 - active_versions = get_max_versions(tenant, repo)
46 + def transactional(tenant, migrator, limit, options) do
47 + active_versions = SchemaMigration.get_max_versions(tenant)
50 48
51 49 tenant = Tenant.set_metadata_cache(tenant, :disabled)
52 50
53 51 ProgressiveJob.new(tenant, __MODULE__, %{
54 52 active_versions: active_versions,
55 - repo: repo,
56 53 migrator: migrator,
57 54 limit: limit,
58 55 options: options
  @@ -65,7 +62,6 @@ defmodule EctoFoundationDB.MigrationsPJ do
65 62 def init(tenant, args) do
66 63 %{
67 64 active_versions: active_versions,
68 - repo: repo,
69 65 migrator: migrator,
70 66 limit: limit,
71 67 options: options
  @@ -96,7 +92,6 @@ defmodule EctoFoundationDB.MigrationsPJ do
96 92 {:ok, claim_keys(tenant, new_migrations), new_migrations,
97 93 %State{
98 94 tenant: tenant,
99 - repo: repo,
100 95 final_version: final_version,
101 96 limit: limit,
102 97 options: options
  @@ -105,18 +100,11 @@ defmodule EctoFoundationDB.MigrationsPJ do
105 100 end
106 101
107 102 @impl true
108 - # Note: EctoFDB's repo.all uses the existing FDB transaction when called
109 - # within a transactional context, so this does not open a new transaction.
110 103 def done?(state, _tx) do
111 - active_versions = get_max_versions(state.tenant, state.repo)
104 + active_versions = SchemaMigration.get_max_versions(state.tenant)
112 105 {state.final_version in active_versions, state}
113 106 end
114 107
115 - defp get_max_versions(tenant, repo) do
116 - from(m in SchemaMigration, select: m.version, limit: 1, order_by: {:desc, m.version})
117 - |> repo.all(prefix: tenant, key_limit: 1)
118 - end
119 -
120 108 @impl true
121 109 def next(state, _tx, []) do
122 110 after_tx = fn -> :ok end
  @@ -124,7 +112,7 @@ defmodule EctoFoundationDB.MigrationsPJ do
124 112 end
125 113
126 114 def next(state, _tx, [{vsn, []} | new_migrations]) do
127 - {:ok, _} = SchemaMigration.up(state.repo, vsn)
115 + {:ok, _} = SchemaMigration.up(state.tenant, vsn)
128 116 after_tx = fn -> :ok end
129 117 {after_tx, [vsn], new_migrations, state}
130 118 end
Loading more files…