Giter Site home page Giter Site logo

rails-mysql-mongo-weblog's People

Contributors

nyamadori avatar

rails-mysql-mongo-weblog's Issues

Content モデルの作成

データベース設計: #1

属性名 役割
ObjectID _id コンテンツを一意に特定する ID
int type コンテンツの種類
string body コンテンツ文字列

Rails のセットアップ

  • Rails 4.2
  • MySQL
  • MongoDB (Mongoid)
  • モデルのジェネレータ設定
    • rails g model で MySQL のモデルを作成

Article モデルの作成

データベース設計: #1
MySQL テーブル

属性名 役割
int id 記事を一意に特定する ID
string title_oid タイトル本体を特定する MongoDB の ObjectID
string body_oid 記事本文を特定する MongoDB の ObjectID
int category_id 所属カテゴリを特定するための categories テーブルへの ID
datetime published_at 投稿日時

データベース設計

命名規則

テーブル名や属性名の規則は基本的に Rails の規則を踏襲する。

DB の使い分け

  • MySQL ではリレーショナルなデータやメタデータを管理する
  • 実データ (記事のタイトルや本文) は MongoDB で管理する

MySQL

MySQL から MongoDB のデータを参照するための属性の名前には _oid を末尾に付与する。

articles テーブル

属性名 役割
int id 記事を一意に特定する ID
string title_oid タイトル本体を特定する MongoDB の ObjectID
string body_oid 記事本文を特定する MongoDB の ObjectID
int category_id 所属カテゴリを特定するための categories テーブルへの ID
datetime published_at 投稿日時

categories テーブル

属性名 役割
int id カテゴリを一意に特定する ID
string name カテゴリ名

MongoDB

titles コレクション

属性名 役割
ObjectID _id タイトルを一意に特定する ID
string body タイトル本体文字列

bodies コレクション

属性名 役割
ObjectID _id 本文を一意に特定する ID
string body 本文本体文字列

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.