mirror of
https://github.com/harness/drone.git
synced 2025-05-11 06:30:06 +08:00
Add shell script to generate migration script.
This commit is contained in:
parent
7b4c698e79
commit
d9e4f3f509
30
pkg/database/migrate/migration
Executable file
30
pkg/database/migrate/migration
Executable file
@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
REV=$(date -u +%Y%m%d%H%M%S)
|
||||||
|
filename=$1
|
||||||
|
|
||||||
|
TAB="$(printf '\t')"
|
||||||
|
|
||||||
|
titleize() {
|
||||||
|
echo "$1" | sed -r -e "s/-|_/ /g" -e 's/\b(.)/\U\1/g' -e 's/ //g'
|
||||||
|
}
|
||||||
|
|
||||||
|
cat > ${REV}_$filename.go << EOF
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
type rev${REV} struct{}
|
||||||
|
|
||||||
|
var $(titleize $filename) = &rev${REV}{}
|
||||||
|
|
||||||
|
func (r *rev$REV) Revision() int64 {
|
||||||
|
${TAB}return $REV
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *rev$REV) Up(op Operation) error {
|
||||||
|
${TAB}// Migration steps here
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *rev$REV) Down(op Operation) error {
|
||||||
|
${TAB}// Revert migration steps here
|
||||||
|
}
|
||||||
|
EOF
|
Loading…
Reference in New Issue
Block a user