1- defmodule EctoTrail do
1+ defmodule EctoTrailer do
22 @ moduledoc """
3- EctoTrail allows to store changeset changes into a separate `audit_log` table.
3+ EctoTrailer allows to store changeset changes into a separate `audit_log` table.
44
55 ## Usage
66
7- 1. Add `ecto_trail ` to your list of dependencies in `mix.exs`:
7+ 1. Add `ecto_trailer ` to your list of dependencies in `mix.exs`:
88
99 def deps do
10- [{:ecto_trail , "~> 0.1.0"}]
10+ [{:ecto_trailer , "~> 0.1.0"}]
1111 end
1212
13- 2. Ensure `ecto_trail` is started before your application :
13+ 2. Add a migration that creates `audit_log` table to `priv/repo/migrations` folder :
1414
15- def application do
16- [extra_applications: [:ecto_trail]]
17- end
18-
19- 3. Add a migration that creates `audit_log` table to `priv/repo/migrations` folder:
20-
21- defmodule EctoTrail.TestRepo.Migrations.CreateAuditLogTable do
15+ defmodule EctoTrailer.TestRepo.Migrations.CreateAuditLogTable do
2216 @moduledoc false
2317 use Ecto.Migration
2418
@@ -35,24 +29,24 @@ defmodule EctoTrail do
3529 end
3630 end
3731
38- 4. Use `EctoTrail ` in your repo:
32+ 4. Use `EctoTrailer ` in your repo:
3933
4034 defmodule MyApp.Repo do
4135 use Ecto.Repo, otp_app: :my_app
42- use EctoTrail
36+ use EctoTrailer
4337 end
4438
45- 5. Use logging functions instead of defaults. See `EctoTrail ` module docs.
39+ 5. Use logging functions instead of defaults. See `EctoTrailer ` module docs.
4640 """
4741 alias Ecto.Changeset
48- alias EctoTrail .Changelog
42+ alias EctoTrailer .Changelog
4943 alias Ecto.Multi
5044 require Logger
5145
5246 @ type action_type :: :insert | :update | :upsert | :delete
5347
5448 # Cache frequently accessed config to avoid repeated lookups
55- @ redacted_fields_config Application . compile_env ( :ecto_trail , :redacted_fields , nil )
49+ @ redacted_fields_config Application . compile_env ( :ecto_trailer , :redacted_fields , nil )
5650 @ changelog_fields [ :actor_id , :resource , :resource_id , :changeset , :change_type ]
5751 @ not_loaded_pattern "Ecto.Association.NotLoaded"
5852
@@ -70,7 +64,7 @@ defmodule EctoTrail do
7064 action_type :: action_type ( )
7165 ) :: { :ok , Ecto.Schema . t ( ) } | { :error , Ecto.Changeset . t ( ) }
7266 def log ( struct_or_changeset , changes , actor_id , action_type ) ,
73- do: EctoTrail . log ( __MODULE__ , struct_or_changeset , changes , actor_id , action_type )
67+ do: EctoTrailer . log ( __MODULE__ , struct_or_changeset , changes , actor_id , action_type )
7468
7569 @ doc """
7670 Store bulk changes in a `change_log` table.
@@ -82,7 +76,7 @@ defmodule EctoTrail do
8276 action_type :: action_type ( )
8377 ) :: :ok
8478 def log_bulk ( structs , changes , actor_id , action_type ) ,
85- do: EctoTrail . log_bulk ( __MODULE__ , structs , changes , actor_id , action_type )
79+ do: EctoTrailer . log_bulk ( __MODULE__ , structs , changes , actor_id , action_type )
8680
8781 @ doc """
8882 Call `c:Ecto.Repo.insert/2` operation and store changes in a `change_log` table.
@@ -95,7 +89,7 @@ defmodule EctoTrail do
9589 opts :: Keyword . t ( )
9690 ) :: { :ok , Ecto.Schema . t ( ) } | { :error , Ecto.Changeset . t ( ) }
9791 def insert_and_log ( struct_or_changeset , actor_id , opts \\ [ ] ) ,
98- do: EctoTrail . insert_and_log ( __MODULE__ , struct_or_changeset , actor_id , opts )
92+ do: EctoTrailer . insert_and_log ( __MODULE__ , struct_or_changeset , actor_id , opts )
9993
10094 @ doc """
10195 Call `c:Ecto.Repo.update/2` operation and store changes in a `change_log` table.
@@ -110,7 +104,7 @@ defmodule EctoTrail do
110104 { :ok , Ecto.Schema . t ( ) }
111105 | { :error , Ecto.Changeset . t ( ) }
112106 def update_and_log ( changeset , actor_id , opts \\ [ ] ) ,
113- do: EctoTrail . update_and_log ( __MODULE__ , changeset , actor_id , opts )
107+ do: EctoTrailer . update_and_log ( __MODULE__ , changeset , actor_id , opts )
114108
115109 @ doc """
116110 Call `c:Ecto.Repo.upsert/2` operation and store changes in a `change_log` table.
@@ -125,7 +119,7 @@ defmodule EctoTrail do
125119 { :ok , Ecto.Schema . t ( ) }
126120 | { :error , Ecto.Changeset . t ( ) }
127121 def upsert_and_log ( struct_or_changeset , actor_id , opts \\ [ ] ) ,
128- do: EctoTrail . upsert_and_log ( __MODULE__ , struct_or_changeset , actor_id , opts )
122+ do: EctoTrailer . upsert_and_log ( __MODULE__ , struct_or_changeset , actor_id , opts )
129123
130124 @ doc """
131125 Call `c:Ecto.Repo.delete/2` operation and store deleted objext in a `change_log` table.
@@ -138,7 +132,7 @@ defmodule EctoTrail do
138132 { :ok , Ecto.Schema . t ( ) }
139133 | { :error , Ecto.Changeset . t ( ) }
140134 def delete_and_log ( struct_or_changeset , actor_id , opts \\ [ ] ) ,
141- do: EctoTrail . delete_and_log ( __MODULE__ , struct_or_changeset , actor_id , opts )
135+ do: EctoTrailer . delete_and_log ( __MODULE__ , struct_or_changeset , actor_id , opts )
142136 end
143137 end
144138
0 commit comments