kphcdr 1 year ago
parent
commit
5db5747a36
2 changed files with 33 additions and 1 deletions
  1. 1 1
      Makefile
  2. 32 0
      migrate.sh

+ 1 - 1
Makefile

@@ -3,4 +3,4 @@
 build:
 	go build -o build/ytools
 buildLinux:
-	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o build/
+	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o build/

+ 32 - 0
migrate.sh

@@ -0,0 +1,32 @@
+#!/bin/bash
+
+
+# 定义函数
+function up {
+  	migrate -verbose -source file://database/migrations -database "mysql://root:root@tcp(127.0.0.1)/ppadmin" up
+}
+
+function down {
+  migrate -verbose -source file://database/migrations -database "mysql://root:root@tcp(127.0.0.1)/ppadmin" down
+}
+
+function status {
+  migrate -verbose -source file://database/migrations -database "mysql://root:root@tcp(127.0.0.1)/ppadmin" version
+}
+
+function create {
+  migrate create -ext sql -dir database/migrations -seq "$1"
+}
+
+# 根据参数执行不同的函数
+if [ "$1" == "up" ]; then
+  up
+elif [ "$1" == "down" ]; then
+  down
+elif [ "$1" == "status" ]; then
+  status
+elif [ "$1" == "create" ]; then
+  create $2
+else
+  echo "nothing to do"
+fi