graze/sprout

为您的项目提供种子数据

0.4.4 2021-07-01 18:24 UTC

This package is auto-updated.

Last update: 2024-08-29 04:48:48 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score PHP Version Docker Image Size Docker Pulls

Sprout是一个帮助将删除、截断和种子开发数据导入数据库的工具。

fun image

  1. 从本地文件中种子sql数据
  2. 从mysql表导出数据
  3. 并行执行操作
  4. 处理多组种子数据(例如,staticcoretesting

安装

通过Composer

composer require graze/sprout

通过docker

docker run -v [volumes] --rm graze/sprout [command]

用法

请参阅完整文档以获取完整的用法信息。

文件结构

Sprout将默认使用以下文件结构,您可以在配置文件中更改根目录和每个组的路径。

- /seed
  - group1
    - schema1
      - table1.sql
      - table2.sql
    - schema2
      - table3.sql
  - group1
    - schema3
      - table4.sql

快速开始

# Dump all tables you are interested in
sprout dump --config=config/sprout.yml --group=static a_schema:table_1,table_2 ...

# Store the data in your repository of choice
git add /seed/static/*

# Seed the data from your local files
sprout seed --config=config/sprout.yml --group=static

种子数据

sprout seed [--config=<path>] [--group=<group>] [--no-chop|--chop-all] [<schema>[:<table>,...]] ...

sprout seed --config=config/sprout.yml the_schema
sprout seed --config=config/sprout.yml --chop-all the_schema
sprout seed --config=config/sprout.yml --no-chop the_schema

sprout seed --config=config/sprout.yml the_schema:country
sprout seed --config=config/sprout.yml --no-chop the_schema:country other_schema:planets

sprout seed --config=config/sprout.yml --group=core
sprout seed --config=config/sprout.yml --group=core the_schema
sprout seed --config=config/sprout.yml --no-chop --group=extra
sprout seed --config=config/sprout.yml --chop-all --group=extra

截断模式中所有表的数据

sprout chop [--config=<path>] [--group=<group>] [--all] [<schema>[:<table>,...]] ...

sprout chop --config=config/sprout.yml the_schema
sprout chop --config=config/sprout.yml the_schema:country
sprout chop --config=config/sprout.yml --all the_schema

sprout chop --config=config/sprout.yml --group=core the_schema
sprout chop --config=config/sprout.yml --group=extra the_schema:country
sprout chop --config=config/sprout.yml --group=extra --all

导出模式中所有表的数据

sprout dump [--config=<path>] [--group=<group>] [<schema>[:<table>,...]] ...

sprout dump --config=config/sprout.yml the_schema
sprout dump --config=config/sprout.yml the_schema:country

sprout dump --config=config/sprout.yml --group=core
sprout dump --config=config/sprout.yml --group=core the_schema:country

配置

配置文件遵循以下标准。

默认情况下,sprout寻找config/sprout.yml文件,您可以使用--config=path/to/file.yml指定不同的文件。

defaults:
  group: core
  # default path
  path: /seed
  # number of simultaneous processors to run at a time (default: 10)
  simultaneousProcesses: 10

# ability to specify custom paths for groups
groups:
  core:
    path: /custom/path/to/group

schemas:
  # name of the schema to reference
  <name>:
    # [optional] the actual name of the schema in the database. If not specified, <name> from above will be used
    schema: 'schema'

    # Connection details - this is just an example, you may want to specify
    # different properties, e.g. if connecting to a remote server. You are
    # advised to refer to the 'pdo' documentation for further details.
    connection:
      user: 'morphism'
      password: 'morphism'
      # driver for the database connection, currently only: `mysql` is supported
      driver: 'mysql'
      # [optional] name of the database
      dbName: 'schema'
      # database on a remote host
      host: 'db'
      # [optional] port to use, by default: 3306
      port: 3306

测试

make build test

贡献

请参阅CONTRIBUTING以获取详细信息。

安全

如果您发现任何与安全相关的问题,请通过security@graze.com发送电子邮件,而不是使用问题跟踪器。

鸣谢

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。