Over a million developers have joined DZone.

Rails-reverse-rename-column

·
Emacs lisp macro for rails development to reverse the order of the columns in rename_column
Could use this approach to automatically rewrite most of the migration's "down"


(defun rails-reverse-rename-column ()
  "In a rails migration, from point to end of buffer, reverse the order of renamed columns"
  (interactive)
  (save-excursion
    (while (re-search-forward "rename_column *\"\\([^\"]*\\)\" *, *\"\\([^\"]*\\)\" *, *\"\\([^\"]*\\)\" *$" nil t)
       (replace-match "rename_column \"\\1\", \"\\3\", \"\\2\""))))
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}