From 817b4ff08ec162a3600285904667a7ffc439608b Mon Sep 17 00:00:00 2001
From: Dessalines <tyhou13@gmx.com>
Date: Wed, 3 Mar 2021 23:40:00 -0500
Subject: [PATCH] Fixing wrong user_ and community icon and banner urls.

- Fixes #1477
---
 docker/dev/volume_mount.dockerfile                    | 2 ++
 migrations/2021-03-04-040229_clean_icon_urls/down.sql | 3 +++
 migrations/2021-03-04-040229_clean_icon_urls/up.sql   | 5 +++++
 3 files changed, 10 insertions(+)
 create mode 100644 migrations/2021-03-04-040229_clean_icon_urls/down.sql
 create mode 100644 migrations/2021-03-04-040229_clean_icon_urls/up.sql

diff --git a/docker/dev/volume_mount.dockerfile b/docker/dev/volume_mount.dockerfile
index 62d77fa3..0cb03624 100644
--- a/docker/dev/volume_mount.dockerfile
+++ b/docker/dev/volume_mount.dockerfile
@@ -1,4 +1,6 @@
 # syntax=docker/dockerfile:experimental
+
+# Warning: this will not pick up migrations unless there are code changes
 FROM rust:1.50-buster as rust
 
 ENV HOME=/home/root
diff --git a/migrations/2021-03-04-040229_clean_icon_urls/down.sql b/migrations/2021-03-04-040229_clean_icon_urls/down.sql
new file mode 100644
index 00000000..f866b155
--- /dev/null
+++ b/migrations/2021-03-04-040229_clean_icon_urls/down.sql
@@ -0,0 +1,3 @@
+-- This is a clean-up migration that cannot be undone,
+-- but Diesel requires a non-empty script so run a no-op.
+SELECT 1;
diff --git a/migrations/2021-03-04-040229_clean_icon_urls/up.sql b/migrations/2021-03-04-040229_clean_icon_urls/up.sql
new file mode 100644
index 00000000..8b22b33f
--- /dev/null
+++ b/migrations/2021-03-04-040229_clean_icon_urls/up.sql
@@ -0,0 +1,5 @@
+-- If these are not urls, it will crash the server
+update user_ set avatar = NULL where avatar not like 'http%';
+update user_ set banner = NULL where banner not like 'http%';
+update community set icon = NULL where icon not like 'http%';
+update community set banner = NULL where banner not like 'http%';
-- 
2.44.1