
Research
/Security News
DuckDB npm Account Compromised in Continuing Supply Chain Attack
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
master-slave replication helper for ActiveRecord.
# Gemfile
gem "replicat"
Modify your replicable models & config/database.yml.
# app/models/user.rb
class User < ActiveRecord::Base
replicate
end
# config/database.yml
production:
adapter: mysql2
encoding: utf8
host: 192.168.24.1
port: 3306
replications:
slave1:
adapter: mysql2
encoding: utf8
host: 192.168.24.2
port: 3306
slave2:
adapter: mysql2
encoding: utf8
host: 192.168.24.3
port: 3306
slave3:
adapter: mysql2
encoding: utf8
host: 192.168.24.4
port: 3306
Now SELECT queries of User model will be sent to slave connections.
# INSERT query is sent to master.
User.create(name: "replicat")
# SELECT query is sent to slave.
User.first
using
can help you specify particular connection.
When you want to send queries to master,
you can use using(:master)
to do that (:master is reserved name for using
method).
When you want to send queries to a particular slave,
you can use the slave's name on database.yml like using(:slave1)
.
# SELECT query is sent to master.
User.using(:master).first
# INSERT query is sent to slave1.
User.using(:slave1).create(name: "replicat")
# :slave1 is used for User connection in the passed block.
User.using(:slave1) { blog.user }
slave connections are balanced by round-robin way.
User.first # sent to slave1
User.first # sent to slave2
User.first # sent to slave3
User.first # sent to slave1
User.first # sent to slave2
User.first # sent to slave3
User.first # sent to slave1
User.first # sent to slave2
User.first # sent to slave3
Pass the master's connection name to replicate
method.
# app/models/user.rb
class User < ActiveRecord::Base
replicate "production_user"
end
# app/models/recipe.rb
class Recipe < ActiveRecord::Base
replicate "production_recipe"
end
# config/database.yml
production_user:
<<: *production
host: 192.168.24.1
replications:
slave1:
<<: *slave
host: 192.168.24.2
slave2:
<<: *slave
host: 192.168.24.3
slave3:
<<: *slave
host: 192.168.24.4
production_recipe:
<<: *production
host: 192.168.24.5
replications:
slave1:
<<: *slave
host: 192.168.24.6
slave2:
<<: *slave
host: 192.168.24.7
slave3:
<<: *slave
host: 192.168.24.8
# setup gems
bundle install
# setup database
cd spec/dummy
rake db:create
rake db:schema:load RAILS_ENV=test
cd ../../
# run tests
bundle exec rspec
FAQs
Unknown package
We found that replicat demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.