Go/migrate: Difference between revisions
< Go
Jump to navigation
Jump to search
| (One intermediate revision by the same user not shown) | |||
| Line 18: | Line 18: | ||
migrate -path assets/migrations -database "postgres://sysop:mypass@localhost:45432/mydb" down | migrate -path assets/migrations -database "postgres://sysop:mypass@localhost:45432/mydb" down | ||
</syntaxhighlight> | </syntaxhighlight> | ||
} | |} | ||
== Taskfile.yaml == | |||
<syntaxhighlight lang="yaml"> | |||
mig-up: | |||
desc: "Use golang-migrate to upgrade db" | |||
cmds: | |||
- migrate -path assets/migrations -database "postgres://sysop:mypass@localhost:45432/mydb" up | |||
mig-down: | |||
desc: "Use golang-migrate to downgrade db" | |||
cmds: | |||
- migrate -path assets/migrations -database "postgres://sysop:mypass@localhost:45432/mydb" down | |||
mig-create: | |||
desc: "Use golang-migrate to create up/down file (Usage: task mig-create -- NAME)" | |||
CLI_ARGS: true | |||
cmds: | |||
# by date | |||
# - migrate create -ext sql -dir assets/migrations -format "20060102" -tz "Asia/Taipei" {{.CLI_ARGS}} | |||
# by sequence number | |||
- migrate create -ext sql -dir assets/migrations -seq {{.CLI_ARGS}} | |||
</syntaxhighlight> | |||
== DSN Problem == | == DSN Problem == | ||
Latest revision as of 10:30, 28 July 2026
Best practice
| Purpose | Command |
|---|---|
| create |
migrate create -ext sql -dir assets/migrations -seq {{.CLI_ARGS}}
|
| up |
migrate -path assets/migrations -database "postgres://sysop:mypass@localhost:45432/mydb" up
|
| down |
migrate -path assets/migrations -database "postgres://sysop:mypass@localhost:45432/mydb" down
|
Taskfile.yaml
mig-up:
desc: "Use golang-migrate to upgrade db"
cmds:
- migrate -path assets/migrations -database "postgres://sysop:mypass@localhost:45432/mydb" up
mig-down:
desc: "Use golang-migrate to downgrade db"
cmds:
- migrate -path assets/migrations -database "postgres://sysop:mypass@localhost:45432/mydb" down
mig-create:
desc: "Use golang-migrate to create up/down file (Usage: task mig-create -- NAME)"
CLI_ARGS: true
cmds:
# by date
# - migrate create -ext sql -dir assets/migrations -format "20060102" -tz "Asia/Taipei" {{.CLI_ARGS}}
# by sequence number
- migrate create -ext sql -dir assets/migrations -seq {{.CLI_ARGS}}