diff --git a/config/config.exs b/config/config.exs index 3e0640b3..d26f12bd 100644 --- a/config/config.exs +++ b/config/config.exs @@ -2,6 +2,7 @@ # and its dependencies with the aid of the Mix.Config module. use Mix.Config +# config :paper_trail, ecto_repos: [] # This configuration is loaded before any dependency and is restricted # to this project. If another project depends on this project, this # file won't be loaded nor affect the parent project. For this reason, diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 00000000..6e1db0f1 --- /dev/null +++ b/example/.gitignore @@ -0,0 +1,17 @@ +# The directory Mix will write compiled artifacts to. +/_build + +# If you run "mix test --cover", coverage assets end up here. +/cover + +# The directory Mix downloads your dependencies sources to. +/deps + +# Where 3rd-party dependencies like ExDoc output generated docs. +/doc + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez diff --git a/example/README.md b/example/README.md new file mode 100644 index 00000000..0780bdb0 --- /dev/null +++ b/example/README.md @@ -0,0 +1,24 @@ +# Example + +**TODO: Add description** + +## Installation + +If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: + + 1. Add `example` to your list of dependencies in `mix.exs`: + + ```elixir + def deps do + [{:example, "~> 0.1.0"}] + end + ``` + + 2. Ensure `example` is started before your application: + + ```elixir + def application do + [applications: [:example]] + end + ``` + diff --git a/example/config/config.exs b/example/config/config.exs new file mode 100644 index 00000000..6db7ac79 --- /dev/null +++ b/example/config/config.exs @@ -0,0 +1,38 @@ +# This file is responsible for configuring your application +# and its dependencies with the aid of the Mix.Config module. +use Mix.Config + +config :example, ecto_repos: [Example.Repo] + +config :example, Example.Repo, + adapter: Ecto.Adapters.Postgres, + database: "papertrail_example", + username: "postgres", + password: "postgres" + +# This configuration is loaded before any dependency and is restricted +# to this project. If another project depends on this project, this +# file won't be loaded nor affect the parent project. For this reason, +# if you want to provide default values for your application for +# 3rd-party users, it should be done in your "mix.exs" file. + +# You can configure for your application as: +# +# config :example, key: :value +# +# And access this configuration in your application as: +# +# Application.get_env(:example, :key) +# +# Or configure a 3rd-party app: +# +# config :logger, level: :info +# + +# It is also possible to import configuration files, relative to this +# directory. For example, you can emulate configuration per environment +# by uncommenting the line below and defining dev.exs, test.exs and such. +# Configuration from the imported file will override the ones defined +# here (which is why it is important to import them last). +# +# import_config "#{Mix.env}.exs" diff --git a/example/lib/company.ex b/example/lib/company.ex new file mode 100644 index 00000000..392197e0 --- /dev/null +++ b/example/lib/company.ex @@ -0,0 +1,28 @@ +defmodule Company do + use Ecto.Schema + + import Ecto + import Ecto.Changeset + import Ecto.Query + + schema "companies" do + field :name, :string + field :is_active, :boolean + field :website, :string + field :city, :string + field :address, :string + field :facebook, :string + field :twitter, :string + field :founded_in, :string + + timestamps + end + + @required_fields ~w() + @optional_fields ~w() + + def changeset(model, params \\ :empty) do + model + |> cast(params, @required_fields, @optional_fields) + end +end diff --git a/example/lib/example.ex b/example/lib/example.ex new file mode 100644 index 00000000..49144f27 --- /dev/null +++ b/example/lib/example.ex @@ -0,0 +1,3 @@ +defmodule Example.Repo do + use Ecto.Repo, otp_app: :example +end diff --git a/example/lib/person.ex b/example/lib/person.ex new file mode 100644 index 00000000..130fd134 --- /dev/null +++ b/example/lib/person.ex @@ -0,0 +1,25 @@ +defmodule Person do + use Ecto.Schema + + import Ecto + import Ecto.Changeset + import Ecto.Query + + schema "people" do + field :first_name, :string + field :last_name, :string + field :visit_count, :integer + field :gender, :boolean + field :birthdate, Ecto.Date + + timestamps + end + + @required_fields ~w() + @optional_fields ~w() + + def changeset(model, params \\ :empty) do + model + |> cast(params, @required_fields, @optional_fields) + end +end diff --git a/example/mix.exs b/example/mix.exs new file mode 100644 index 00000000..8cf9e0bc --- /dev/null +++ b/example/mix.exs @@ -0,0 +1,36 @@ +defmodule Example.Mixfile do + use Mix.Project + + def project do + [app: :example, + version: "0.1.0", + elixir: "~> 1.3", + build_embedded: Mix.env == :prod, + start_permanent: Mix.env == :prod, + deps: deps()] + end + + # Configuration for the OTP application + # + # Type "mix help compile.app" for more information + def application do + [applications: [:logger, :postgrex, :ecto]] + end + + # Dependencies can be Hex packages: + # + # {:mydep, "~> 0.3.0"} + # + # Or git/path repositories: + # + # {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"} + # + # Type "mix help deps" for more examples and options + defp deps do + [ + {:postgrex, ">= 0.0.0"}, + {:ecto, "~> 2.0.2"}, + {:poison, "2.1.0"} + ] + end +end diff --git a/example/mix.lock b/example/mix.lock new file mode 100644 index 00000000..d47a9026 --- /dev/null +++ b/example/mix.lock @@ -0,0 +1,7 @@ +%{"connection": {:hex, :connection, "1.0.3", "3145f7416be3df248a4935f24e3221dc467c1e3a158d62015b35bd54da365786", [:mix], []}, + "db_connection": {:hex, :db_connection, "1.0.0-rc.3", "d9ceb670fe300271140af46d357b669983cd16bc0d01206d7d3222dde56cf038", [:mix], [{:sbroker, "~> 1.0.0-beta.3", [hex: :sbroker, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:connection, "~> 1.0.2", [hex: :connection, optional: false]}]}, + "decimal": {:hex, :decimal, "1.1.2", "79a769d4657b2d537b51ef3c02d29ab7141d2b486b516c109642d453ee08e00c", [:mix], []}, + "ecto": {:hex, :ecto, "2.0.2", "b02331c1f20bbe944dbd33c8ecd8f1ccffecc02e344c4471a891baf3a25f5406", [:mix], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: true]}, {:sbroker, "~> 1.0-beta", [hex: :sbroker, optional: true]}, {:mariaex, "~> 0.7.7", [hex: :mariaex, optional: true]}, {:postgrex, "~> 0.11.2", [hex: :postgrex, optional: true]}, {:db_connection, "~> 1.0-rc.2", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}]}, + "poison": {:hex, :poison, "2.1.0", "f583218ced822675e484648fa26c933d621373f01c6c76bd00005d7bd4b82e27", [:mix], []}, + "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []}, + "postgrex": {:hex, :postgrex, "0.11.2", "139755c1359d3c5c6d6e8b1ea72556d39e2746f61c6ddfb442813c91f53487e8", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.0-rc", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}} diff --git a/example/priv/repo/migrations/20160715113434_create_versions.exs b/example/priv/repo/migrations/20160715113434_create_versions.exs new file mode 100644 index 00000000..002bb55f --- /dev/null +++ b/example/priv/repo/migrations/20160715113434_create_versions.exs @@ -0,0 +1,16 @@ +defmodule Example.Repo.Migrations.CreateVersions 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 diff --git a/example/priv/repo/migrations/20160715113439_create_companies.exs b/example/priv/repo/migrations/20160715113439_create_companies.exs new file mode 100644 index 00000000..35f3fc1c --- /dev/null +++ b/example/priv/repo/migrations/20160715113439_create_companies.exs @@ -0,0 +1,18 @@ +defmodule Example.Repo.Migrations.CreateCompanies do + use Ecto.Migration + + def change do + create table(:companies) do + add :name, :string + add :is_active, :string + add :website, :string + add :city, :string + add :address, :string + add :facebook, :string + add :twitter, :string + add :founded_in, :string + + timestamps + end + end +end diff --git a/example/priv/repo/migrations/20160715113442_create_people.exs b/example/priv/repo/migrations/20160715113442_create_people.exs new file mode 100644 index 00000000..72822dd3 --- /dev/null +++ b/example/priv/repo/migrations/20160715113442_create_people.exs @@ -0,0 +1,15 @@ +defmodule Example.Repo.Migrations.CreatePeople do + use Ecto.Migration + + def change do + create table(:people) do + add :first_name, :string + add :last_name, :string + add :visit_count, :integer + add :gender, :boolean + add :birthdate, :date + + timestamps + end + end +end diff --git a/example/test/example_test.exs b/example/test/example_test.exs new file mode 100644 index 00000000..b65fc3c4 --- /dev/null +++ b/example/test/example_test.exs @@ -0,0 +1,8 @@ +defmodule ExampleTest do + use ExUnit.Case + doctest Example + + test "the truth" do + assert 1 + 1 == 2 + end +end diff --git a/example/test/test_helper.exs b/example/test/test_helper.exs new file mode 100644 index 00000000..869559e7 --- /dev/null +++ b/example/test/test_helper.exs @@ -0,0 +1 @@ +ExUnit.start() diff --git a/priv/repo/migrations/20160619190937_add_companies.exs b/priv/repo/migrations/20160619190937_add_companies.exs new file mode 100644 index 00000000..e2f0549f --- /dev/null +++ b/priv/repo/migrations/20160619190937_add_companies.exs @@ -0,0 +1,18 @@ +defmodule Repo.Migrations.AddCompanies do + use Ecto.Migration + + def change do + create table(:companies) do + add :name, :string + add :is_active, :string + add :website, :string + add :city, :string + add :address, :string + add :facebook, :string + add :twitter, :string + add :founded_in, :string + + timestamps + end + end +end diff --git a/priv/repo/migrations/20160619190938_add_people.exs b/priv/repo/migrations/20160619190938_add_people.exs new file mode 100644 index 00000000..df486fb1 --- /dev/null +++ b/priv/repo/migrations/20160619190938_add_people.exs @@ -0,0 +1,15 @@ +defmodule Repo.Migrations.AddPeople do + use Ecto.Migration + + def change do + create table(:people) do + add :first_name, :string + add :last_name, :string + add :visit_count, :integer + add :gender, :boolean + add :birthdate, :date + + timestamps + end + end +end diff --git a/test/paper_trail_test.exs b/test/paper_trail_test.exs index 9a0d12a0..565eb4c7 100644 --- a/test/paper_trail_test.exs +++ b/test/paper_trail_test.exs @@ -21,6 +21,14 @@ defmodule PaperTrailTest do timestamps end + + @required_fields ~w() + @optional_fields ~w() + + def changeset(model, params \\ :empty) do + model + |> cast(params, @required_fields, @optional_fields) + end end defmodule Person do @@ -39,9 +47,17 @@ defmodule PaperTrailTest do timestamps end + + @required_fields ~w() + @optional_fields ~w() + + def changeset(model, params \\ :empty) do + model + |> cast(params, @required_fields, @optional_fields) + end end - test "the truth" do + test "" do assert 1 + 1 == 2 end end