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

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:

https://github.com/discourse/discourse-topic-voting/blob/main/app/jobs/onceoff/voting_ensure_consistency.rb#L28

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: