# Add likes programmatically?

**URL:** <https://meta.discourse.org/t/add-likes-programmatically/242993>\
**Category:** Product Support\
**Created:** [October 26, 2022, 6:24pm UTC](https://meta.discourse.org/t/add-likes-programmatically/242993 "2022-10-26T18:24:50Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![piffy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/piffy/32/254198_2.png) [@piffy](https://meta.discourse.org/u/piffy)\
**Post date:** [October 26, 2022, 7:56pm UTC](https://meta.discourse.org/t/add-likes-programmatically/242993/3 "2022-10-26T19:56:16Z")

</div>

Thanks for the response. I am nervous to re-run the import script since it’s been almost 6 months and I’m not sure what kind of side-effects it could have in edge cases where old data interacts with new data.

Here’s the helper function I used in my import script.

> <https://github.com/discourse/discourse/blob/fcc2e7ebbf3fa5f17c24c70149a949850f29a5f3/script/import_scripts/base.rb#L643>

Here’s the relevant code

```plaintext
created_by = User.find_by(id: user_id_from_imported_user_id(params[:user_id]))
post = Post.find_by(id: post_id_from_imported_post_id(params[:post_id]))

if created_by && post
          PostActionCreator.create(created_by, post, :like, created_at: params[:created_at])
          created += 1
...

```

I will run something similar to this. Thanks!

---

_[View the full topic](https://meta.discourse.org/t/add-likes-programmatically/242993)._
