Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Rails-reverse-rename-column

DZone's Guide to

Rails-reverse-rename-column

· ·
Free Resource
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:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}