定制 benmorel/smartdump 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

benmorel/smartdump

Composer 安装命令:

composer require benmorel/smartdump

包简介

Dumps selected MySQL tables together with their relationships

README 文档

README

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 the whole order_items table, with broken foreign key constraints to orders and products.

If you use smartdump instead, you'll get the rows you want from order_items (or the whole table, as you wish), plus the rows from orders and products required to satisfy their 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/rows.

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

To dump only a subset of a table, add extra conditions after the table name:

vendor/bin/smartdump "db.table:LIMIT 100"

Or even:

vendor/bin/smartdump "db.table:WHERE user_id=123 ORDER BY id DESC LIMIT 10"

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.
--merge Add this option to create a dump that can be merged into an existing schema; this removes CREATE TABLE statements and uses upserts instead of inserts. Implies --no-create-table.

Future scope (todo, ideas)

  • standalone PHAR version
  • support for other RDBMS
  • 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.

benmorel/smartdump 适用场景与选型建议

benmorel/smartdump 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 104.22k 次下载、GitHub Stars 达 161, 最近一次更新时间为 2020 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 benmorel/smartdump 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 benmorel/smartdump 我们能提供哪些服务?
定制开发 / 二次开发

基于 benmorel/smartdump 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 104.22k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 161
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 161
  • Watchers: 7
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-21