mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-30 10:11:23 +02:00
97825cf6bf
Also suppress error at the latest migration script for backward compatibility with existing database, in which open_invitations column wasn't added via migration.
49 lines
1.1 KiB
Bash
Executable File
49 lines
1.1 KiB
Bash
Executable File
#!/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'
|
|
}
|
|
|
|
howto() {
|
|
echo "Usage:"
|
|
echo " ./migration create_sample_table"
|
|
echo ""
|
|
echo "Above invocation will create a migration script called:"
|
|
echo " ${REV}_create_sample_table.go"
|
|
echo "You can add your migration step at the Up and Down function"
|
|
echo "definition inside the file."
|
|
echo ""
|
|
echo "Database transaction available through MigrationDriver,"
|
|
echo "so you can access mg.Tx (sql.Tx instance) directly,"
|
|
echo "there are also some migration helpers available, see api.go"
|
|
echo "for the list of available helpers (Operation interface)."
|
|
echo ""
|
|
}
|
|
|
|
[[ $# -eq 0 ]] && howto && exit 0
|
|
|
|
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(mg *MigrationDriver) error {
|
|
${TAB}// Migration steps here
|
|
}
|
|
|
|
func (r *rev$REV) Down(mg *MigrationDriver) error {
|
|
${TAB}// Revert migration steps here
|
|
}
|
|
EOF
|