Build a typical Ruby on Rails Web site (ii)

Source: Internet
Author: User
Tags abstract mysql database ruby on rails

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.