Packages
paper_trail
0.0.2
1.1.2
1.1.1
1.1.0
1.0.0
0.14.5
0.14.4
0.14.3
0.14.2
0.14.1
0.14.0
0.13.0
0.12.4
0.12.3
0.12.2
0.12.1
0.12.0
0.11.3
0.11.2
0.11.1
0.11.0
0.10.1
0.10.0
0.9.0
0.8.8
0.8.7
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.9
0.7.8
0.7.7
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.0
0.6.3
0.6.2
0.6.1
0.6.0
0.5.3
0.5.2
0.5.0
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
Track and record all the changes in your database. Revert back to anytime in history.
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/papertrail/install.ex
defmodule Mix.Tasks.Papertrail.Install do
@shortdoc "generates paper_trail migration file for your database"
import Macro, only: [camelize: 1, underscore: 1]
import Mix.Generator
use Mix.Task
def run(args) do
path = Path.relative_to("priv/repo/migrations", Mix.Project.app_path)
file = Path.join(path, "#{timestamp()}_#{underscore(AddVersions)}.exs")
create_directory path
create_file file, """
defmodule Repo.Migrations.AddVersions do
use Ecto.Migration
def change do
create table(:versions) do
add :event, :string
add :item_type, :string
add :item_id, :integer
add :item_changes, :map
add :meta, :map
add :originator, :string
add :inserted_at, :datetime, null: false
end
end
end
"""
end
defp timestamp do
{{y, m, d}, {hh, mm, ss}} = :calendar.universal_time()
"#{y}#{pad(m)}#{pad(d)}#{pad(hh)}#{pad(mm)}#{pad(ss)}"
end
defp pad(i) when i < 10, do: << ?0, ?0 + i >>
defp pad(i), do: to_string(i)
end