My space on the web https://inhji.de
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

24 lines
520 B

defmodule Mirage.Repo.Migrations.MigrateLinksToJoinTable do
use Ecto.Migration
import Ecto.Query
def change do
alter table(:links) do
add :domain, :string
end
execute(&link_join_up/0, &link_join_down/0)
end
def link_join_up() do
links =
repo().all(from(l in Mirage.Links.Link))
|> Enum.map(fn l -> %{note_id: l.note_id, link_id: l.id} end)
repo().insert_all("notes_links", links)
end
def link_join_down() do
repo().query!("DELETE FROM notes_links")
end
end