add ON DELETE to relations

pull/1/head
Tao Bror Bojlén 2019-08-09 20:30:22 +03:00
rodzic 3320e050c8
commit b2e849cf9f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: C6EC7AAB905F9E6F
1 zmienionych plików z 40 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,40 @@
defmodule Backend.Repo.Migrations.AddOnDeletes do
use Ecto.Migration
def change do
# Add ON DELETE CASCADE to foreign key relations.
# crawls -> instances
execute("ALTER TABLE crawls DROP CONSTRAINT crawls_instance_domain_fkey")
execute(
"ALTER TABLE crawls ADD CONSTRAINT crawls_instance_domain_fkey FOREIGN KEY (instance_domain) REFERENCES instances(domain) ON DELETE CASCADE"
)
# instance_peers -> instances
execute("ALTER TABLE instance_peers DROP CONSTRAINT instance_peers_source_domain_fkey")
execute(
"ALTER TABLE instance_peers ADD CONSTRAINT instance_peers_source_domain_fkey FOREIGN KEY (source_domain) REFERENCES instances(domain) ON DELETE CASCADE"
)
execute("ALTER TABLE instance_peers DROP CONSTRAINT instance_peers_target_domain_fkey")
execute(
"ALTER TABLE instance_peers ADD CONSTRAINT instance_peers_target_domain_fkey FOREIGN KEY (target_domain) REFERENCES instances(domain) ON DELETE CASCADE"
)
# edges -> instances
execute("ALTER TABLE edges DROP CONSTRAINT edges_source_domain_fkey")
execute(
"ALTER TABLE edges ADD CONSTRAINT edges_source_domain_fkey FOREIGN KEY (source_domain) REFERENCES instances(domain) ON DELETE CASCADE"
)
execute("ALTER TABLE edges DROP CONSTRAINT edges_target_domain_fkey")
execute(
"ALTER TABLE edges ADD CONSTRAINT edges_target_domain_fkey FOREIGN KEY (target_domain) REFERENCES instances(domain) ON DELETE CASCADE"
)
end
end