Cant rollback migration for tenants
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing the tenant rollback with the MyMenu.Repo.all_tenants/0 example in the issue. Trace the tenant discovery path from lib/mix/helpers.ex:171 and compare it with the Ash.read! call shown in lib/my_menu/repo.ex:26, including the telemetry failure. Done means mix ash_postgres.rollback --tenants runs the down function of the last migration.
Written by the indexing model from the issue text.
Description
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
Erlang/OTP 27 [erts-15.2] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]
Elixir 1.18.1 (compiled with Erlang/OTP 27)
Operating system
Mac OS Sequoia Version 15.6.1 (24G90)
Current Behavior
when trying to rollback a tenant migration i run into
Generated my_menu app
** (RuntimeError) MyMenu.Repo.all_tenants/0 was called, but was not defined. In order to migrate tenants, you must define this function.
For example, you might say:
def all_tenants do
for org <- MyApp.Accounts.all_organizations!() do
org.schema
end
end
then I added this into repo.ex @impl true def all_tenants do MyMenu.Orgs.Org |> Ash.read!() |> Enum.map(fn org -> "org_#{org.slug}" end) end
running: mix ash.migrate --tenants worked fine, but mix ash_postgres.rollback --tenants is failing
** (Ash.Error.Unknown)
Bread Crumbs:
> Exception raised in: MyMenu.Orgs.Org.read
Unknown Error
* ** (ArgumentError) errors were found at the given arguments:
* 1st argument: the table identifier does not refer to an existing ETS table
(stdlib 6.2) :ets.match_object(:telemetry_handler_table, {:handler, :_, [:ash, :orgs, :read | :_], :_, :_})
(telemetry 1.3.0) /Users/icaro/Projects/icaro/my_menu/deps/telemetry/src/telemetry_handler_table.erl:59: :telemetry_handler_table.list_by_prefix/1
(telemetry 1.3.0) /Users/icaro/Projects/icaro/my_menu/deps/telemetry/src/telemetry.erl:379: :telemetry.list_handlers/1
(ash 3.7.2) lib/ash/actions/read/read.ex:84: Ash.Actions.Read.run/3
(ash 3.7.2) lib/ash.ex:2776: Ash.read/2
(ash 3.7.2) lib/ash.ex:2711: Ash.read!/2
(my_menu 0.1.0) lib/my_menu/repo.ex:26: MyMenu.Repo.all_tenants/0
(ash_postgres 2.6.23) lib/mix/helpers.ex:171: AshPostgres.Mix.Helpers.tenants/2
(stdlib 6.2) :ets.match_object(:telemetry_handler_table, {:handler, :_, [:ash, :orgs, :read | :_], :_, :_})
(telemetry 1.3.0) /Users/icaro/Projects/icaro/my_menu/deps/telemetry/src/telemetry_handler_table.erl:59: :telemetry_handler_table.list_by_prefix/1
(telemetry 1.3.0) /Users/icaro/Projects/icaro/my_menu/deps/telemetry/src/telemetry.erl:379: :telemetry.list_handlers/1
(ash 3.7.2) lib/ash/actions/read/read.ex:84: Ash.Actions.Read.run/3
(ash 3.7.2) lib/ash.ex:2776: Ash.read/2
(ash 3.7.2) lib/ash.ex:2711: Ash.read!/2
(my_menu 0.1.0) lib/my_menu/repo.ex:26: MyMenu.Repo.all_tenants/0
(ash_postgres 2.6.23) lib/mix/helpers.ex:171: AshPostgres.Mix.Helpers.tenants/2
Reproduction
defmodule MyMenu.Repo do
use AshPostgres.Repo,
otp_app: :my_menu
@impl true
def installed_extensions do
# Add extensions here, and the migration generator will install them.
["ash-functions", "citext", AshMoney.AshPostgresExtension]
end
# Don't open unnecessary transactions
# will default to `false` in 4.0
@impl true
def prefer_transaction? do
false
end
@impl true
def min_pg_version do
%Version{major: 16, minor: 0, patch: 0}
end
@impl true
def all_tenants do
MyMenu.Orgs.Org
|> Ash.read!()
|> Enum.map(fn org -> "org_#{org.slug}" end)
end
end
require Ash.Resource.Change.Builtins
use Ash.Resource,
domain: MyMenu.Orgs,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication]
postgres do
table "orgs"
repo MyMenu.Repo
# Automatic tenant schema creation
manage_tenant do
template ["org_", :slug]
create? true
update? false
end
end
actions do
defaults [:read]
create :create do
accept [:name]
change fn changeset, _context ->
name = Ash.Changeset.get_attribute(changeset, :name)
slug =
name
|> String.downcase()
|> String.replace(" ", "-")
Ash.Changeset.force_change_attribute(changeset, :slug, slug)
end
end
end
attributes do
uuid_v7_primary_key :id
attribute :name, :string do
allow_nil? false
public? true
end
attribute :slug, :string do
allow_nil? false
public? true
end
create_timestamp :created_at
update_timestamp :updated_at
end
identities do
identity :unique_slug, [:slug]
end
end
Expected Behavior
mix ash_postgres.rollback --tenants run down function of the last migration created
- Dominant language
- Elixir
- Stars
- 191
- Forks
- 186
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 17
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ash-project/ash_postgres
-
Temporal: an update or destroy as of an instant doesn't carry into later versionsPossibly taken @hoanle0126 claimed this 13 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
ash-project/ash_postgres#915 · 1 comment ·
Maintainers usually reply within 1 day
-
has_create_action?/1 excludes manual creates, making the #49 nullability fix inert on AshEvents resourcesMay be free again @Mckay-Hinds claimed this 18 days ago, and no pull request is open. Open
Difficulty 3/5 1-2 days Newbie friendliness 76/100
ash-project/ash_postgres#851 · 9 comments ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ash-project/ash_postgres#650 · 6 comments ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 40/100
ash-project/ash_postgres#628 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement good first issue
Difficulty 4/5 3-5 days Newbie friendliness 48/100
ash-project/ash_postgres#538 · 1 comment ·
Maintainers usually reply within 1 day
All issues in ash-project/ash_postgres
Similar issues
-
@swmansion/popcorn: published .d.ts files lack extensions on relative imports, breaking moduleResolution node16/nodenextPossibly taken @Huyvux12 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
software-mansion/popcorn#929 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
ash-project/ash#3127 ·
Maintainers usually reply within 1 day
-
Bug: Table layout and date column are cut off on mobile screens on the Tournaments -> History pageOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
hexlet-codebattle/codebattle#2375 ·
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wintermeyer/vutuv#2388 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100