-
Notifications
You must be signed in to change notification settings - Fork 0
/
laravel-csv-file-seeder.php
208 lines (190 loc) · 6.84 KB
/
laravel-csv-file-seeder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
return [
/*
|--------------------------------------------------------------------------
| Database connection
|--------------------------------------------------------------------------
|
| The database connection to use for seeding.
|
*/
'connection' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
| Data path
|--------------------------------------------------------------------------
|
| The folder the csv files are located. It defaults to database/data.
|
*/
'data_path' => database_path('data'),
/*
|--------------------------------------------------------------------------
| Delimiter character
|--------------------------------------------------------------------------
|
| The csv delimiter to use for parsing csv fields.
|
*/
'delimiter' => ',',
/*
|--------------------------------------------------------------------------
| Enclosure character
|--------------------------------------------------------------------------
|
| The csv enclosure to use for parsing csv fields.
|
*/
'enclosure' => '"',
/*
|--------------------------------------------------------------------------
| Escape character
|--------------------------------------------------------------------------
|
| The csv escape to use for parsing csv fields.
|
*/
'escape' => '\\',
/*
|--------------------------------------------------------------------------
| Trim csv values
|--------------------------------------------------------------------------
|
| Indicates if any leading or trailing white space should be trimmed
| from the csv fields.
|
*/
'trim_values' => true,
/*
|--------------------------------------------------------------------------
| Insert chunk size.
|--------------------------------------------------------------------------
|
| Set the number of rows to read before an insert query will be executed.
| This will limit the sql queries fired by the seeder and speed up the
| performance.
|
| NOTE: If you have a large amount of data a small chunk size can cause
| the seeder to fail because of the large number of insert queries.
|
*/
'insert_chunk_size' => 50,
/*
|--------------------------------------------------------------------------
| Truncate tables
|--------------------------------------------------------------------------
|
| Whether or not the desired tables should be truncated before seeding.
|
| NOTE: This will only affect tables where seeder data is available for!
| All other tables will be untouched!
*/
'truncate' => true,
/*
|--------------------------------------------------------------------------
| Foreign key checks
|--------------------------------------------------------------------------
|
| Enable or disable foreign key checks while truncating.
|
*/
'foreign_key_checks' => true,
/*
|--------------------------------------------------------------------------
| Files to run by the seeder
|--------------------------------------------------------------------------
|
| The files that should be seeded in the given order.
|
| If no files are given all files located in the 'data_path' folder will
| be seeded in alphabetically order.
|
*/
'files' => [],
/*
|--------------------------------------------------------------------------
| Zipped import/export
|--------------------------------------------------------------------------
|
| Whether or not export/import an zip archive containing the csv files.
|
*/
'zipped' => false,
/*
|--------------------------------------------------------------------------
| Archive name
|--------------------------------------------------------------------------
|
| The archive name to use.
|
*/
'archive_name' => 'db-csv-export.zip',
/*
|--------------------------------------------------------------------------
| Encrypted zip archive
|--------------------------------------------------------------------------
|
| Whether or not the exported/imported zip archive should be/is password
| protected.
|
*/
'encrypted' => false,
/*
|--------------------------------------------------------------------------
| Encryption password
|--------------------------------------------------------------------------
|
| The password to use when encryption is enabled.
|
*/
'encryption_password' => env('CSV_SEEDER_ENCRYPTION_PASSWORD', 'secret'),
/*
|--------------------------------------------------------------------------
| Command specific configurations
|--------------------------------------------------------------------------
*/
'commands' => [
/*
|--------------------------------------------------------------------------
| Configuration for the db:export-csv command
|--------------------------------------------------------------------------
*/
'export_csv' => [
/*
|--------------------------------------------------------------------------
| Add column names
|--------------------------------------------------------------------------
|
| Whether or not the csv files should contain the column names in the
| first row.
|
*/
'with_headers' => true,
/*
|--------------------------------------------------------------------------
| Tables to ignore
|--------------------------------------------------------------------------
|
| The tables that should be ignored when creating csv files.
|
*/
'except' => [
'migrations',
'password_resets',
],
/*
|--------------------------------------------------------------------------
| Export chunk size
|--------------------------------------------------------------------------
|
| Set the number of items to be written into the csv file at a time.
| This will decrease the php memory needed to write the files.
|
| NOTE: If you have a large amount of data a small chunk size can cause
| the export to fail e.g. out of memory exception.
|
*/
'export_chunk_size' => 100,
],
],
];