Download the PHP package sascha-steinbrink/laravel-csv-file-seeder without Composer
On this page you can find all versions of the php package sascha-steinbrink/laravel-csv-file-seeder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sascha-steinbrink/laravel-csv-file-seeder
More information about sascha-steinbrink/laravel-csv-file-seeder
Files in sascha-steinbrink/laravel-csv-file-seeder
Package laravel-csv-file-seeder
Short Description Seed or export the database from/to csv or zip files.
License MIT
Homepage https://github.com/sascha-steinbrink/laravel-csv-file-seeder
Informations about the package laravel-csv-file-seeder
LaravelCsvFileSeeder
This package provides the ability to import or export your database to csv or zip files.
- Installation
- Usage
- Available seed options
- Available export options
- Using a different path
- Using a different delimiter
- Using an archive
- Only specific files
- Using an encrypted archive
- Using a connection other than the default
- FAQ
This is where your description should go. Take a look at contributing.md to see a to do list.
Installation
This package can be used in Laravel 5.5 or higher!
Via Composer
If you want to use zipped files make sure and is installed on your system!
You can publish the configuration file with the following command:
The configuration file contains:
Usage
You can seed or export your database through the console using the following artisan commands:
To seed your database using laravel's command you have to register the in the class.
The main difference between those two methods is the flexibility of changing the default values of the configuration file through command options which is only possible with the command.
Without any options given or by using the command all available commands will use the values from the config/laravel-csv-file-seeder.php configuration file.
The default data path in the config file points to database/data. Therefore a call to or would seed all files from the database/data directory with an .csv extension into the database.
The csv file names must match the corresponding table names! All csv files where the name does not match any table in the database will be ignored.
You can debug the output of the commands to see which files were ignored (and other information) by increasing the verbosity level (-v/-vv/-vvv)!
If you are getting 'Integrity constraint violation' errors while seeding try to disable the foreign key checks either by specifying the / option or by disable them globally in the config/laravel-csv-file-seeder.php configuration file
The export command will export all tables (except the ones specified in the config file which are by default migrations and password_resets) into database/data directory.
To be able to change any of the configuration values you have to publish the configuration file. See the installation instructions to do so.
Available seed options
Note: This options can only be assigned to the command! To change any option for the command you have to change the values in the configuration file!
Option | Default | Description | |
---|---|---|---|
--data-path | -p | database/data | The folder the csv files are located in |
--files | -i | [] | The files that should be seeded |
--delimiter | -d | ',' | The delimiter character to use for parsing csv fields |
--enclosure | -l | '"' | The enclosure character to use for parsing csv fields |
--escape | -c | '\' | The escape character to use for parsing csv fields |
--trim-values | -m | true | Should trim lead-/trailing white spaces from csv fields |
--insert-chunk-size | -s | 50 | The number of rows to read before an insert query is fired |
--truncate | -t | true | Truncate the desired tables before seeding |
--foreign-key-checks | -k | true | Enable/disable foreign key checks while truncating |
--zipped | -z | false | Import data is an archive (zip) file |
--archive-name | -a | "db-csv-export.zip" | The archive name to import |
--encrypted | -e | false | The import archive is encrypted |
--connection | default | The database connection to seed | |
--force | Force the operation to run when in production |
The defaults to the default database connection ()
Available export options
Option | Default | Description | |
---|---|---|---|
--data-path | -p | database/data | The folder the csv files should be stored |
--except | -x | "migrations,password_resets" | The tables that should be ignored |
--with-headers | -w | true | Should include column names |
--delimiter | -d | ',' | The delimiter character to use for parsing csv fields |
--enclosure | -l | '"' | The enclosure character to use for parsing csv fields |
--escape | -c | '\' | The escape character to use for parsing csv fields |
--export-chunk-size | -s | 100 | The number of items to be written into the csv file at a time |
--zipped | -z | false | Export data as an archive (zip) file |
--archive-name | -a | "db-csv-export.zip" | The archive name to use for saving |
--encrypted | -e | false | Encrypt the archive |
--connection | default | The database connection to export |
The defaults to the default database connection ()
Using a different path
To seed all csv files located in /my/path:
To export all tables (except the ones specified in the config file) as csv files into /my/path:
Using a different delimiter
To seed all csv files located in /my/path using a semicolon as delimiter:
To export all tables (except the ones specified in the config file) as csv files into /my/path using a semicolon as delimiter:
Using an archive file
The zip option is not available on windows!
To seed the export.zip archive located in /my/path:
To export all tables (except the ones specified in the config file) into database/data/dbExport.zip:
Only specific files
To import only the users.csv file located in database/data:
To import only the users.csv file located in /my/other/path:
To export all tables except the users table and the migrations table to the database/data directory:
Using an encrypted archive
The zip option is not available on windows!
When providing the or option in combination with the or option a password prompt will be shown, where you can specify the password to use for encryption.
The or will be ignored when zipping is not activated. (Either by setting the option / or by enabling the zipped option in the configuration file.)
To seed the encrypted db-csv-export.zip archive located in /my/path:
To export all tables into an encrypted /my/path/encrypted.zip archive:
NOTE:
If you want to specify a default encryption password for your project you can add it to your env file using the key.
Using a connection other than the default
To seed all csv files located in /my/path using the database bound to my-other-db connection:
To export all tables as csv files into /my/path using the database bound to my-other-db connection:
The is set to also include the excepted ones specified in the config file which are by default migrations and password_resets
FAQ
Please see the FAQ for more information.
Change log
Please see the changelog for more information on what has changed recently.
Testing
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email author email instead of using the issue tracker.
Credits
License
license. Please see the license file for more information.