Advanced DB Setup

For more complex database connections with multiple databases for read/write consider the following configuration:

database:
# simple dsn
default: mysql://dbuser:dbpassword@dbhost:3306/dbname
db2: mysql://dbuser:dbpassword@dbhost:3306/dbname
# Advanced configuration:
# If you have multiple database servers for read/write then this might be a better options.
dbPool1:
# Failover logic: When a server becomes unavailable then following logics is applied:
# default logic: In default logic
# Write: If master server is not reachable for write, then next writeable master (if any) will be used based on weight.
# Read: If slave server is not reachable for reads, the next slave (if any) will be used based on weight.
# 1. If there are no slave servers available then master read only server (if any) will be used based on weight.
# 2. If there is still no read only master server, then next master with allow_read (if any) will be used based on weight
# TODO custom logic: An array containing class and method to call. User can specify which db server to use.
# This gives user the flexibility to pick a db based on db health, concurrent threads etc..
# Format is [\class, method]
failover: default
#list of servers in this pool
servers:
dbMaster1:
dsn: mysql://dbuser:dbpassword@dbhost:3306/dbname
# role - In advance db setup, there are two types of roles:
# master - used for write (and some occasions for read, keep reading)
# slave - used for read
role: master
# read_only - (default: false) 'readonly' mode would not allow any writes to specified server. Read only
# servers (masters) are usually passive in nature or hot stand by. In read only mode data is not written to
# dsn and any query except for SELECT is ignored and result in empty result set
read_only: false
# allow_read - (default: true) To allow reads from master when there is no slave and no read only master db
# Note that you cannot use allow_read & rad_only for the master
allow_read: true
# weight - For the same roles a database with higher weight is picked first.
weight: 1
# on_connect - Any sql commands to run on connect
on_connect:
- SET NAMES utf8;
dbMaster2:
dsn: mysql://dbuser:dbpassword@dbhost:3306/dbname
role: master
read_only: true
weight: 2
on_connect:
- SET NAMES utf8;
- /* Another SQL command */;
dbSlave1:
dsn: mysql://dbuser:dbpassword@dbhost:3306/dbname
role: slave
weight: 1