# Global Replace across database

**URL:** <https://meta.discourse.org/t/global-replace-across-database/55930>\
**Category:** Support\
**Created:** [January 17, 2017, 10:06pm UTC](https://meta.discourse.org/t/global-replace-across-database/55930 "2017-01-17T22:06:00Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)\
**Post date:** [January 18, 2017, 3:09pm UTC](https://meta.discourse.org/t/global-replace-across-database/55930/3 "2017-01-18T15:09:01Z")

</div>

> [@pfaffman](#):
>
> leaving that link in the first post in every topic.

In this case what I will recommend is looping through all the topics and revising the first post. You should add a new custom rake task for this manually on the droplet. The rake task will be like:

```ruby
task 'posts:remap_custom' => :environment do
  puts "Remapping"
  i = 0
  Topic.all.each do |t|
    p = t.first_post
    new_raw = p.raw.dup
    new_raw = new_raw.gsub!(/\[ORIGINAL POST\]\(.*t\)/, "") || new_raw

    if new_raw != p.raw
      p.revise(Discourse.system_user, { raw: new_raw }, { bypass_bump: true, skip_revision: true })
      putc "."
      i += 1
    end
  end
  puts "", "#{i} posts remapped!", ""
end

```

Considering that there are ~2.3 million posts this process will take some time to complete.

---

_[View the full topic](https://meta.discourse.org/t/global-replace-across-database/55930)._
