-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial tests on actual paper_trail directory similar to the ones on …
…examples
- Loading branch information
Showing
14 changed files
with
315 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use Mix.Config | ||
|
||
config :paper_trail, ecto_repos: [Repo] | ||
|
||
config :paper_trail, Repo, | ||
adapter: Ecto.Adapters.Postgres, | ||
username: "postgres", | ||
password: "postgres", | ||
database: "paper_trail_test", | ||
hostname: "localhost", | ||
poolsize: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule PaperTrail.Migration do | ||
# TODO: this module will handle column changes in database schemas. It will query legacy column names | ||
# and change the legacy column names to new column names in every :item_changes field of a PaperTrail.Version | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
defmodule PaperTrail.VersionQueries do | ||
import Ecto.Query | ||
alias PaperTrail.Version | ||
|
||
|
||
@doc """ | ||
Gets all the versions of a record given a module and its id | ||
""" | ||
def get_versions(model, id) do | ||
item_type = model |> Module.split |> List.last | ||
version_query(item_type, id) |> Repo.all | ||
end | ||
|
||
@doc """ | ||
Gets all the versions of a record | ||
""" | ||
def get_versions(record) do | ||
item_type = record.__struct__ |> Module.split |> List.last | ||
version_query(item_type, record.id) |> Repo.all | ||
end | ||
|
||
@doc """ | ||
Gets the last version of a record given its module reference and its id | ||
""" | ||
def get_version(model, id) do | ||
item_type = Module.split(model) |> List.last | ||
last(version_query(item_type, id)) |> Repo.one | ||
end | ||
|
||
@doc """ | ||
Gets the last version of a record | ||
""" | ||
def get_version(record) do | ||
item_type = record.__struct__ |> Module.split |> List.last | ||
last(version_query(item_type, record.id)) |> Repo.one | ||
end | ||
|
||
defp version_query(item_type, id) do | ||
from v in Version, | ||
where: v.item_type == ^item_type and v.item_id == ^id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.