Skip to content

Commit 6544261

Browse files
authored
Force primary key type on migrations (#28)
This MR fixes a bug found on #27 , which arises when your application is configured to use other types of field which is not `bigserial` for primary keys. After this change, the migrations needed for the `ErrorTracker` enforce the type `bigserial` for its primary keys. --- As for people that already tried to implement the library on their systems, they need to down migrate the migration in which they introduced the library and run it again after this change is released. In normal situations we would run a migration to fix existing systems, but given that the library is less than a week old and this bug avoids using the library at all, it is safe to say that users impacted by this will not have any data stored.
1 parent 8cc2e84 commit 6544261

File tree

1 file changed

+11
-3
lines changed
  • lib/error_tracker/migration/postgres

1 file changed

+11
-3
lines changed

lib/error_tracker/migration/postgres/v01.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ defmodule ErrorTracker.Migration.Postgres.V01 do
66
def up(%{create_schema: create_schema, prefix: prefix}) do
77
if create_schema, do: execute("CREATE SCHEMA IF NOT EXISTS #{prefix}")
88

9-
create table(:error_tracker_errors, prefix: prefix) do
9+
create table(:error_tracker_errors,
10+
primary_key: [name: :id, type: :bigserial],
11+
prefix: prefix
12+
) do
1013
add :kind, :string, null: false
1114
add :reason, :text, null: false
1215
add :source_line, :text, null: false
@@ -20,11 +23,16 @@ defmodule ErrorTracker.Migration.Postgres.V01 do
2023

2124
create unique_index(:error_tracker_errors, [:fingerprint], prefix: prefix)
2225

23-
create table(:error_tracker_occurrences, prefix: prefix) do
26+
create table(:error_tracker_occurrences,
27+
primary_key: [name: :id, type: :bigserial],
28+
prefix: prefix
29+
) do
2430
add :context, :map, null: false
2531
add :reason, :text, null: false
2632
add :stacktrace, :map, null: false
27-
add :error_id, references(:error_tracker_errors, on_delete: :delete_all), null: false
33+
34+
add :error_id, references(:error_tracker_errors, on_delete: :delete_all, type: :bigserial),
35+
null: false
2836

2937
timestamps(type: :utc_datetime_usec, updated_at: false)
3038
end

0 commit comments

Comments
 (0)