_vkigw
Last Updated: May 03, 2017
·
30
· Minkihn

Open pending Rails migrations in your text editor (Example)

When I checkout a new branch from a teammate, I find it a bit tedious to have to guess or list pending migrations manually. Here's a script I use regularly, grepping rake db:migrate:status and cutting the output to retrieve corresponding timestamps with ls. Voila, everything opened in SublimeText.

#!/bin/bash

# Open all your pending Rails migrations into your text editor.
# It's not optimal but should work with gnu and bsd tools.
# Author: Maxime Buffa <mbuffa@gmail.com>

INPUT=$(rake db:migrate:status|grep -e '^  down    '|cut -c 11-24)
VERSIONS=()

for p in ${INPUT}
do
  VERSIONS+=(`ls "db/migrate/${p}"*`)
done
$EDITOR ${VERSIONS[@]}
Say Thanks
Respond