Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with generated migrations for multitenant resources #144

Closed
revati opened this issue May 7, 2023 · 1 comment
Closed

Issue with generated migrations for multitenant resources #144

revati opened this issue May 7, 2023 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@revati
Copy link

revati commented May 7, 2023

Describe the bug
If i create resource with

  multitenancy do
    strategy :attribute
    attribute :organization_id
  end

and have another resource relating to this one, generated migration is wrong.
Fails with error:

** (Postgrex.Error) ERROR 42830 (invalid_foreign_key) there is no unique constraint matching given keys for referenced table "<table_name>"

To fix i need to add

  identities do
    identity :unique_id, [:id]
  end

which creates unique index with tenant (organization_id in this case prefix) so unique index [:organization_id, :id]
Then migrations works fine

Expected behavior
It would add corrcet unique indexes by default for primary fields with multitenancy

Runtime

  • Elixir version - Elixir 1.14.3 (compiled with Erlang/OTP 25)
  • Erlang version - Erlang/OTP 25
  • OS - macos 13.1
  • Ash version - 2.9.4
@zachdaniel
Copy link
Contributor

Basically what we need to do here is, if the relationship points at the primary key of the target, we should not add the multitenancy attribute. This should be relatively easy to do.

@zachdaniel zachdaniel added the good first issue Good for newcomers label May 9, 2023
moissela added a commit to zoonect-oss/ash_postgres that referenced this issue Sep 25, 2023
…f the relationship points at the primary key of the target then not adding the multitenancy attribute (ash-project#144 and ash-project#157)
@moissela moissela mentioned this issue Sep 25, 2023
2 tasks
zachdaniel pushed a commit that referenced this issue Sep 25, 2023
… if the relationship points at the primary key of the target then not adding the multitenancy attribute (#144 and #157)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants