Add dev DB management rules to Makefile (#2643)

This commit is contained in:
Zach Wasserman 2021-10-22 11:26:54 -07:00 committed by GitHub
parent 99673eb148
commit 4808e86c40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 5 deletions

View file

@ -1,4 +1,4 @@
.PHONY: build clean clean-assets e2e-reset-db e2e-serve e2e-setup changelog
.PHONY: build clean clean-assets e2e-reset-db e2e-serve e2e-setup changelog db-reset db-backup db-restore
export GO111MODULE=on
@ -247,3 +247,20 @@ changelog:
sh -c "find changes -type file | grep -v .keep | xargs -I {} sh -c 'grep \"\S\" {}; echo' > new-CHANGELOG.md"
sh -c "cat new-CHANGELOG.md CHANGELOG.md > tmp-CHANGELOG.md && rm new-CHANGELOG.md && mv tmp-CHANGELOG.md CHANGELOG.md"
sh -c "git rm changes/*"
###
# Development DB commands
###
# Reset the development DB
db-reset:
docker-compose exec -T mysql bash -c 'echo "drop database if exists fleet; create database fleet;" | mysql -uroot -ptoor'
./build/fleet prepare db --dev
# Back up the development DB to file
db-backup:
./tools/backup_db/backup.sh
# Restore the development DB from file
db-restore:
./tools/backup_db/restore.sh

View file

@ -229,14 +229,15 @@ Then, in the "SMTP options" section, enter any email address in the "Sender addr
Visit [locahost:8025](http://localhost:8025) to view Mailhog's admin interface which will display all emails sent using the simulated mail server.
## Database Backup/Restore
## Development database management
In the course of development (particularly when crafting database migrations), it may be useful to backup and restore the MySQL database. This can be achieved with the following commands:
In the course of development (particularly when crafting database migrations), it may be useful to
backup, restore, and reset the MySQL database. This can be achieved with the following commands:
Backup:
```
./tools/backup_db/backup.sh
make db-backup
```
The database dump is stored in `backup.sql.gz`.
@ -244,11 +245,18 @@ The database dump is stored in `backup.sql.gz`.
Restore:
```
./tools/backup_db/restore.sh
make db-restore
```
Note that a "restore" will replace the state of the development database with the state from the backup.
Reset:
```
make db-reset
```
## MySQL shell
Connect to the MySQL shell to view and interact directly with the contents of the development database.