Skip to content

Instantly share code, notes, and snippets.

@taybin
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taybin/ffc8c18f9c8459f5f47a to your computer and use it in GitHub Desktop.
Save taybin/ffc8c18f9c8459f5f47a to your computer and use it in GitHub Desktop.
ecto node migration
defmodule Repo.Migrations.CreateNodes do
use Ecto.Migration
def up do
[
"CREATE TABLE IF NOT EXISTS nodes(id SERIAL PRIMARY KEY, name TEXT NOT NULL, script TEXT)",
"CREATE TABLE IF NOT EXISTS node_to_node(parent_id INTEGER NOT NULL REFERENCES nodes(id) ON DELETE CASCADE, child_id INTEGER NOT NULL REFERENCES nodes(id) ON DELETE CASCADE)"
]
end
def down do
[
"DROP TABLE node_to_node",
"DROP TABLE nodes"
]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment