GithubHelp home page GithubHelp logo

rare_map's Introduction

Gem Version

rare_map

Relational db to ActiveREcord models MAPper

It does the reverse engineering to convert existing databases to ActiveRecord models.

Features:

  1. Rebuiding assocauations.

  2. Rebuiding attribute accessors(Optional in Rails 4).

  3. Providing an interactive console which is like Rails console.

  4. Table or column names which are out of convention can be matched by configuraiton. (Plural and singular words are already matched automatically.)

  5. Can be used for BOTH standalone application & Rails

Installation:

gem install rare_map

Basic RareMap Usage

Standalone:

Create a new rare_map.yml with following lines in the root of your application

Rails:

Create a new config/rare_map.yml with following lines in rails

rare_map.yml:

  legacy:
    adapter: sqlite3
    database: db/db1.sqlite3

  old_db:
    adapter: mysql2
    host: localhost
    database: db_name
    port: 3306
    username: user
    password: pw

Run following command in the root of your application or rails

$ raremap

Standalone: A demo.rb example is generated for you in the root of your application

RareMap console which is like rails console for standalone app can be run by following command

$ raremap console  # or simply run `raremap c`

Advanced RareMap Usage

Seperate databases into groups (highly recommended)

  her_group:
    -
      db1:
        adapter: sqlite3
        database: db/db1.sqlite3
    -
      db2:
        adapter: sqlite3
        database: db/db1.sqlite3

  his_group:
    -
      db1:
        adapter: sqlite3
        database: db/db3.sqlite3
    -
      db2:
        adapter: sqlite3
        database: db/db4.sqlite3

There are benefits by separating databases into groups:

  1. Associations are built between databases within a group

  2. Group name is treated as a module namespace

  3. Models of a group are organized within a folder

If all your data reside in several legacy databases, it is important to build back those associations across databases

If there are 2 or more tables with the same name, giving them group names could avoid naming collision

If there are tons of tables, it is better to organize them well

Set up RareMap Options

  rare_map_opts:
    foreign_key:
      suffix: fk
      alias:
        abnormal_fk1: table1
        abnormal_fk2: table2
    primary_key:
      table1: abnormal_pk
  • rare_map_opts[foreign_key][suffix]: If your foreign keys are not ended with 'id', you can specify the suffix you want here
  • rare_map_opts[foreign_key][alias]: If naming convention is not followed by some foreign keys, you can list them here
  • rare_map_opts[primary_key]: Usually rare_map can identify the primary key of a table, if it fails, please list primary keys here

RareMap Options Precedence

You can place rare_map options in 3 ways

  rare_map_opts:             # Global options
    ...
  group1:
    -
      rare_map_opts:         # Group options
        ...
    -
      db1:
        ...
  legacy_db:
    adapter: sqlite3
    database: db/db.sqlite3
    rare_map_opts:           # DB options
      ...

Precedence: DB > Group > Global

Copyright

Copyright (c) 2013 Wei-Ming Wu. See LICENSE.txt for further details.

rare_map's People

Contributors

wnameless avatar

Stargazers

 avatar Frank Wang avatar Aboobacker MK avatar Yao avatar Max Surkov avatar David avatar Yumei Leventhal avatar  avatar Daniel Naranjo avatar Duško Milekić avatar DaMo Wang avatar Alexander Fuhr avatar Josh Rieken avatar Noah Pryor avatar Jason Hoekstra avatar Heber Uriegas avatar José Salinas avatar Kacper Madej avatar seansg avatar  avatar Tse-Ching Ho avatar  avatar Hannah avatar

Watchers

James Cloos avatar Hannah avatar

rare_map's Issues

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.