elixir-error-tracker / error-tracker

🐛 An Elixir-based built-in error reporting and tracking solution
https://hex.pm/packages/error_tracker
Apache License 2.0
383 stars 17 forks source link

Use explicit column name for FK references #62

Closed crbelaus closed 2 months ago

crbelaus commented 2 months ago

The ErrorTracker tables use id as the primary key name. This was causing trouble when the client repository was configured to use a different column name for references since it tried to create a foreign key pointing to a non-existing column.

This commit explicitly states the referenced column name to avoid this problems.

To check this you can create a new Phoenix application that uses the error tracker and add the following configuration to the application repository:

config :my_app, MyApp.Repo,
  migration_primary_key: [name: :uuid, type: :binary_id],
  migration_foreign_key: [column: :uuid, type: :binary_id]

Trying this on main will raise an error when running the migrations. The error is not present in this branch.

Closes #59

crbelaus commented 2 months ago

It is worth mentioning that this fails only on Postgres. SQLite creates the column but ignores the FK creation if there are any errors. I've updated both migrations regardless to ensure that they are consistent.

petrus-jvrensburg commented 2 months ago

Thanks @crbelaus ! I tried this branch locally, and it's working as expected.