Need database-level assurance that certain records are immutable—that is to
say, unable to be UPDATE
d once INSERT
ed? Mutiny is glad to oblige.
Mutiny is available on Hex and can be installed by
adding mutiny
to your list of dependencies in mix.exs
:
def deps do
[
{:mutiny, "~> 0.1.0"}
]
end
Check the documentation for full details.
Mutiny generates SQL commands for you and is designed to be used in conjunction with Ecto SQL migrations.
First off, you'll want to create the database function that Mutiny calls. Mutiny can generate a migration for you that will do just that:
mix mutiny.gen.migration postgres
mix ecto.migrate
If you'd rather write the migration yourself, take a look at
Mutiny.create_prevent_update_function/0
and
Mutiny.drop_prevent_update_function/0
.
Now you're ready to use
Mutiny in your migrations:
defmodule MyApp.Repo.Migrations.CreateSnapshots do
use Ecto.Migration
use Mutiny, adapter: Mutiny.Adapters.Postgres
def change do
create table("snapshots") do
add :data, :map
add :last_viewed, :utc_datetime
end
table("snapshots")
|> protect(:data)
|> execute()
end
end
Contributions are welcome! To make changes, clone the repo, make sure tests pass, and then open a PR on GitHub.
git clone https://github.com/newaperio/mutiny.git
cd mutiny
mix deps.get
mix test
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Mutiny is Copyright © 2020 NewAperio. It is free software, and may be redistributed under the terms specified in the LICENSE file.
Mutiny is built by NewAperio, LLC.
NewAperio is a web and mobile design and development studio. We offer expert Elixir and Phoenix development as part of our portfolio of services. Get in touch to see how our team can help you.