Run delete queries on one or more databases in a given environment. This is useful for delete test account records for users.
go build -o laprune main.go
touch db.json queries.sql
vim db.json # use db.example.json as reference
vim queries.sql # use config/queries.example.sql as reference
./laprune /path/to/db.json /path/to/queries.sql
- ping - Test the database connection
Usage:
./laprune db.json config/queries.sql ping
The valid environment types are:
test
development
staging
production
Install cron
sudo apt-get update
sudo apt-get install cron
Start cron
sudo systemctl start cron
Update permissions for executable
chmod +x /path/to/laprune
Open crontab file for editing
crontab -e
Add cronjob
* * * * * /path/to/laprune
Example of running executable everyday at 1am
0 1 * * * /path/to/laprune
Verify cronjob
crontab -l
- The script requires you pass both db.json and queries.sql file paths. You can provide the directories to each and the program will append the file names to the end and validate if the files exist.
- "ping" argument does not work for MongoDB connections.