683 B · text History bbb2a48
defmodule Vigil.Repo.Migrations.AddDsnIdToProjects do
  use Ecto.Migration

  # The project id in a DSN (`https://<key>@host/<dsn_id>`) and the ingest
  # path (`/api/<dsn_id>/envelope/`) must be an integer: sentry-python does
  # `int(path.pop())`, sentry-elixir `Integer.parse/1` on it, and other
  # SDKs alike. Projects keep their UUIDv7 primary key; this is the number
  # the wire sees, given out by Postgres.
  def up do
    execute "ALTER TABLE projects ADD COLUMN dsn_id bigint GENERATED BY DEFAULT AS IDENTITY"
    create unique_index(:projects, [:dsn_id])
  end

  def down do
    drop index(:projects, [:dsn_id])
    alter table(:projects), do: remove(:dsn_id)
  end
end