You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When adding a belongs_to relationship and using the attribute for multitenancy, if you generate single migrate all at once, it is invalid. If you break it up--add the relationship, generate a migration, add multitenancy, and generate a 2nd migration--then the individual migrations are valid.
def up do
alter table(:accounts) do
add :environment_id,
references(:environments,
column: :id,
name: "accounts_environment_id_fkey",
type: :uuid,
prefix: "public"
),
null: false
end
end
def up do
drop_if_exists unique_index(:accounts, [:key], name: "accounts_key_index")
create unique_index(:accounts, [:environment_id, :key], name: "accounts_key_index")
end
However if you were to generate the migrations all at once, you'd get...
22:56:57.955 [info] create table accounts
** (Postgrex.Error) ERROR 42830 (invalid_foreign_key) there is no unique constraint matching given keys for referenced table "environments"
The reference for the :environment_id column has a with: [environment_id: :tenant_id], match: :full which you don't get running generating multiple migrations.
Expected behavior
I expect the migration generator to generate a valid migration.
That is pretty strange...I'll leave this one up for grabs and mark it as a good first issue, as I don't have time to fix it. There is a workaround as you've stated.
Describe the bug
When adding a belongs_to relationship and using the attribute for multitenancy, if you generate single migrate all at once, it is invalid. If you break it up--add the relationship, generate a migration, add multitenancy, and generate a 2nd migration--then the individual migrations are valid.
To Reproduce
Initial migration looks like:
Add in a relation...
Second migration looks good...
Turn on multitenancy...
Third migration looks good...
However if you were to generate the migrations all at once, you'd get...
And that migration gives you this error:
The reference for the :environment_id column has a
with: [environment_id: :tenant_id], match: :full
which you don't get running generating multiple migrations.Expected behavior
I expect the migration generator to generate a valid migration.
** Runtime
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: