Current section
20 Versions
Jump to
Current section
20 Versions
Compare versions
5
files changed
+49
additions
-6
deletions
| @@ -1,5 +1,15 @@ | |
| 1 1 | # Changelog |
| 2 2 | |
| 3 | + ## v0.7.2 (2026-04-05) |
| 4 | + |
| 5 | + ### Bug fixes |
| 6 | + |
| 7 | + * (#86): Added `Repo.transactional/1` for use on single-tenant repos. |
| 8 | + |
| 9 | + ### Dependencies |
| 10 | + |
| 11 | + * `erlfdb ~> 1.0` - no functional changes, adopting v1.0 release that matches v0.3 API |
| 12 | + |
| 3 13 | ## v0.7.1 (2026-02-17) |
| 4 14 | |
| 5 15 | ### Bug fixes |
| @@ -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.1">>}. |
| 5 | + {<<"version">>,<<"0.7.2">>}. |
| 6 6 | {<<"description">>,<<"FoundationDB adapter for Ecto">>}. |
| 7 7 | {<<"elixir">>,<<"~> 1.15">>}. |
| 8 8 | {<<"app">>,<<"ecto_foundationdb">>}. |
| @@ -11,7 +11,7 @@ | |
| 11 11 | [[{<<"name">>,<<"erlfdb">>}, |
| 12 12 | {<<"app">>,<<"erlfdb">>}, |
| 13 13 | {<<"optional">>,false}, |
| 14 | - {<<"requirement">>,<<"~> 0.3.4">>}, |
| 14 | + {<<"requirement">>,<<"~> 1.0">>}, |
| 15 15 | {<<"repository">>,<<"hexpm">>}], |
| 16 16 | [{<<"name">>,<<"ecto">>}, |
| 17 17 | {<<"app">>,<<"ecto">>}, |
| @@ -427,6 +427,19 @@ defmodule Ecto.Adapters.FoundationDB do | |
| 427 427 | Note: If you're looking for PubSub-like functionality pushed from the database itself, please see |
| 428 428 | [Watches](#module-watches). |
| 429 429 | |
| 430 | + For a single-tenant Repo (one configured with `:tenant_id`), you can use `Repo.transactional/1`, |
| 431 | + which automatically uses the configured tenant: |
| 432 | + |
| 433 | + ```elixir |
| 434 | + MyApp.SystemRepo.transactional(fn -> |
| 435 | + MyApp.SystemRepo.insert(%User{name: "Alice"}) |
| 436 | + # ... |
| 437 | + end) |
| 438 | + ``` |
| 439 | + |
| 440 | + `Repo.transactional/1` raises `EctoFoundationDB.Exception.IncorrectTenancy` if called on |
| 441 | + a multi-tenant Repo. |
| 442 | + |
| 430 443 | ## Migrations |
| 431 444 | |
| 432 445 | At first glance, EctoFoundationDB migrations may look similar to that of `:ecto_sql`, |
| @@ -1074,7 +1087,7 @@ defmodule Ecto.Adapters.FoundationDB do | |
| 1074 1087 | For example, a transaction must complete |
| 1075 1088 | [within 5 seconds](https://apple.github.io/foundationdb/developer-guide.html#long-running-transactions). |
| 1076 1089 | """ |
| 1077 | - @spec transactional(Tenant.t() | nil, function()) :: any() |
| 1090 | + @spec transactional(Tenant.t(), function()) :: any() |
| 1078 1091 | def transactional(tenant, fun), do: Tx.transactional_external(tenant, fun) |
| 1079 1092 | |
| 1080 1093 | @impl Ecto.Adapter |
| @@ -1082,6 +1095,11 @@ defmodule Ecto.Adapters.FoundationDB do | |
| 1082 1095 | quote do |
| 1083 1096 | def transactional(tenant, fun), do: Ecto.Adapters.FoundationDB.transactional(tenant, fun) |
| 1084 1097 | |
| 1098 | + def transactional(fun) do |
| 1099 | + tenant = EctoFoundationDB.Assert.CorrectTenancy.assert_single_tenant!(__MODULE__) |
| 1100 | + Ecto.Adapters.FoundationDB.transactional(tenant, fun) |
| 1101 | + end |
| 1102 | + |
| 1085 1103 | def async_insert_all!(schema, list, opts \\ []) do |
| 1086 1104 | repo = get_dynamic_repo() |
| 1087 1105 | EctoAdapterAsync.async_insert_all!(__MODULE__, repo, schema, list, opts) |
| @@ -17,6 +17,21 @@ defmodule EctoFoundationDB.Assert.CorrectTenancy do | |
| 17 17 | end |
| 18 18 | end |
| 19 19 | |
| 20 | + def assert_single_tenant!(repo) do |
| 21 | + repo_config = [repo: repo] ++ repo.config() |
| 22 | + |
| 23 | + if single?(repo_config) do |
| 24 | + SingleTenantRepo.get!(repo) |
| 25 | + else |
| 26 | + raise IncorrectTenancy, """ |
| 27 | + Repo.transactional/1 can only be used with a single-tenant Repo \ |
| 28 | + (one configured with `:tenant_id`). |
| 29 | + |
| 30 | + Use Repo.transactional/2 with an explicit tenant argument instead. |
| 31 | + """ |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 20 35 | def assert_by_schema!(repo_config, schema_meta) do |
| 21 36 | if single?(repo_config) do |
| 22 37 | assert_single_tenancy_by_schema!(repo_config, schema_meta) |
| @@ -4,7 +4,7 @@ defmodule EctoFoundationdb.MixProject do | |
| 4 4 | def project do |
| 5 5 | [ |
| 6 6 | app: :ecto_foundationdb, |
| 7 | - version: "0.7.1", |
| 7 | + version: "0.7.2", |
| 8 8 | description: "FoundationDB adapter for Ecto", |
| 9 9 | elixir: "~> 1.15", |
| 10 10 | start_permanent: Mix.env() == :prod, |
| @@ -74,14 +74,14 @@ defmodule EctoFoundationdb.MixProject do | |
| 74 74 | # Run "mix help deps" to learn about dependencies. |
| 75 75 | defp deps do |
| 76 76 | [ |
| 77 | - {:erlfdb, "~> 0.3.4"}, |
| 77 | + {:erlfdb, "~> 1.0"}, |
| 78 78 | {:ecto, "~> 3.13"}, |
| 79 79 | {:jason, "~> 1.4"}, |
| 80 80 | {:credo, "~> 1.6", only: [:dev, :test, :docs]}, |
| 81 81 | {:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false}, |
| 82 82 | {:ex_doc, "~> 0.16", only: :dev, runtime: false}, |
| 83 83 | {:benchee, "~> 1.0", only: :bench}, |
| 84 | - {:ex_fdbmonitor, "~> 0.1", only: :bench, runtime: false} |
| 84 | + {:ex_fdbmonitor, "~> 0.2", only: :bench, runtime: false} |
| 85 85 | ] ++ optional_deps() |
| 86 86 | end |