Skip to content

Commit d5128a8

Browse files
author
Harry Bragg
authored
Filesystem abstraction (#3)
* 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 * 🌱
1 parent 86c65ea commit d5128a8

24 files changed

+780
-193
lines changed

.dockerignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
docs/
2+
example/
3+
hooks/
4+
theme/
5+
6+
.git
7+
.markdownlint.json
8+
.travis.yml
9+
.idea
10+
LICENSE
11+
Makefile
12+
mkdocs.yml
13+
phpcs.xml
14+
phpunit.xml.dist
15+
README.md

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/vendor/
22
/tests/report/
33
/site/
4+
5+
.idea

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Sprout
1+
# 🌱 Sprout
22

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

3535
## Usage
3636

37+
See the [full documentation](https://graze.github.io/sprout) for complete usage information.
38+
3739
### File Structure
3840

3941
Sprout will use the following file structure by default, you can change the root and each group's path in the

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@
2929
},
3030
"require": {
3131
"php": "^7.0",
32-
"symfony/console": "^3.3 | ^4",
33-
"symfony/filesystem": "^3.3 | ^4",
34-
"symfony/yaml": "^3.3 | ^4",
3532
"graze/parallel-process": "^0.7",
3633
"graze/console-diff-renderer": "^0.6.1",
3734
"graze/data-structure": "^2.0",
38-
"respect/validation": "^1.1",
3935
"graze/config-validation": "^0.2",
40-
"psr/log": "^1.0"
36+
"league/flysystem": "^1.0",
37+
"psr/log": "^1.0",
38+
"respect/validation": "^1.1",
39+
"symfony/console": "^3.3 | ^4",
40+
"symfony/yaml": "^3.3 | ^4"
4141
},
4242
"require-dev": {
4343
"graze/standards": "^2.0",
44+
"mockery/mockery": "^1",
4445
"phpunit/phpunit": "^5.7.21 | ^6 | ^7",
45-
"squizlabs/php_codesniffer": "^3.0",
46-
"mockery/mockery": "^1"
46+
"squizlabs/php_codesniffer": "^3.0"
4747
},
4848
"autoload": {
4949
"psr-4": {

composer.lock

Lines changed: 85 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,21 @@ schemas:
145145
146146
1. Should this be limited to sql dumping/restoring only?
147147
1. Alternative is to use php/yaml/json files too.
148+
1. sql/yaml/json are similar, need a yaml/json to sql and back converter.
149+
150+
```yaml
151+
schema: some_schema
152+
table: some_table
153+
prefix: prf_
154+
155+
data:
156+
- id: 123
157+
name: something
158+
date: 2018-02-12 16:15:15
159+
160+
- id: 234
161+
name: other
162+
cake: things
163+
```
148164
1. Should this handle stored procedures?
149165
1. How should this handle triggers / complex table setup? (prep tables, disable triggers, indexes, etc)

docs/groups.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ Sprout allows you to group your seed data into arbitrary categories.
1212

1313
## Creating grouped seed data
1414

15-
!!! note
16-
Currently you must create the group/schema directory before running this.
17-
1815
You can dump data from sprout into a grouped collection using the `--group=<group>` option on all of the commands
1916

2017
```bash

docs/index.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Sprout 🌱
1+
# 🌱 Sprout
22

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

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

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

40-
!!! warning
41-
Currently you need to create the directories before running this command (or let it fail and tell you what you need
42-
to create)
43-
4440
### Seed your data
4541

4642
You can now seed your data using the local files.

example/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ chop-group: start-db
2626

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

3131
dump-group: ## Dump the data from a table
3232
dump-group: start-db

src/Command/ChopCommand.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
use Graze\ParallelProcess\Table;
1818
use Graze\Sprout\Chop\Chopper;
1919
use Graze\Sprout\Chop\TableChopperFactory;
20-
use Graze\Sprout\Config;
20+
use Graze\Sprout\Config\Config;
2121
use Graze\Sprout\Parser\ParsedSchema;
2222
use Graze\Sprout\Parser\SchemaParser;
23+
use Graze\Sprout\Parser\TablePopulator;
24+
use League\Flysystem\Adapter\Local;
2325
use Symfony\Component\Console\Command\Command;
2426
use Symfony\Component\Console\Input\InputArgument;
2527
use Symfony\Component\Console\Input\InputInterface;
@@ -74,7 +76,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7476
$config = (new Config())->parse($input->getOption('config'));
7577
$group = $input->getOption('group') ?: $config->get(Config::CONFIG_DEFAULT_GROUP);
7678

77-
$schemaParser = new SchemaParser($config, $group);
79+
$tablePopulator = new TablePopulator(new Local('.'));
80+
$schemaParser = new SchemaParser($tablePopulator, $config, $group);
7881
$parsedSchemas = $schemaParser->extractSchemas($schemas);
7982

8083
$numTables = array_sum(array_map(
@@ -93,7 +96,7 @@ function (ParsedSchema $schema) {
9396
$output->writeln(sprintf(
9497
'Chopping down <info>%d</info> tables in <info>%s</info> schema in group <info>%s</info>',
9598
count($schema->getTables()),
96-
$schema->getSchameName(),
99+
$schema->getSchemaName(),
97100
$group
98101
));
99102

@@ -104,7 +107,7 @@ function (ParsedSchema $schema) {
104107
[],
105108
$config->get(Config::CONFIG_DEFAULT_SIMULTANEOUS_PROCESSES),
106109
false,
107-
['chop', 'schema' => $schema->getSchameName()]
110+
['chop', 'schema' => $schema->getSchemaName()]
108111
);
109112
$globalPool->add($pool);
110113
}

0 commit comments

Comments
 (0)