Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR to track downstream changes in a fork #12

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c9d5b4a
Set PR template
valiotbot Nov 21, 2018
21aee94
remove uuid change to normal id
gdavila09 Nov 28, 2018
cd269fa
mix format
acrogenesis Dec 5, 2018
cf3d6f7
working tests
acrogenesis Dec 5, 2018
e179f9b
Merge pull request #1 from valiot/gdavila/TEAPP-30-uuid_to_id
acrogenesis Dec 5, 2018
bc17834
update deps
gdavila09 Dec 5, 2018
2ff19c1
removed updated at false
gdavila09 Dec 5, 2018
3b70013
Merge pull request #2 from valiot/gdavila/update-ecto
acrogenesis Dec 6, 2018
bade652
delete and log function
gdavila09 Dec 17, 2018
b1abcc1
Merge pull request #3 from valiot/gdavila/TEAPP-23-delete-and-log
acrogenesis Dec 19, 2018
f849298
remove unused variable
acrogenesis Jan 2, 2019
3df7d04
upsert in ecto trail
gdavila09 Jan 8, 2019
6bb34a0
remove dogma, update deps
acrogenesis Jan 16, 2019
28f5a56
fix Multi.run deprecation warning
acrogenesis Jan 16, 2019
8ee7d94
Merge pull request #4 from valiot/gdavila/TEAPP-70-upsert-log
acrogenesis Jan 16, 2019
b9348f2
passing tests
acrogenesis Jan 29, 2019
34f529a
log the type of change
gdavila09 Jan 24, 2019
d215432
changed type from created to insert
gdavila09 Jan 29, 2019
266442b
change enum to insert and test upsert
gdavila09 Jan 30, 2019
e5b6300
fix test
gdavila09 Jan 30, 2019
e93bc16
Merge pull request #5 from valiot/gdavila/TEAPP-84-log-type-change
acrogenesis Jan 30, 2019
eb43295
update de readme
gdavila09 Feb 20, 2019
4683628
Merge pull request #6 from valiot/gdavila/TEAPP-84-log-type-change
acrogenesis Feb 20, 2019
c36819b
rename ChangeEnum
acrogenesis Feb 21, 2019
bd1e1c0
update deps
acrogenesis Sep 30, 2021
641c2b2
update dialyxir
acrogenesis Sep 30, 2021
d2b4b85
redact custom fields from changeset
acrogenesis Sep 30, 2021
c926fe0
solve breaking change, redacted_fields not required
acrogenesis Sep 30, 2021
2c9cf3f
Merge pull request #8 from valiot/maintenance
gdavila09 Oct 2, 2021
f28fc13
change data structure for delete changesets
afloram Feb 21, 2022
d04bb25
update dependencies
afloram Feb 22, 2022
32cba31
Merge pull request #9 from valiot/alex/VAPP-136-format-for-delete-cha…
acrogenesis Mar 1, 2022
eec819c
Corral/log only (#10)
doctorcorral Nov 14, 2023
a8d8d77
remove unused vars
acrogenesis Nov 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Used by "mix format"
[
line_length: 110,
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a final \n at the end of each file.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ GitHub.sublime-settings
.tags_sorted_by_file
.vagrant
.DS_Store
.elixir_ls

# Ignore released binaries
.deliver
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ script:
- mix coveralls.travis --exclude pending
# Run static code analysis
- mix credo --strict
# Check code style
- mix dogma
77 changes: 40 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# EctoTrail

[![Hex.pm Downloads](https://img.shields.io/hexpm/dw/ecto_trail.svg?maxAge=3600)](https://hex.pm/packages/ecto_trail) [![Latest Version](https://img.shields.io/hexpm/v/ecto_trail.svg?maxAge=3600)](https://hex.pm/packages/ecto_trail) [![License](https://img.shields.io/hexpm/l/ecto_trail.svg?maxAge=3600)](https://hex.pm/packages/ecto_trail) [![Build Status](https://travis-ci.org/Nebo15/ecto_trail.svg?branch=master)](https://travis-ci.org/Nebo15/ecto_trail) [![Coverage Status](https://coveralls.io/repos/github/Nebo15/ecto_trail/badge.svg?branch=master)](https://coveralls.io/github/Nebo15/ecto_trail?branch=master) [![Ebert](https://ebertapp.io/github/Nebo15/ecto_trail.svg)](https://ebertapp.io/github/Nebo15/ecto_trail)

EctoTrail allows to store changeset changes into a separate `audit_log` table.
Expand All @@ -7,59 +8,61 @@ EctoTrail allows to store changeset changes into a separate `audit_log` table.

1. Add `ecto_trail` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[{:ecto_trail, "~> 0.2.0"}]
end
```
```elixir
def deps do
[{:ecto_trail, "~> 0.2.0"}]
end
```

2. Ensure `ecto_trail` is started before your application:

```elixir
def application do
[extra_applications: [:ecto_trail]]
end
```
```elixir
def application do
[extra_applications: [:ecto_trail]]
end
```

3. Add a migration that creates `audit_log` table to `priv/repo/migrations` folder:

```elixir
defmodule EctoTrail.TestRepo.Migrations.CreateAuditLogTable do
@moduledoc false
use Ecto.Migration

def change do
create table(:audit_log, primary_key: false) do
add :id, :uuid, primary_key: true
add :actor_id, :string, null: false
add :resource, :string, null: false
add :resource_id, :string, null: false
add :changeset, :map, null: false

timestamps([type: :utc_datetime, updated_at: false])
end
```elixir
defmodule EctoTrail.TestRepo.Migrations.CreateAuditLogTable do
@moduledoc false
use Ecto.Migration

@table_name String.to_atom(Application.fetch_env!(:ecto_trail, :table_name))

def change(table_name \\ @table_name) do
EctoTrailChangeEnum.create_type
create table(table_name) do
add :actor_id, :string, null: false
add :resource, :string, null: false
add :resource_id, :string, null: false
add :changeset, :map, null: false
add(:change_type, :change)

timestamps([type: :utc_datetime, updated_at: false])
end
end
```
end
```

4. Use `EctoTrail` in your repo:

```elixir
defmodule MyApp.Repo do
use Ecto.Repo, otp_app: :my_app
use EctoTrail
end
```
```elixir
defmodule MyApp.Repo do
use Ecto.Repo, otp_app: :my_app
use EctoTrail
end
```

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

```elixir
config :ecto_trail, table_name: "audit_log"
```
```elixir
config :ecto_trail, table_name: "audit_log", redacted_fields: [:password, :token]
```

6. Use logging functions instead of defaults. See `EctoTrail` module docs.

## Docs

The docs can be found at [https://hexdocs.pm/ecto_trail](https://hexdocs.pm/ecto_trail).

2 changes: 1 addition & 1 deletion config/.credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
checks: [
{Credo.Check.Design.TagTODO, exit_status: 0},
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 120},
{Credo.Check.Readability.Specs, exit_status: 0},
{Credo.Check.Readability.Specs, exit_status: 0}
]
}
]
Expand Down
3 changes: 1 addition & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use Mix.Config

config :ecto_trail,
table_name: "audit_log"
config :ecto_trail, table_name: "audit_log", redacted_fields: [:password]
13 changes: 0 additions & 13 deletions config/dogma.exs

This file was deleted.

12 changes: 6 additions & 6 deletions lib/ecto_trail/changelog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ defmodule EctoTrail.Changelog do
"""
use Ecto.Schema

@primary_key {:id, :binary_id, autogenerate: true}
schema Application.fetch_env!(:ecto_trail, :table_name) do
field :actor_id, :string
field :resource, :string
field :resource_id, :string
field :changeset, :map
field(:actor_id, :string)
field(:resource, :string)
field(:resource_id, :string)
field(:changeset, :map)
field(:change_type, EctoTrailChangeEnum)

timestamps([type: :utc_datetime, updated_at: false])
timestamps(type: :utc_datetime, updated_at: false)
end
end
Loading