From a7b34173ddbf1dfea6899a2cc9935f8cd90725a4 Mon Sep 17 00:00:00 2001
From: Bat <baptiste@gelez.xyz>
Date: Fri, 7 Sep 2018 23:01:53 +0100
Subject: [PATCH] Don't delete account with avatar

Fixes #200
---
 migrations/2018-09-07-212003_fix_avatar_deletion/down.sql | 7 +++++++
 migrations/2018-09-07-212003_fix_avatar_deletion/up.sql   | 7 +++++++
 2 files changed, 14 insertions(+)
 create mode 100644 migrations/2018-09-07-212003_fix_avatar_deletion/down.sql
 create mode 100644 migrations/2018-09-07-212003_fix_avatar_deletion/up.sql

diff --git a/migrations/2018-09-07-212003_fix_avatar_deletion/down.sql b/migrations/2018-09-07-212003_fix_avatar_deletion/down.sql
new file mode 100644
index 00000000..a3f0047d
--- /dev/null
+++ b/migrations/2018-09-07-212003_fix_avatar_deletion/down.sql
@@ -0,0 +1,7 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE users
+    DROP CONSTRAINT users_avatar_id_fkey,
+    ADD CONSTRAINT users_avatar_id_fkey
+    FOREIGN KEY (avatar_id)
+    REFERENCES medias(id)
+    ON DELETE CASCADE;
diff --git a/migrations/2018-09-07-212003_fix_avatar_deletion/up.sql b/migrations/2018-09-07-212003_fix_avatar_deletion/up.sql
new file mode 100644
index 00000000..780af5ab
--- /dev/null
+++ b/migrations/2018-09-07-212003_fix_avatar_deletion/up.sql
@@ -0,0 +1,7 @@
+-- Your SQL goes here
+ALTER TABLE users
+    DROP CONSTRAINT users_avatar_id_fkey,
+    ADD CONSTRAINT users_avatar_id_fkey
+    FOREIGN KEY (avatar_id)
+    REFERENCES medias(id)
+    ON DELETE SET NULL;