Skip to content

Commit 3c33ca0

Browse files
committed
Added docs folder
1 parent d6a2966 commit 3c33ca0

File tree

5 files changed

+202
-1
lines changed

5 files changed

+202
-1
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
build
22
composer.lock
3-
docs
43
vendor
54
coverage
65
.phpunit.result.cache

docs/_index.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
packageName: Laravel Masked DB Dump
3+
githubUrl: https://github.com/beyondcode/laravel-masked-db-dump
4+
---

docs/dumping-the-database.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Dumping the Database
3+
order: 3
4+
---
5+
# Dumping the Database
6+
7+
After you have configured your dump schema, it's time to dump your tables. This can be done using the `db:masked-dump` artisan command.
8+
The command expects one argument, which is the name of the output file to use.
9+
10+
```
11+
php artisan db:masked-dump output.sql
12+
```
13+
14+
Running this command, will use the `default` dump schema definition and write the resulting dump to a file called `output.sql`.
15+
16+
## Changing Definitions
17+
18+
In case that your configuration file contains multiple dump schema definitions, you can pass the definition to use to the command like this:
19+
20+
```
21+
php artisan db:masked-dump output.sql --definition=sqlite
22+
```
23+
24+
## GZip compression
25+
26+
The default output is a plain text file - depending on the size of your dump, you might want to enable GZip compression. This can be done by passing the `--gzip` flag to the command:
27+
28+
```
29+
php artisan db:masked-dump output.sql --gzip
30+
```
31+
32+
This will write the compressed output to a file called `output.sql.gz`.

docs/installation.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Installation
3+
order: 1
4+
---
5+
# Installation
6+
7+
To install the Laravel Masked DB Dump package, you can use composer:
8+
9+
```
10+
composer require beyondcode/laravel-masked-db-dump
11+
```
12+
13+
Next, you should publish the package configuration file, so that you can configure your dump schema:
14+
15+
```
16+
php artisan vendor:publish --provider=BeyondCode\\LaravelMaskedDumper\\LaravelMaskedDumpServiceProvider
17+
```
18+
19+
This will create a new file called `masked-dump.php` in your config folder.

docs/schema-definition.md

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
---
2+
title: Dump Schema Definition
3+
order: 2
4+
---
5+
# Dump Schema Definition
6+
7+
Your database dump configuration takes place in the `config/masked-dump.php` file.
8+
9+
You can use the package's fluent API to define which tables should be dumped and which information should be replaced or masked during the dump process.
10+
11+
This is the basic configuration that you'll receive after installing the package:
12+
13+
```php
14+
15+
use BeyondCode\LaravelMaskedDumper\DumpSchema;
16+
use BeyondCode\LaravelMaskedDumper\TableDefinitions\TableDefinition;
17+
use Faker\Generator as Faker;
18+
19+
return [
20+
/**
21+
* Use this dump schema definition to remove, replace or mask certain parts of your database tables.
22+
*/
23+
'default' => DumpSchema::define()
24+
->allTables()
25+
->table('users', function (TableDefinition $table) {
26+
$table->replace('name', function (Faker $faker) {
27+
return $faker->name;
28+
});
29+
$table->replace('email', function (Faker $faker) {
30+
return $faker->safeEmail;
31+
});
32+
$table->mask('password');
33+
})
34+
->schemaOnly('failed_jobs')
35+
->schemaOnly('password_resets'),
36+
];
37+
```
38+
39+
## Definiting which tables to dump
40+
41+
The dump configuration allows you to specify which tables you want to dump. The simplest form of dumping your database can be achieved by using the `allTables()` method.
42+
This ensures that all of your database tables will be represented in the dump. You can then go and customize how certain tables should be dumped:
43+
44+
```php
45+
return [
46+
'default' => DumpSchema::define()
47+
->allTables(),
48+
];
49+
```
50+
51+
## Dumping table schemas only
52+
53+
For certain tables, you do not need to dump the data, but only need the structure of the table itself - like a `password_reset` table. To instruct the masked dumper to only dump the schema, you may use the `schemaOnly` method:
54+
55+
```php
56+
return [
57+
'default' => DumpSchema::define()
58+
->allTables()
59+
->schemaOnly('password_resets'),
60+
];
61+
```
62+
63+
This configuration will dump all of your tables - but for the `password_resets` table, it will not create any `INSERT` statements and only dumps the schema of this table.
64+
65+
## Masking table column content
66+
67+
To mask the content of a given table column, you can use the `mask` method on a custom table definition. For example, let's mask the `password` column on our `users` table:
68+
69+
```php
70+
return [
71+
'default' => DumpSchema::define()
72+
->table('users', function ($table) {
73+
$table->mask('password');
74+
})
75+
];
76+
```
77+
78+
By default, the data will be masked using the `x` character, but you can also specify your own custom masking character as a second parameter:
79+
80+
```php
81+
return [
82+
'default' => DumpSchema::define()
83+
->table('users', function ($table) {
84+
$table->mask('password', '-');
85+
})
86+
];
87+
```
88+
89+
## Replacing table column content
90+
91+
Instead of completely masking the content of a column, you can also replace the column content. The content can either be replaced with a static string, or you can make use of a callable and replace it with custom content - for example faker data.
92+
93+
To replace a column with a static string, you can use the `replace` method and pass the string to use as a replacement as the second argument:
94+
95+
```php
96+
return [
97+
'default' => DumpSchema::define()
98+
->table('users', function ($table) {
99+
$table->replace('name', 'John Doe');
100+
})
101+
];
102+
```
103+
104+
This configuration will dump all users and replace their name with "John Doe".
105+
106+
To gain more flexibility over the replacement, you can pass a function as the second argument. This function receives a Faker instance, as well as the original value of the column:
107+
108+
```php
109+
110+
return [
111+
'default' => DumpSchema::define()
112+
->table('users', function (TableDefinition $table) {
113+
$table->replace('email', function (Faker $faker, $value) {
114+
return $faker->safeEmail;
115+
});
116+
})
117+
];
118+
```
119+
120+
When dumping your data, the dump will now contain a safe, randomly generated email address for every user.
121+
122+
## Specifying the database connection to use
123+
124+
By default, this package will use your `default` database connection when dumping the tables.
125+
You can pass the connection to the `DumpSchema::define` method, in order to specify your own database connection string:
126+
127+
```php
128+
return [
129+
'default' => DumpSchema::define('sqlite')
130+
->allTables()
131+
];
132+
```
133+
134+
## Multiple dump schemas
135+
136+
You can define multiple database dump schemas in the `masked-dump.php` configuration file.
137+
The key in the configuration array is the identifier that will be used when you dump your tables:
138+
139+
```php
140+
return [
141+
'default' => DumpSchema::define()
142+
->allTables(),
143+
144+
'sqlite' => DumpSchema::define('sqlite')
145+
->schemaOnly('custom_table'),
146+
];
147+
```

0 commit comments

Comments
 (0)