This is the second part, the main is the MySQL database distributed design. When I set up the environment, I basically did not separate the database. For the time being, prepare for it.
Database design of master-slave structure
The www.eol.org project itself has the database design of master-slave database and read-write separate.
(Master/slave) and the rails core database are separated from the application core database. Mainly depends on the following plug-in implementations:
use_db: The main function is to distribute different models to different databases. Detailed explanation see below: (http://rails.elctech.com/blog/using-and-testing-rails-with-multiple-databases)
Masochism: Mainly used for ActiveRecord, read and write operation separate detailed description of the following Web site (http://www.planetrubyonrails.org/tags/view/masochism)
Design of MySQL database for distributed organization
In this program, the implementation of the distributed database, mainly by creating the abstract class Models connected to different databases, the other Models and then by inheriting the virtual class, and then connect different databases. This is achieved by distributing the models to a different database.
In this project, there are two abstract Class model corresponding to the application database, and the log library respectively. These two abstract Class model are:
Ruby Code
-Speciesschemamodel
-Loggingmodel
and their corresponding databases can be found in the definition of DATABASE.YML, respectively
Java code
-Environment_data (e.g Development_data)
-environment_logging (e.g. development_logging)
The mechanism of distributed database with read-write separation
The read-write separate database mechanism relies on masochism plugin to build two databases. These two numerical control libraries can also be seen from the config/database.yml in the description
Ruby Code
-Master_database (master database storage core rails data)
-master_data_database (master database stores the data that applies this book)
In addition, to differentiate data access, two different abstract classes are designed to read the two different master databases, each of which has direct SQL query permissions.
Ruby Code
-Masterdatabase (for the core Rails database)
-Speciesschemawriter (for the species data database)