Port your MySQL data from old schema to the new schema with just a configuration file.
- Create a
config.js
file which exports an object with rules and database config. npm install
node index.js
config.js
must export an object with host
, user
, password
, db
and
rules
. See below for details.
- Host for database
- User for database
- Password for the database
- Must contain
source
anddestination
pairs with database names
- Contains the rules for porting
- One rule for each target table
- Example:
rules: [ {}, {}, ... , {} ]
- Object with info about target and source tables
- Must contain:
old
andnew
objectsnew
: Stringold
: String or Object withunion
andon
pairs
- See old below for details
- Example:
table: { new: 'NEW_TABLE', old: 'OLD_TABLE' }
- Object with
target_attribute
s as keys andsource_attribute
s or other rules as values - See fields below for details
- Example:
This SELECTs
fields: { user: 'login', password: 'pass' }
login
andpass
fields from old table and puts inuser
andpass
of the new table, respectively
- A MySQL query to run instead of target and source pairs
- If found,
table
andfields
objects are ignored - Example:
Runs the query as it is
query: 'INSERT INTO table (user, password) VALUES ("bits", "goa_ftw!");'
- If
true
, the rule is skipped - Example:
This rule is skipped regardless of anything else
rules: [ { skip: true, ... }, {}, {} ]
- Must be either a string with table name
- Or an object with
union
andon
union
must be an array with table nameson
must be a MySQL condition
- Example:
Inner joins the tables with common
old: { union: ['t1', 't2', 't3'], on: 't1.id = t2.id AND t2.id = t3.id' }
id
- Evaluates an if condition and enters data accordingly
- Must contain
condition
,pass
andfail
- See condition below for details
- Example:
Checks if
if: { condition: { eval: {} }, pass: 'login', fail: { value: 'some other' } }
login
attribute of old table is equal to "bits". If yes, putslogin
of old table in the new table else puts a string "some other"
- Evaluates switch condition and enters data accordingly
- Must contain
condition
,cases
cases
must be an object of key-value pairs- Example:
If
switch: { condition: 'login_type', cases: [ { type1: { value: '1' } }, { type2: { value: '2' } }, { other: 'login_type' } ] }
login_type
equals "type1" put a string "1" or if "type2" put a string "2" or if "other" put the value oflogin_type
attribute of old table
- Any field with
value
will be put as value itself rather than getting it from the source table - Example:
Puts the string "some value" in
user: { value: 'some value' }
user
attribute of the new table
- Must contain
eval
oror
orand
or
orand
must be an array of objects which must containeval
- See eval below for details
- Example:
Is equivalent to
condition: { or: [ { eval: {C1} }, { eval: {C2} }, { and: [ { eval: {C3} }, { eval: {C4} } ] } ] }
C1 || C2 || (C3 && C4)
- Must contain
operator
and (first_attribute
orfirst_value
) and (second_attribute
orsecond_value
)operator
must be a constant stringX_attribute
must be an attribute of the tableX_value
must be a constant string
- Example:
Put "1" or "0" if
condition: { eval: operator: '===', first_attribute: 'login', second_value: 'bits' } pass: { value: '1' }, fail: { value: '0' } },
login
of old table is===
tobits
of new table