Giter VIP home page Giter VIP logo

smartdump's Introduction

Smart Dump

Exports a referentially intact subset of a MySQL database.

Note: although this tool targets MySQL only for now, it is designed to be able to support other RDBMS in the future.

License

Introduction

Did you ever need to export just a couple tables from your MySQL database, but end up with broken foreign key constraints? What if you could import every single foreign row your data depends on as well, and nothing more? This tool does just that.

Let's say you want to dump the order_items table below:

If you use mysqldump, you'll get broken foreign key constraints to orders and products.

If you use smartdump instead, you'll get the whole order_items table, plus the rows from orders and products required to satisfy the constraints, plus, in turn, the rows from users and countries required to satisfy the remaining constraints! ๐Ÿ’ช

The key takeaway here is that smartdump will only import the rows required to satisfy the constraints of the requested tables.

Installation

The only currently supported installation method is through Composer:

composer require benmorel/smartdump

Usage

To dump some tables, just run:

vendor/bin/smartdump db.table1 db.table2

or, if all your tables are in the same database:

vendor/bin/smartdump --database db table1 table2

Options

Options that take a value:

Option Description Default value
--host The host name localhost
--port The port number 3306
--user The user name root
--password The password
--charset The character set utf8mb4
--database The database name to prepend to table names

Options that don't take a value:

Option Description
--no-create-table Add this option to not include a CREATE TABLE statement
--add-drop-table Add this option to include a DROP TABLE IF EXISTS statement before CREATE TABLE
--no-schema-name Add this option to not include the schema name in the output; this allows for importing the dump into a schema name other than that of the source database.

Future scope (todo, ideas)

  • standalone PHAR version
  • support for other RDBMS
  • support for loading only n rows in the base tables; useful to extract a sample dataset
  • support for loading incoming relationships to the tables (?)
    Right now, only the outgoing relationships are followed, it could be interesting to follow incoming relationships to each row we're exporting as well; at least as an option?
  • a mode that does not dump, but scans the whole database for broken foreign key constraints

Database diagram courtesy dbdiagram.io.

Logo by Pixel perfect.

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.