2019-02-14 14:19:55 +01:00
|
|
|
defmodule Mobilizon.Repo.Migrations.TagsRelations do
|
|
|
|
use Ecto.Migration
|
|
|
|
|
|
|
|
def up do
|
|
|
|
create table(:tag_relations, primary_key: false) do
|
2019-02-22 14:18:52 +01:00
|
|
|
add(:tag_id, references(:tags, on_delete: :delete_all), null: false, primary_key: true)
|
|
|
|
add(:link_id, references(:tags, on_delete: :delete_all), null: false, primary_key: true)
|
|
|
|
add(:weight, :integer, null: false, default: 1)
|
2019-02-14 14:19:55 +01:00
|
|
|
end
|
2019-02-22 14:18:52 +01:00
|
|
|
|
|
|
|
create(constraint(:tag_relations, :no_self_loops_check, check: "tag_id <> link_id"))
|
|
|
|
create(index(:tag_relations, [:tag_id], name: :index_tag_relations_tag_id))
|
|
|
|
create(index(:tag_relations, [:link_id], name: :index_tag_relations_link_id))
|
2019-02-14 14:19:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def down do
|
2019-02-22 14:18:52 +01:00
|
|
|
drop(constraint(:tag_relations, :no_self_loops_check))
|
2019-02-14 14:19:55 +01:00
|
|
|
|
2019-02-22 14:18:52 +01:00
|
|
|
drop(index(:tag_relations, [:tags_id]))
|
|
|
|
drop(index(:tag_relations, [:link_id]))
|
|
|
|
drop(table(:tag_relations))
|
2019-02-14 14:19:55 +01:00
|
|
|
end
|
|
|
|
end
|