EctoTemp
EctoTemp is an Ecto extension to support using PostgreSQL temporary tables with Ecto. This can be useful in situations where permanent tables may not be viable, such as when testing data migrations (where the schema at the time of test creation will differ over time), or to test modules that extend Ecto, but are not concernted with a specific schema.
This library is tested against the most recent 3 versions of Elixir and Erlang.
Installation
Add ecto_temp to mix.exs. Consider only adding it to the :test environment.
def deps do
[
{:ecto_temp, "~> 1.2", only: :test}
]
endUsage
EctoTemp provides several macros which can be included by useing EctoTemp.
defmodule MyTest do
use MyProject.DataCase
use EctoTemp, repo: MyProject.Repo
require EctoTemp.Factory
alias EctoTemp.Factory
deftemptable :things do
column :data, :string, null: false
column :data_with_default, :string, default: "default value"
deftimestamps()
end
setup do
create_temp_tables()
:ok
end
test "insert records" do
Factory.insert(:things, data: "stuff")
end
end