Simple script to delete existing database rows matching a defined key & import the new row state from a file.
angela 0075c4cf2d remove unneded escape | 6 years ago | |
---|---|---|
LICENSE | 6 years ago | |
README.md | 6 years ago | |
database-import.sh | 6 years ago |
Incredibly simple script to import a table's row based on a defined key.
Handy for when collaborating with other developers and you wish to import the chunk of the database they're working on, without receiving the needless bloat of a full database export, or using complicated and monolithic diff scripts. This script does not require a remote connection!
All you need is a database file that has insert rows; like those generated by Simple Database Row Export.
ie. *Backup, delete and import all rows from foo table with row bar that equals stuff*
This script is companion to Simple Database Row Export
This script will backup and then delete all rows matching the defined key; so if you've modified the defined rows yourself, before receiving and importing your co-workers' rows, your changes to those rows will be lost!
The instructions below assume you're on a Linux system, though script will work on any platform that has MariaDB or MySQL installed.
Edit the script's configuration to set the path and what table, row and key to target.
Put database-import.sh somewhere on your system, ie. /home/myuser/scripts/
Make the script executable:
chmod +x /home/myuser/scripts/database-import.sh
Create an alias so you can trigger it from anywhere:
nano ~/.bashrc
Add the following to the bottom of your .bashrc file:
alias tblimport='/home/myuser/scripts/database-import.sh'
Update your bash config without requiring logout:
. ~/.bashrc
Run tblimport
in your cli any time you need to export the table rows!