Importing Votes: Is it Possible to Use a PostgreSQL Command or other to Set Vote Counts on Specific Topics?"

Hello, I’m in the process of migrating from AnswerHub to Discourse. However, since I don’t have access to the AnswerHub database, I’ve scraped the entire website to gather the Ideas and their respective vote counts.

How can I override the vote count for a specific question in Discourse? For instance, the question “make a new recipe with oranges” has 42 votes on my AnswerHub. I have imported the question, but I would like to set the vote count to 42 instead of it defaulting to 0. This way, users can see the accurate number of votes for each question.

Is there a way to execute a PostgreSQL command to manually set the vote count?
Do I need to create 100+ fake users to simulate the vote count for each question? I hope not, as that’s not an ideal solution :stuck_out_tongue:

Thank you in advance for your help.

:slight_smile:

1 Like

Hi Luicid!

:warning: I’m no expert and I’ve never used this plugin :upside_down_face:

This is a great question and I’m afraid I can’t answer precisely but maybe I can give some pointers as you seem to know a bit about coding (since you’re migrating from scratch)

The voting plugin uses 2 tables:

discourse_voting_topic_vote_count

Field Name Type Constraints
id serial primary key
topic_id integer foreign key (references topics), can be null
votes_count integer can be null
created_at timestamp
updated_at timestamp

discourse_voting_votes

Field Name Type Constraints
id serial primary key
topic_id integer foreign key (references topics), can be null
user_id integer foreign key (references users), can be null
archive boolean can be null, default false
created_at timestamp
updated_at timestamp

You may be interested in the plugin’s settings as well but I guess you’re already aware of them :slight_smile:

Finally, topic voting must be enabled per category, so I’d enable them during the category creations in the import script.

As for how to properly populate the votes in the topic during a migration, I’m not an expert, but I guess I’ll go with having random, unique users for each vote, as a job prevents multiple votes from the same user and would delete duplicate votes:

I’ll populate the necessary fields (to be determined) and let jobs fill in other fields if there’s such a thing.

You may also want to have a look at all the plugin jobs discourse-topic-voting/app/jobs at main · discourse/discourse-topic-voting · GitHub

I hope this is helping a bit and that you’ll share how things go :slight_smile:

1 Like

Wow, thank you for this great and helpful post! :slight_smile:
I decided to opt for a different approach:

In my original website, I was able to retrieve the data on who voted for what, so I stored that information in a database. Later on, I used a Python script with the requests library to cast votes from their migrated accounts for the ideas they had already voted for, and voilà!

Thank you again

1 Like