diff --git a/hive/db/schema.py b/hive/db/schema.py index 605e8f4d202d8ef955ac58e4752c63759cacfda2..ad6dec1cc47130101822c16a338bf73126c12422 100644 --- a/hive/db/schema.py +++ b/hive/db/schema.py @@ -165,7 +165,6 @@ def build_metadata(): sa.Column('preview', VARCHAR(1024), nullable=False), sa.Column('img_url', VARCHAR(1024), nullable=False), sa.Column('body', TEXT), - sa.Column('votes', TEXT), sa.Column('json', sa.JSON) ) diff --git a/hive/indexer/votes.py b/hive/indexer/votes.py index 9ff633d8e14c8379c3e30ac79f4a59436e82063d..0bd2dc8bfbbafb5ed6501dae191b6df8352b2e93 100644 --- a/hive/indexer/votes.py +++ b/hive/indexer/votes.py @@ -84,4 +84,3 @@ class Votes: rshares = 0 DB.query(sql, weight=weight, rshares=rshares, vote_percent=vote_percent, last_update=date, id=vote_id) - diff --git a/scripts/update_hivemind_db.sql b/scripts/update_hivemind_db.sql index c99b5b1ea4a067d3bb359e151ab6883671a14d3c..10b2c484f9ed1f2579502a1975ce87757d196616 100644 --- a/scripts/update_hivemind_db.sql +++ b/scripts/update_hivemind_db.sql @@ -146,7 +146,6 @@ CREATE TABLE IF NOT EXISTS hive_post_data ( preview VARCHAR(1024) NOT NULL, img_url VARCHAR(1024) NOT NULL, body TEXT, - votes TEXT, json JSON ); CREATE INDEX IF NOT EXISTS hive_post_data_id_idx ON hive_post_data (id); @@ -215,7 +214,26 @@ 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, votes, 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::json FROM hive_posts_cache; + +-- Populate hive_votes table +-- RAISE NOTICE 'Populate table hive_votes with bulk data from hive_posts_cache'; +INSERT INTO + hive_votes (voter_id, author_id, permlink_id, rshares, vote_percent) +SELECT + (SELECT id from hive_accounts WHERE name = vote_data.regexp_split_to_array[1]) AS voter_id, + (SELECT author_id FROM hive_posts WHERE id = vote_data.id) AS author_id, + (SELECT permlink_id FROM hive_posts WHERE id = vote_data.id) AS permlink_id, + (vote_data.regexp_split_to_array[2])::bigint AS rshares, + (vote_data.regexp_split_to_array[3])::int AS vote_percent +FROM + (SELECT + votes.id, regexp_split_to_array(votes.regexp_split_to_table::text, E',') + FROM + (SELECT id, regexp_split_to_table(votes::text, E'\n') + FROM hive_posts_cache) + AS votes) +AS vote_data; -- Helper type for use with json_populate_record -- RAISE NOTICE 'Creating legacy_comment_data table';