Cant rollback migration for tenants
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
首先,使用 issue 中的 MyMenu.Repo.all_tenants/0 示例重现租户回滚。跟踪从 lib/mix/helpers.ex:171 开始的租户发现路径,并将其与 lib/my_menu/repo.ex:26 中所示的 Ash.read! 调用进行比较,包括 telemetry 失败。完成的标准是 mix ash_postgres.rollback --tenants 运行最后一个迁移的 down 函数。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Elixir
- 星标
- 191
- 派生
- 186
- 平均合并
- 16 小时 4 分钟
- 30 天内合并 PR
- 17
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ash-project/ash_postgres 的其他 Issue
-
Temporal: an update or destroy as of an instant doesn't carry into later versions可能已有人在做 @hoanle0126 于 13 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 15/100
ash-project/ash_postgres#915 · 1 条评论 ·
维护者通常 1 天内回复
-
has_create_action?/1 excludes manual creates, making the #49 nullability fix inert on AshEvents resources可能重新可做 @Mckay-Hinds 于 18 天前认领,目前没有进行中的 PR。 未关闭
难度 3/5 1-2 天 新手友好度 76/100
ash-project/ash_postgres#851 · 9 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 4/5 3-5 天 新手友好度 35/100
ash-project/ash_postgres#650 · 6 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 40/100
ash-project/ash_postgres#628 · 1 条评论 ·
维护者通常 1 天内回复
-
enhancement good first issue
难度 4/5 3-5 天 新手友好度 48/100
ash-project/ash_postgres#538 · 1 条评论 ·
维护者通常 1 天内回复
查看 ash-project/ash_postgres 的全部 Issue
相似的 Issue
-
@swmansion/popcorn: published .d.ts files lack extensions on relative imports, breaking moduleResolution node16/nodenext可能已有人在做 @Huyvux12 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
software-mansion/popcorn#929 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
ash-project/ash#3127 ·
维护者通常 1 天内回复
-
Bug: Table layout and date column are cut off on mobile screens on the Tournaments -> History page未关闭bug
难度 2/5 1-3 小时 新手友好度 74/100
hexlet-codebattle/codebattle#2375 ·
-
Bug
难度 2/5 1-3 小时 新手友好度 68/100
wintermeyer/vutuv#2388 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100