An Elixir library to manage database views, functions and triggers - your database's familiars.
Creating a view is as simple as defining it in SQL and then creating it in a migration.
-- priv/repo/views/active_users_v1.sql
SELECT * FROM users
WHERE users.active
There's also a mix task to create a view with an incrementing version number.
mix familiar.gen.view active_users
# priv/repo/migrations/create_users_view.exs
defmodule Sample.Repo.Migrations.CreateViews do
use Ecto.Migration
use Familiar
def change do
create_view "active_users", version: 1
end
end
To update a view, simply create a new view definition and replace it
-- priv/repo/views/active_users_v2.sql
SELECT * FROM users
WHERE users.deactivated_at IS NULL
# priv/repo/migrations/create_users_view.exs
def change do
replace_view "active_users", version: 2, revert: 1
end
Familiar can be installed by adding familiar
to your list of dependencies in mix.exs
:
def deps do
[
{:familiar, "~> 0.1.1"}
]
end