octopus icon indicating copy to clipboard operation
octopus copied to clipboard

db:migrate breaks on read-only slave

Open junheon opened this issue 9 years ago • 6 comments

I'm using aws Aurora for my production database and I using both write-only cluster and read-only replica.

When I run rake db:migrate, following errors are always caused:

ActiveRecord::StatementInvalid: Mysql2::Error: The MySQL server is running with the --read-only option so it cannot execute this statement

How can I disable slaves for db migration?

junheon avatar Dec 23 '15 07:12 junheon

@junheon you can try setting up default database in your config/initializers/octopus.rb. Something like:

if Octopus.enabled? 
  Octopus.config[Rails.env.to_s]['master'] = ActiveRecord::Base.connection.config
  ActiveRecord::Base.connection.initialize_shards(Octopus.config)
end

velles avatar Dec 23 '15 07:12 velles

Hi, Is there any chance this got fixed somehow?

asafjaffi avatar Jun 04 '18 10:06 asafjaffi

Seeing the same issue here.

mstroming avatar Sep 12 '18 20:09 mstroming

You can try setting up default database in your config/initializers/octopus.rb. Something like:

return unless Octopus.enabled?

module Octopus
  class ProxyConfig
    # cover shard_names method
    def shard_names
      # support db those commands
      if ARGV[0].match(/^db:/).present?
        ["master"]
      else
        # default
        shards.keys
      end
    end
  end
end

tuliang avatar Jan 10 '19 10:01 tuliang

You can try setting up default database in your config/initializers/octopus.rb. Something like:

return unless Octopus.enabled?

module Octopus
  class ProxyConfig
    # cover shard_names method
    def shard_names
      # support db those commands
      if ARGV[0].match(/^db:/).present?
        ["master"]
      else
        # default
        shards.keys
      end
    end
  end
end

This idea ignore migration for shard db.

neocoin avatar Jan 16 '19 15:01 neocoin

@tuliang Could you explain what shard_names should be returning. I'm trying to fix the exact same problem but I want to refactor the method to fit my implementation.

Here is my shards.yml file

octopus:
  replicated: true
  fully_replicated: false
  environments:
    - development
    - staging
    - production

  development:
    slave:
      adapter: mysql2
      database: DB_NAME
      username: USERNAME
      password: PASSWORD
      host: SLAVE_HOSTNAME
      port: PORT
      pool: pool_count
  staging:
    slave:
      adapter: mysql2
      database: DB_NAME
      username: USERNAME
      password: PASSWORD
      host: SLAVE_HOSTNAME
      port: PORT
      pool: pool_count
  production:
    slave:
      adapter: mysql2
      database: DB_NAME
      username: USERNAME
      password: PASSWORD
      host: SLAVE_HOSTNAME
      port: PORT
      pool: pool_count

azamzamy avatar Nov 05 '20 15:11 azamzamy