Skip to content

Commit

Permalink
Filesystem abstraction (#3)
Browse files Browse the repository at this point in the history
* some docs and process-mysqldump safer

* store process-mysqldump locally

* abstract the filesystem to allow testing

* add tests

* remove docs about not creating directories, can do this now

* update composer file

* fix dev.md

* fix config namespace

* fix actual commands

* update .gitignore file

* add dockerignore file

* 🌱
  • Loading branch information
Harry Bragg authored Aug 13, 2018
1 parent 86c65ea commit d5128a8
Show file tree
Hide file tree
Showing 24 changed files with 780 additions and 193 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
docs/
example/
hooks/
theme/

.git
.markdownlint.json
.travis.yml
.idea
LICENSE
Makefile
mkdocs.yml
phpcs.xml
phpunit.xml.dist
README.md
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor/
/tests/report/
/site/

.idea
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sprout
# 🌱 Sprout

[![Latest Version on Packagist](https://img.shields.io/packagist/v/graze/sprout.svg?style=flat-square)](https://packagist.org/packages/graze/sprout)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
Expand Down Expand Up @@ -34,6 +34,8 @@ docker run -v [volumes] --rm graze/sprout [command]

## Usage

See the [full documentation](https://graze.github.io/sprout) for complete usage information.

### File Structure

Sprout will use the following file structure by default, you can change the root and each group's path in the
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@
},
"require": {
"php": "^7.0",
"symfony/console": "^3.3 | ^4",
"symfony/filesystem": "^3.3 | ^4",
"symfony/yaml": "^3.3 | ^4",
"graze/parallel-process": "^0.7",
"graze/console-diff-renderer": "^0.6.1",
"graze/data-structure": "^2.0",
"respect/validation": "^1.1",
"graze/config-validation": "^0.2",
"psr/log": "^1.0"
"league/flysystem": "^1.0",
"psr/log": "^1.0",
"respect/validation": "^1.1",
"symfony/console": "^3.3 | ^4",
"symfony/yaml": "^3.3 | ^4"
},
"require-dev": {
"graze/standards": "^2.0",
"mockery/mockery": "^1",
"phpunit/phpunit": "^5.7.21 | ^6 | ^7",
"squizlabs/php_codesniffer": "^3.0",
"mockery/mockery": "^1"
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
"psr-4": {
Expand Down
136 changes: 85 additions & 51 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,21 @@ schemas:
1. Should this be limited to sql dumping/restoring only?
1. Alternative is to use php/yaml/json files too.
1. sql/yaml/json are similar, need a yaml/json to sql and back converter.
```yaml
schema: some_schema
table: some_table
prefix: prf_

data:
- id: 123
name: something
date: 2018-02-12 16:15:15

- id: 234
name: other
cake: things
```
1. Should this handle stored procedures?
1. How should this handle triggers / complex table setup? (prep tables, disable triggers, indexes, etc)
3 changes: 0 additions & 3 deletions docs/groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ Sprout allows you to group your seed data into arbitrary categories.

## Creating grouped seed data

!!! note
Currently you must create the group/schema directory before running this.

You can dump data from sprout into a grouped collection using the `--group=<group>` option on all of the commands

```bash
Expand Down
6 changes: 1 addition & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sprout 🌱
# 🌱 Sprout

Sprout is a tool to help you Populate your databases with seed data.

Expand Down Expand Up @@ -37,10 +37,6 @@ sprout dump --config=/path/to/config.yml --group=group1 schema:table1,table2,...

This will create a set of `.sql` files locally containing the data in your database.

!!! warning
Currently you need to create the directories before running this command (or let it fail and tell you what you need
to create)

### Seed your data

You can now seed your data using the local files.
Expand Down
2 changes: 1 addition & 1 deletion example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ chop-group: start-db

dump: ## Dump the data from a table
dump: start-db
docker-compose run --rm sprout dump the_schema:* -v
docker-compose run --rm sprout dump the_schema -v

dump-group: ## Dump the data from a table
dump-group: start-db
Expand Down
11 changes: 7 additions & 4 deletions src/Command/ChopCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
use Graze\ParallelProcess\Table;
use Graze\Sprout\Chop\Chopper;
use Graze\Sprout\Chop\TableChopperFactory;
use Graze\Sprout\Config;
use Graze\Sprout\Config\Config;
use Graze\Sprout\Parser\ParsedSchema;
use Graze\Sprout\Parser\SchemaParser;
use Graze\Sprout\Parser\TablePopulator;
use League\Flysystem\Adapter\Local;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -74,7 +76,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$config = (new Config())->parse($input->getOption('config'));
$group = $input->getOption('group') ?: $config->get(Config::CONFIG_DEFAULT_GROUP);

$schemaParser = new SchemaParser($config, $group);
$tablePopulator = new TablePopulator(new Local('.'));
$schemaParser = new SchemaParser($tablePopulator, $config, $group);
$parsedSchemas = $schemaParser->extractSchemas($schemas);

$numTables = array_sum(array_map(
Expand All @@ -93,7 +96,7 @@ function (ParsedSchema $schema) {
$output->writeln(sprintf(
'Chopping down <info>%d</info> tables in <info>%s</info> schema in group <info>%s</info>',
count($schema->getTables()),
$schema->getSchameName(),
$schema->getSchemaName(),
$group
));

Expand All @@ -104,7 +107,7 @@ function (ParsedSchema $schema) {
[],
$config->get(Config::CONFIG_DEFAULT_SIMULTANEOUS_PROCESSES),
false,
['chop', 'schema' => $schema->getSchameName()]
['chop', 'schema' => $schema->getSchemaName()]
);
$globalPool->add($pool);
}
Expand Down
14 changes: 9 additions & 5 deletions src/Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
use Exception;
use Graze\ParallelProcess\Pool;
use Graze\ParallelProcess\Table;
use Graze\Sprout\Config;
use Graze\Sprout\Config\Config;
use Graze\Sprout\Dump\Dumper;
use Graze\Sprout\Dump\TableDumperFactory;
use Graze\Sprout\Parser\ParsedSchema;
use Graze\Sprout\Parser\SchemaParser;
use Graze\Sprout\Parser\TablePopulator;
use League\Flysystem\Adapter\Local;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -71,7 +73,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$config = (new Config())->parse($input->getOption('config'));
$group = $input->getOption('group') ?: $config->get(Config::CONFIG_DEFAULT_GROUP);

$schemaParser = new SchemaParser($config, $group);
$fileSystem = new Local('.');
$tablePopulator = new TablePopulator($fileSystem);
$schemaParser = new SchemaParser($tablePopulator, $config, $group);
$parsedSchemas = $schemaParser->extractSchemas($schemas);

$numTables = array_sum(array_map(
Expand All @@ -90,7 +94,7 @@ function (ParsedSchema $schema) {
$output->writeln(sprintf(
'Dumping <info>%d</info> tables in <info>%s</info> schema in group <info>%s</info>',
count($schema->getTables()),
$schema->getSchameName(),
$schema->getSchemaName(),
$group
));

Expand All @@ -101,12 +105,12 @@ function (ParsedSchema $schema) {
[],
$config->get(Config::CONFIG_DEFAULT_SIMULTANEOUS_PROCESSES),
false,
['dump', 'schema' => $schema->getSchameName()]
['dump', 'schema' => $schema->getSchemaName()]
);
$globalPool->add($pool);
}

$dumper = new Dumper($schema->getSchemaConfig(), $output, new TableDumperFactory($pool));
$dumper = new Dumper($schema->getSchemaConfig(), $output, new TableDumperFactory($pool), $fileSystem);
$dumper->dump($schema->getPath(), $schema->getTables());
}

Expand Down
Loading

0 comments on commit d5128a8

Please sign in to comment.