octopus
octopus copied to clipboard
db:migrate breaks on read-only slave
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 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
Hi, Is there any chance this got fixed somehow?
Seeing the same issue here.
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
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.
@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