Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db:migrate breaks on read-only slave #345

Open
junheon opened this issue Dec 23, 2015 · 6 comments
Open

db:migrate breaks on read-only slave #345

junheon opened this issue Dec 23, 2015 · 6 comments

Comments

@junheon
Copy link

junheon commented Dec 23, 2015

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?

@velles
Copy link

velles commented Dec 23, 2015

@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

@asafjaffi
Copy link

Hi,
Is there any chance this got fixed somehow?

@mstroming
Copy link

Seeing the same issue here.

@tuliang
Copy link

tuliang commented Jan 10, 2019

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

@neocoin
Copy link

neocoin commented Jan 16, 2019

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.

@azamzamy
Copy link

azamzamy commented Nov 5, 2020

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants