izelnakri / paper_trail

Track and record all the changes in your database with Ecto. Revert back to anytime in history.
https://hex.pm/packages/paper_trail
MIT License
565 stars 92 forks source link

Settings does not work in application with runtime #212

Closed viniciusilveira closed 1 year ago

viniciusilveira commented 1 year ago

Hello! I'm using paper_trail in an application when code is compiled, and the settings of lib do not work.

This error is returned when a try to save, update or delete data with PaperTrail: ** (Ecto.ChangeError) value `"9002cb70-ddf1-4c9b-8c88-458f3086d14d"` for `PaperTrail.Version.item_id` in `insert` does not match type :integer

When I start the application with mix phx.server the settings works and the error does not happen.

That is my config in runtime.exs:

config :paper_trail,
    repo: BalanceManager.Repo,
    item_type: Ecto.UUID,
    originator_type: Ecto.UUID,
    originator_relationship_options: [references: :uuid],
    strict_mode: false

This is my versions migrate:

defmodule Repo.Migrations.AddVersionsPaperTrail do
  use Ecto.Migration

  def change do
    create table(:versions) do
      add :event, :string, null: false, size: 10
      add :item_type, :string, null: false
      add :item_id, :binary_id
      add :item_changes, :map, null: false
      add :originator_id, :binary_id
      add :origin, :string, size: 50
      add :meta, :map

      # Configure timestamps type in config.ex :paper_trail :timestamps_type
      add :inserted_at, :utc_datetime, null: false
    end

    create index(:versions, [:originator_id])
    create index(:versions, [:item_id, :item_type])
    # Uncomment if you want to add the following indexes to speed up special queries:
    # create index(:versions, [:event, :item_type])
    # create index(:versions, [:item_type, :inserted_at])
  end
end

Can someone help me?

izelnakri commented 1 year ago

If you use the type uuid, your column name should be item_uuid unless specified otherwise in the settings.

izelnakri commented 1 year ago

Closing this issue based on my response and inactivity.