mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 00:46:30 +00:00
Add usage info at migration script generator.
Also suppress error at the latest migration script for backward compatibility with existing database, in which open_invitations column wasn't added via migration.
This commit is contained in:
parent
89a00bd448
commit
97825cf6bf
2 changed files with 23 additions and 6 deletions
|
@ -9,10 +9,9 @@ func (r *rev20140310104446) Revision() int64 {
|
|||
}
|
||||
|
||||
func (r *rev20140310104446) Up(mg *MigrationDriver) error {
|
||||
if _, err := mg.AddColumn("settings", "open_invitations BOOLEAN"); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := mg.Tx.Exec("UPDATE settings SET open_invitations=0 WHERE open_invitations IS NULL")
|
||||
// Suppress error here for backward compatibility
|
||||
_, err := mg.AddColumn("settings", "open_invitations BOOLEAN")
|
||||
_, err = mg.Tx.Exec("UPDATE settings SET open_invitations=0 WHERE open_invitations IS NULL")
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,24 @@ 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
|
||||
|
||||
|
@ -20,11 +38,11 @@ func (r *rev$REV) Revision() int64 {
|
|||
${TAB}return $REV
|
||||
}
|
||||
|
||||
func (r *rev$REV) Up(op Operation) error {
|
||||
func (r *rev$REV) Up(mg *MigrationDriver) error {
|
||||
${TAB}// Migration steps here
|
||||
}
|
||||
|
||||
func (r *rev$REV) Down(op Operation) error {
|
||||
func (r *rev$REV) Down(mg *MigrationDriver) error {
|
||||
${TAB}// Revert migration steps here
|
||||
}
|
||||
EOF
|
||||
|
|
Loading…
Reference in a new issue