Skip to content

Commit 9b84f29

Browse files
committed
Feat: rename package to "ecto_trailer".
Problem: - the original package from Nebo15 (https://github.com/Nebo15/ecto_trail) seems barely supported - the PR to merge the fork from Valiot is stuck in limbo (Nebo15/ecto_trail#12) - the improvements from Valiot are not releases on Hex (and there are some API differences from the original package) Solution: - lets change the name and release an actively maintained package - ecto_trailer is available and seems OK for an alternative implementation
1 parent ee93aa3 commit 9b84f29

15 files changed

Lines changed: 46 additions & 59 deletions

README.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,19 @@ EctoTrail allows to store changeset changes into a separate `audit_log` table.
1010

1111
```elixir
1212
def deps do
13-
[{:ecto_trail, "~> 0.2.0"}]
13+
[{:ecto_trailer, "~> 0.2.0"}]
1414
end
1515
```
1616

17-
2. Ensure `ecto_trail` is started before your application:
1817

19-
```elixir
20-
def application do
21-
[extra_applications: [:ecto_trail]]
22-
end
23-
```
24-
25-
3. Add a migration that creates `audit_log` table to `priv/repo/migrations` folder:
18+
2. Add a migration that creates `audit_log` table to `priv/repo/migrations` folder:
2619

2720
```elixir
28-
defmodule EctoTrail.TestRepo.Migrations.CreateAuditLogTable do
21+
defmodule EctoTrailer.TestRepo.Migrations.CreateAuditLogTable do
2922
@moduledoc false
3023
use Ecto.Migration
3124

32-
@table_name String.to_atom(Application.compile_env(:ecto_trail, :table_name, "audit_log"))
25+
@table_name String.to_atom(Application.compile_env(:ecto_trailer, :table_name, "audit_log"))
3326

3427
def change(table_name \\ @table_name) do
3528
EctoTrailChangeEnum.create_type
@@ -51,17 +44,17 @@ end
5144
```elixir
5245
defmodule MyApp.Repo do
5346
use Ecto.Repo, otp_app: :my_app
54-
use EctoTrail
47+
use EctoTrailer
5548
end
5649
```
5750

5851
5. Configure table name which is used to store audit log (in `config.ex`):
5952

6053
```elixir
61-
config :ecto_trail, table_name: "audit_log", redacted_fields: [:password, :token]
54+
config :ecto_trailer, table_name: "audit_log", redacted_fields: [:password, :token]
6255
```
6356

64-
6. Use logging functions instead of defaults. See `EctoTrail` module docs.
57+
6. Use logging functions instead of defaults. See `EctoTrailer` module docs.
6558

6659
## Docs
6760

benchmark/ecto_trail_benchmark.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Mix.env(:test)
88
Application.ensure_all_started(:postgrex)
99
Application.ensure_all_started(:ecto)
1010

11-
alias EctoTrail.TestRepo
11+
alias EctoTrailer.TestRepo
1212
alias Ecto.Changeset
1313

1414
# Ensure the repo is started and create tables

config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import Config
22

3-
config :ecto_trail, table_name: "audit_log", redacted_fields: [:password]
3+
config :ecto_trailer, table_name: "audit_log", redacted_fields: [:password]

lib/ecto_trail/changelog.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
defmodule EctoTrail.Changelog do
1+
defmodule EctoTrailer.Changelog do
22
@moduledoc """
33
This is schema that used to store changes in DB.
44
"""
55
use Ecto.Schema
66

7-
@table_name Application.compile_env(:ecto_trail, :table_name, "audit_log")
7+
@table_name Application.compile_env(:ecto_trailer, :table_name, "audit_log")
88
schema @table_name do
99
field(:actor_id, :string)
1010
field(:resource, :string)

lib/ecto_trail/ecto_trail.ex

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
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

mix.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
defmodule EctoTrail.Mixfile do
1+
defmodule EctoTrailer.Mixfile do
22
use Mix.Project
33

44
@version "1.0.0"
55

66
def project do
77
[
8-
app: :ecto_trail,
8+
app: :ecto_trailer,
99
description: description(),
1010
package: package(),
1111
version: @version,
@@ -48,7 +48,7 @@ defmodule EctoTrail.Mixfile do
4848
contributors: ["Valiot, Nebo #15"],
4949
maintainers: ["Valiot"],
5050
licenses: ["LICENSE.md"],
51-
links: %{github: "https://github.com/Valiot/ecto_trail"},
51+
links: %{github: "https://github.com/maxohq/ecto_trailer"},
5252
files: ~w(lib LICENSE.md mix.exs README.md)
5353
]
5454
end

priv/repo/migrations/20170419082821_create_log_changes_table.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
defmodule EctoTrail.TestRepo.Migrations.CreateAuditLogTable do
1+
defmodule EctoTrailer.TestRepo.Migrations.CreateAuditLogTable do
22
@moduledoc false
33
use Ecto.Migration
44

5-
@table_name String.to_atom(Application.fetch_env!(:ecto_trail, :table_name))
5+
@table_name String.to_atom(Application.fetch_env!(:ecto_trailer, :table_name))
66

77
def change(table_name \\ @table_name) do
88
EctoTrailChangeEnum.create_type

priv/repo/migrations/20170419082822_create_resources_table.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule EctoTrail.TestRepo.Migrations.CreateResourcesTable do
1+
defmodule EctoTrailer.TestRepo.Migrations.CreateResourcesTable do
22
@moduledoc false
33
use Ecto.Migration
44

priv/repo/migrations/20170621091222_add_items_into_resource_table.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule EctoTrail.TestRepo.Migrations.AddItemsIntoResourcesTable do
1+
defmodule EctoTrailer.TestRepo.Migrations.AddItemsIntoResourcesTable do
22
@moduledoc false
33
use Ecto.Migration
44

priv/repo/migrations/20170621091223_create_comments_and_categories_tables.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule EctoTrail.TestRepo.Migrations.CreateCommentsAndCategoriesTables do
1+
defmodule EctoTrailer.TestRepo.Migrations.CreateCommentsAndCategoriesTables do
22
@moduledoc false
33
use Ecto.Migration
44

0 commit comments

Comments
 (0)