You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/schema-definition.md
+78-6Lines changed: 78 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -2,23 +2,81 @@
2
2
title: Dump Schema Definition
3
3
order: 2
4
4
---
5
+
5
6
# Dump Schema Definition
6
7
7
8
Your database dump configuration takes place in the `config/masked-dump.php` file.
8
9
9
10
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
11
-
This is the basic configuration that you'll receive after installing the package:
12
+
## Configuration Methods
13
+
14
+
There are two ways to configure your dump schema. For production applications using Laravel's config caching, the callable method is strongly recommended.
15
+
16
+
### Method 1: Using PHP Callables (Recommended for Production)
17
+
18
+
When using Laravel's config caching feature, the default inline configuration approach may cause serialization errors. To avoid this issue, use PHP callables in your configuration:
12
19
13
20
```php
21
+
<?php
22
+
23
+
use BeyondCode\LaravelMaskedDumper\DumpSchema;
24
+
use App\Support\MaskedDump;
25
+
26
+
return [
27
+
/**
28
+
* Use a callable class to define your dump schema
29
+
* This method is compatible with Laravel's config caching
30
+
*/
31
+
'default' => [MaskedDump::class, 'define'],
32
+
];
33
+
```
34
+
35
+
Then create the referenced class:
36
+
37
+
```php
38
+
<?php
39
+
40
+
namespace App\Support;
41
+
42
+
use BeyondCode\LaravelMaskedDumper\DumpSchema;
43
+
use BeyondCode\LaravelMaskedDumper\TableDefinitions\TableDefinition;
44
+
use Faker\Generator as Faker;
14
45
46
+
class MaskedDump
47
+
{
48
+
public static function define()
49
+
{
50
+
return DumpSchema::define()
51
+
->allTables()
52
+
->table('users', function (TableDefinition $table) {
53
+
$table->replace('name', function (Faker $faker) {
54
+
return $faker->name;
55
+
});
56
+
$table->replace('email', function (Faker $faker) {
57
+
return $faker->safeEmail;
58
+
});
59
+
$table->mask('password');
60
+
})
61
+
->schemaOnly('failed_jobs')
62
+
->schemaOnly('password_reset_tokens');
63
+
}
64
+
}
65
+
```
66
+
67
+
### Method 2: Inline Definition
68
+
69
+
This is the basic configuration that you'll receive after installing the package. While simpler for development, this method is not compatible with Laravel's config caching:
70
+
71
+
```php
15
72
use BeyondCode\LaravelMaskedDumper\DumpSchema;
16
73
use BeyondCode\LaravelMaskedDumper\TableDefinitions\TableDefinition;
17
74
use Faker\Generator as Faker;
18
75
19
76
return [
20
77
/**
21
78
* Use this dump schema definition to remove, replace or mask certain parts of your database tables.
79
+
* NOTE: This approach is not compatible with Laravel's config caching.
22
80
*/
23
81
'default' => DumpSchema::define()
24
82
->allTables()
@@ -34,7 +92,7 @@ return [
34
92
];
35
93
```
36
94
37
-
## Definiting which tables to dump
95
+
## Defining which tables to dump
38
96
39
97
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.
40
98
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:
@@ -116,22 +174,22 @@ When dumping your data, the dump will now contain a safe, randomly generated ema
116
174
117
175
## Optimizing large datasets
118
176
119
-
The method TableDefinition::outputInChunksOf(int $chunkSize) allows for chunked inserts for large datasets,
177
+
The method TableDefinition::outputInChunksOf(int $chunkSize) allows for chunked inserts for large datasets,
120
178
improving performance and reducing memory consumption during the dump process.
121
179
122
180
```php
123
181
return [
124
182
'default' => DumpSchema::define()
125
183
->allTables()
126
-
->table('users', function($table) {
127
-
return $table->outputInChunksOf(3);
184
+
->table('users', function($table) {
185
+
return $table->outputInChunksOf(3);
128
186
});
129
187
];
130
188
```
131
189
132
190
## Specifying the database connection to use
133
191
134
-
By default, this package will use your `default` database connection when dumping the tables.
192
+
By default, this package will use your `default` database connection when dumping the tables.
135
193
You can pass the connection to the `DumpSchema::define` method, in order to specify your own database connection string:
136
194
137
195
```php
@@ -155,3 +213,17 @@ return [
155
213
->schemaOnly('custom_table'),
156
214
];
157
215
```
216
+
217
+
When using the callable approach with multiple schemas, you can define separate classes for each schema:
0 commit comments