# Hosted to self-hosted migration: past uploads still reference discourse infra

**URL:** <https://meta.discourse.org/t/hosted-to-self-hosted-migration-past-uploads-still-reference-discourse-infra/281131>\
**Category:** Product Support\
**Created:** [October 5, 2023, 9:56am UTC](https://meta.discourse.org/t/hosted-to-self-hosted-migration-past-uploads-still-reference-discourse-infra/281131 "2023-10-05T09:56:45Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![kluvin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kluvin/32/289447_2.png) [@kluvin](https://meta.discourse.org/u/kluvin)\
**Post date:** [October 6, 2023, 12:25pm UTC](https://meta.discourse.org/t/hosted-to-self-hosted-migration-past-uploads-still-reference-discourse-infra/281131/17 "2023-10-06T12:25:49Z")

</div>

I did what everyone told my not to do: to meddle with the database and its dumpfile. Currently, most everything works, except for same cases of:

```plaintext
<img src="https://forum.everviz.com/images/transparent.png"
alt="image" data-orig-src="upload://npqpp5O0wbL89nR9OXtP7Btu4hc.png"
width="517" height="90" style="aspect-ratio: 517 / 90;" loading="lazy">

```

Let’s compute the b62 and take its hex

_npqpp5O0wbL89nR9OXtP7Btu4hc = **0x** a411c90267cafca7a1cbcd7c8f4f9b8db17e51ba_

Now try to `find` it from /var/www/discourse/public/uploads:

`find . -name '*a411c90267cafca7a1cbcd7c8f4f9b8db17e51ba*'`  
`./default/original/1X/a411c90267cafca7a1cbcd7c8f4f9b8db17e51ba.png`

**Yes!**

 ![](https://global.discourse-cdn.com/meta/original/4X/9/6/7/967973543dd6e5605c13df09f81e824ea0dec678.png)  
But why is it transparent.png in the post? I’ve done `rake uploads:recover_from_tombstone` and `rake posts:rebake`

* * *

## How did I get here?

The uploads column in the database, for table `url` would still show `cdck` as part of the source URL for images. I dropped into the database from inside the container:

`postgres psql discourse`

Then

```sql
UPDATE uploads
SET url = REPLACE(
           url, 
           '//cdck-file-uploads-europe1.s3.dualstack.eu-west-1.amazonaws.com/standard21/uploads/everviz/', 
           '/uploads/default/'
         )
WHERE url LIKE '//cdck-file-uploads-europe1.s3.dualstack.eu-west-1.amazonaws.com/standard21/uploads/everviz/%';

```

This showed promising results, where most original images and thumbnails would reappear.

**One step further: modifiying dumpfiles**

The assumption is that Discourse is stateless\* and the only thing we need to care about is what is inside the database. I was not eager to fiddle around with rake tasks or ruby for this, as I am not very familiar with either of those or Discourse internals. I just want results, fast.

\*_short of the `public` folder which contains our images. We can nevertheless confirm that we have everything we need._

So we download a copy of the database from the UI, then open it in VSCode and regressively substitute `cdck` (bucket) references and `europe1` (bucket from CDN) references

By regressively I mean that in some instances you would see ‘//…’ and in other cases you would see ‘https://’. Therefore you need to match and replace ‘//…’ first, else you will have trailing https: across the file.

Then reupload the modified dumpfile. Part of what made this all tricky is the base62 step, which makes it a little harder to go from a raw representation to the actual image URL.

---

_[View the full topic](https://meta.discourse.org/t/hosted-to-self-hosted-migration-past-uploads-still-reference-discourse-infra/281131)._
