2.0.8 • Published 8 years ago

mysqlminidump v2.0.8

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

! NEEDS mysqldump utility installed to work

mysqlminidump

Create small mysql dumps from your production database.

Dumps your main table and all the required tables with foreign key constraints.
Create fake foreign key constraints if you need.

install

npm install -g mysqlminidump
can be used with any version of node. Tested with 4.2.6 and 0.12.7

usage

mysqlminidump ~/config.json

config.json sample:

{
  "verbose": true,
  "chunkSize": 1000,
  "resultFile": "dump.sql",
  "mysqlConfig": {
    "host"     : "localhost",
    "user"     : "root",
    "password" : "password",
    "database" : "database"
  },
  "dumpConfig": {
    "table"       : "product",
    "primaryKey"  : "id",
    "starterQuery": "select * from product limit 100;"
  },
  "mysqldumpOptions": [],
  "overridePrimaryKey": {
    "category": "id"
  },
  "fakeConstraints": [{
    "TABLE_NAME"             : "product",
    "COLUMN_NAME"            : "merchant_id",
    "REFERENCED_TABLE_NAME"  : "merchant",
    "REFERENCED_COLUMN_NAME" : "id"
  }]
}

verbose

show logs

chunkSize

many dumps are created which are appended to the same file, this option tells how many ids to use to create a dump.

resultFile

output dump file path

mysqlConfig

mysql configuration

dumpConfig

  • table: name of the main table
  • primaryKey: primary key of main table
  • starterQuery: the query to start the dump process

mysqldumpOptions

array of mysqldump options

overridePrimaryKey

I have assumed primary key of all tables is id, to override use

--
"overridePrimaryKey": {
  tableName1: primaryKey1,
  tableName2: primaryKey2
}
--

fakeContraints

array of objects to inject fake foreign key constraints


Example

--
"dump": {
    "table"      : "product",
    "primaryKey" : "id",
    "offset"     : 0,
    "limit"      : 2
  },
--

FOREIGN KEY (category_id) REFERENCES category (id)
FOREIGN KEY (merchant_id) REFERENCES merchant (id)
brand_id is not a foreign key so we add an object in fakeConstraints

--
"fakeConstraints": [{
   "TABLE_NAME"             : "product",
   "COLUMN_NAME"            : "brand_id",
   "REFERENCED_TABLE_NAME"  : "brand",
   "REFERENCED_COLUMN_NAME" : "id"
 }]
--
  1. product

    idcategory_idmerchant_idbrand_id
    15000100901
    25000101902
    35002102903
    ........
  2. category

    idname
    5000category0
    5001category1
    5003category3
    ....
  3. merchant

    idname
    100merchant0
    101merchant1
    102merchant2
    ....
  4. brand

    idname
    901brand1
    902brand2
    903brand3
    ....

resulting dump ids:

  1. product : 1,2
  2. category : 5000
  3. merchant : 100, 101
  4. brand : 901, 902