# Multisite stellt Uploads auf „default" statt auf den tatsächlichen DB-Namen wieder her

**URL:** <https://meta.discourse.org/t/multisite-restores-uploads-to-default-instead-of-actual-db-name/130778>\
**Category:** Development\
**Created:** [11. Oktober 2019 um 11:30 UTC](https://meta.discourse.org/t/multisite-restores-uploads-to-default-instead-of-actual-db-name/130778 "2019-10-11T11:30:04Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![kris.kotlarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kris.kotlarek/32/176919_2.png) [@kris.kotlarek](https://meta.discourse.org/u/kris.kotlarek)\
**Post date:** [22. Oktober 2019 um 02:57 UTC](https://meta.discourse.org/t/multisite-restores-uploads-to-default-instead-of-actual-db-name/130778/10 "2019-10-22T02:57:31Z")

</div>

Ich habe mir etwas Zeit genommen, das zu untersuchen, und habe schließlich eine Lösung gefunden 🙂

> <https://github.com/discourse/discourse/pull/8218>
>
> Simplified flow of restore is like that
> \`\`\`
> migrate\_database
> reconnect
> extra…ct\_uploads
> \`\`\`
> 
> Problem with incorrect current database started with this fix https://github.com/discourse/discourse/commit/025d4ee91f4
> 
> Dump task is reconnecting to default database https://github.com/rails/rails/blob/master/activerecord/lib/active\_record/railties/databases.rake#L429
> 
> And then, we are trying to reconnect to the original database with that code:
> \`\`\`
> def reconnect\_database
> log "Reconnecting to the database..."
> RailsMultisite::ConnectionManagement::establish\_connection(db: @current\_db)
> end
> \`\`\`
> 
> This reconnect is not switching us back to correct database because of that check
> https://github.com/discourse/rails\_multisite/blob/master/lib/rails\_multisite/connection\_management.rb#L181
> Basically, it finds existing handler and it thinks that we are connected to correct DB and this step can be skipped.
> 
> To solve it, we can reload RailsMultisite::ConnectionManagement which creates a new instance of that class
> https://github.com/discourse/rails\_multisite/blob/master/lib/rails\_multisite/connection\_management.rb#L38
> 
> Meta: https://meta.discourse.org/t/multisite-restores-uploads-to-default-instead-of-actual-db-name/130778

---

_[View the full topic](https://meta.discourse.org/t/multisite-restores-uploads-to-default-instead-of-actual-db-name/130778)._
