Skip to content

Commit e5eea0b

Browse files
authored
Use explicit column name for FK references (#62)
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: ```elixir 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
1 parent cfb9e59 commit e5eea0b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/error_tracker/migration/postgres/v01.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ defmodule ErrorTracker.Migration.Postgres.V01 do
4848
add :stacktrace, :map, null: false
4949

5050
add :error_id,
51-
references(:error_tracker_errors, on_delete: :delete_all, type: :bigserial),
51+
references(:error_tracker_errors,
52+
on_delete: :delete_all,
53+
column: :id,
54+
type: :bigserial
55+
),
5256
null: false
5357

5458
timestamps(type: :utc_datetime_usec, updated_at: false)

lib/error_tracker/migration/sqlite/v02.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ defmodule ErrorTracker.Migration.SQLite.V02 do
2727
add :reason, :text, null: false
2828
add :stacktrace, :map, null: false
2929

30-
add :error_id, references(:error_tracker_errors, on_delete: :delete_all, type: :bigserial),
31-
null: false
30+
add :error_id,
31+
references(:error_tracker_errors, on_delete: :delete_all, column: :id, type: :bigserial),
32+
null: false
3233

3334
timestamps(type: :utc_datetime_usec, updated_at: false)
3435
end

0 commit comments

Comments
 (0)