github.com/marinho/drone@v0.2.1-0.20140504195434-d3ba962e89a7/pkg/database/migrate/migration (about) 1 #!/usr/bin/env bash 2 3 REV=$(date -u +%Y%m%d%H%M%S) 4 filename=$1 5 6 TAB="$(printf '\t')" 7 8 titleize() { 9 echo "$1" | sed -r -e "s/-|_/ /g" -e 's/\b(.)/\U\1/g' -e 's/ //g' 10 } 11 12 howto() { 13 echo "Usage:" 14 echo " ./migration create_sample_table" 15 echo "" 16 echo "Above invocation will create a migration script called:" 17 echo " ${REV}_create_sample_table.go" 18 echo "You can add your migration step at the Up and Down function" 19 echo "definition inside the file." 20 echo "" 21 echo "Database transaction available through MigrationDriver," 22 echo "so you can access mg.Tx (sql.Tx instance) directly," 23 echo "there are also some migration helpers available, see api.go" 24 echo "for the list of available helpers (Operation interface)." 25 echo "" 26 } 27 28 [[ $# -eq 0 ]] && howto && exit 0 29 30 cat > ${REV}_$filename.go << EOF 31 package migrate 32 33 type rev${REV} struct{} 34 35 var $(titleize $filename) = &rev${REV}{} 36 37 func (r *rev$REV) Revision() int64 { 38 ${TAB}return $REV 39 } 40 41 func (r *rev$REV) Up(mg *MigrationDriver) error { 42 ${TAB}// Migration steps here 43 } 44 45 func (r *rev$REV) Down(mg *MigrationDriver) error { 46 ${TAB}// Revert migration steps here 47 } 48 EOF