An open API service indexing awesome lists of open source software.

https://github.com/combodo/mysql-faked-dump


https://github.com/combodo/mysql-faked-dump

combodo-tools

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

          

# Mysql faked dump *ALPHA*
Create censored dump with a finger snap!

:no_entry_sign: *This tool is an alpha version and should not be used.*

## prerequisites
In order to install the dependencies, you need `composer`, and as this tool relies on symfony 4, you'll need at least `php 7.1`.

## installation

```bash
composer install
```

## usage

Just call `bin/console mysql-faked:dump` with one parameter: the path to a valid config file.
It will output the dump on the stdout.
The dump progress is output on the stderr.

you can store the dump by redirecting stdout to a file:
```bash
bin/console mysql-faked:dump path/to/file.yaml > ~/Desktop/dump.sql
```

or directly execute it :
```bash
bin/console mysql-faked:dump path/to/file.yaml | mysql --host=remote_host -C db_name
```

this command accept two options :
- skip-drop-table
- skip-create-table

## configuration
The configuration is written in yaml, it has three main entries.

##### example:
```yaml
data_source:
dsn: 'mysql:dbname=foo;host=localhost;port=3600'
user: 'root'
password: ~
options: []
options:
exclude_missing_tables: false
tables:
fos_user:
preserve_filter:
preserve: "email like '%@combodo.com' or id=1"
reverse: "(email not like '%@combodo.com' or email is null) and id!=1"
columns:
email:
faker: unique.email
alias: [email_canonical]
last_name:
faker: lastName
company:
faker: company
password:
empty: true
oauth_*:
pattern: "oauth_.*"
exclude: true
```

##### data_source:
This part describes how to connect to mysql.
see [PDO::__construct] in order to see how to configure it more deeply

##### options:
for now only one option exists:

- `exclude_missing_tables`: whether non mapped table should be dumped or ignored.

##### tables
This entry lets you configure special cases:
- ignore tables: `exclude: true`
- special values for columns
- empty value: `empty: true`
- fake value : `faker: company`
- preserve some rows from being faked `preserve_filter`
- in this case, you need to provide both the `preserve` and the `reverse` filter. They will be applied as SQL WHERE clauses.

NB : fake values are generated by using the [Faker] library, so you can use every formatter provided, or even write your own.
Behind the scene, [Symfony's property accessor] is used, so you can easily create complex calls (ie for calling `$faker->unique->email()` just type `unique.email` in order to obtain guaranteed unique email)


###### pattern
If you want to map many tables within one configuration entry, use an impossible to match table name (ie: `oauth_*`) and configure a pattern (ie `pattern: "oauth_.*"`).

###### alias
Faker will give you a different result on each call, so if you want many columns to share the same value, configure an alias (ie: `alias: [table2, table3]`).

[PDO::__construct]: http://php.net/manual/fr/pdo.construct.php
[Faker]: https://github.com/fzaninotto/Faker#formatters
[Symfony's property accessor]: https://symfony.com/doc/current/components/property_access.html#reading-from-objects