Created
June 15, 2011 13:31
-
-
Save jacaetevha/1027093 to your computer and use it in GitHub Desktop.
Creates a skeleton migration file for Sequel in a timestamp format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [[ "$@" =~ -(-)?h(elp)? ]] | |
then | |
echo '' | |
echo 'This script will create a skeleton migration in a given directory for a given name.' | |
echo 'It accepts up to two parameters.' | |
echo '' | |
echo ' 1. name of the migration (e.g. table name or description of table alteration)' | |
echo ' 2. directory for migration (default: db/migrations)' | |
echo '' | |
echo 'The first parameter is REQUIRED, the second parameter is optional.' | |
exit 0 | |
fi | |
if [ -z $1 ] | |
then | |
echo '' | |
echo 'ERROR: you must provide a name for the migration. Use [-h|--help] for more help.' | |
echo ' e.g. if you are creating a table, give it the table name to create' | |
exit 1 | |
fi | |
migrations_directory=${2-db/migrations} | |
migration_name=$1 | |
timestamp=`date +%Y%m%d%H%M%S_` | |
filename="$migrations_directory/$timestamp$migration_name.rb" | |
cat > $filename <<EOF | |
Sequel.migration do | |
up do | |
end | |
down do | |
end | |
end | |
EOF | |
echo "created $filename" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment