migrate.sh 726 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/bash
  2. # 定义函数
  3. function up {
  4. migrate -verbose -source file://database/migrations -database "mysql://root:root@tcp(127.0.0.1)/ppadmin" up
  5. }
  6. function down {
  7. migrate -verbose -source file://database/migrations -database "mysql://root:root@tcp(127.0.0.1)/ppadmin" down
  8. }
  9. function status {
  10. migrate -verbose -source file://database/migrations -database "mysql://root:root@tcp(127.0.0.1)/ppadmin" version
  11. }
  12. function create {
  13. migrate create -ext sql -dir database/migrations -seq "$1"
  14. }
  15. # 根据参数执行不同的函数
  16. if [ "$1" == "up" ]; then
  17. up
  18. elif [ "$1" == "down" ]; then
  19. down
  20. elif [ "$1" == "status" ]; then
  21. status
  22. elif [ "$1" == "create" ]; then
  23. create $2
  24. else
  25. echo "nothing to do"
  26. fi