From be557afff52dd6f73aa14dbcbed5e8f7a74b1f3d Mon Sep 17 00:00:00 2001
From: Dariusz Kedzierski <dkedzierski@syncad.com>
Date: Wed, 17 Jun 2020 19:50:01 +0200
Subject: [PATCH] json_metadata can contain malformed json (yeah it sucks) so
 we need to hold it as text

---
 hive/db/schema.py                 | 2 +-
 hive/server/bridge_api/objects.py | 2 +-
 scripts/update_hivemind_db.sql    | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hive/db/schema.py b/hive/db/schema.py
index 9e4722be6..0b52f955b 100644
--- a/hive/db/schema.py
+++ b/hive/db/schema.py
@@ -170,7 +170,7 @@ def build_metadata():
         sa.Column('preview', VARCHAR(1024), nullable=False),
         sa.Column('img_url', VARCHAR(1024), nullable=False),
         sa.Column('body', TEXT),
-        sa.Column('json', sa.JSON)
+        sa.Column('json', TEXT)
     )
 
     sa.Table(
diff --git a/hive/server/bridge_api/objects.py b/hive/server/bridge_api/objects.py
index 400f21fd6..d324bb2fb 100644
--- a/hive/server/bridge_api/objects.py
+++ b/hive/server/bridge_api/objects.py
@@ -239,7 +239,7 @@ def _condenser_post_object(row, truncate_body=0):
 
     post['title'] = row['title']
     post['body'] = row['body'][0:truncate_body] if truncate_body else row['body']
-    post['json_metadata'] = json.loads(row['json'])
+    post['json_metadata'] = row['json']
 
     post['created'] = json_date(row['created_at'])
     post['updated'] = json_date(row['updated_at'])
diff --git a/scripts/update_hivemind_db.sql b/scripts/update_hivemind_db.sql
index f0a2db2ea..392b9276b 100644
--- a/scripts/update_hivemind_db.sql
+++ b/scripts/update_hivemind_db.sql
@@ -151,7 +151,7 @@ CREATE TABLE IF NOT EXISTS hive_post_data (
   preview VARCHAR(1024) NOT NULL,
   img_url VARCHAR(1024) NOT NULL,
   body TEXT,
-  json JSON
+  json TEXT
 );
 CREATE INDEX IF NOT EXISTS hive_post_data_id_idx ON hive_post_data (id);
 
@@ -221,7 +221,7 @@ UPDATE hive_posts_new hpn SET (
 
 -- Populate table hive_post_data with bulk data from hive_posts_cache
 -- RAISE NOTICE 'Populate table hive_post_data with bulk data from hive_posts_cache';
-INSERT INTO hive_post_data (id, title, preview, img_url, body, votes, json) SELECT post_id, title, preview, img_url, body, json::json FROM hive_posts_cache;
+INSERT INTO hive_post_data (id, title, preview, img_url, body, votes, json) SELECT post_id, title, preview, img_url, body, json FROM hive_posts_cache;
 
 -- Populate hive_votes table
 -- RAISE NOTICE 'Populate table hive_votes with bulk data from hive_posts_cache';
-- 
GitLab