How to do rails db:migrate on multiple shards that are not master slave relationship at once on rails? : <p>I have an app which which uses different database based on the subdomain. So essentially, the schema would be the same, but the data would differ for each databases. But when I release some new features and it would require some schema changes, I would need to run a command that would run on all databases configured in the <code>shards.yml</code>.</p>

<p><strong>database.yml</strong></p>

<pre><code>default: &amp;default
  adapter: postgresql
  encoding: unicode
  pool: 15
  host: localhost
  port: 5432
  username: postgres
  password:

development:
  &lt;&lt;: *default
  database: app_default
production:
  &lt;&lt;: *default
  database: app_default
  username: &lt;%= ENV['BACKEND_DATABASE_USERNAME'] %&gt;
  password: &lt;%= ENV['BACKEND_DATABASE_PASSWORD'] %&gt;
</code></pre>

<p><strong>shards.yml</strong></p>

<pre><code>shared: &amp;shared
  adapter: postgresql
  encoding: unicode
  pool: 15
  host: localhost
  username: postgres
  password: 
  port: 5432

octopus:
  environments:
    - development
    - test
    - production
  development:
    default:
      &lt;&lt;: *shared
      database: app
    first:
      &lt;&lt;: *shared
      database: first
    second:
      &lt;&lt;: *shared
      database: second
    ....
  test:
    test:
      host: postgres
      adapter: postgresql
      database: app_test
  production:
    default:
      &lt;&lt;: *shared
      database: app
    first:
      &lt;&lt;: *shared
      database: first
    second:
      &lt;&lt;: *shared
      database: second
    ....
</code></pre>

<p>I am using Octopus to set the shard based on subdomain, which works fine. The problems I have are:</p>

<ol>
<li>I cannot do <code>rails db:reset</code> . Getting the error <code>ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR:  cannot drop the currently open database</code></li>
<li>I cannot do <code>rails db:migrate</code> that would migrate on all databases</li>
</ol>
