tgriesser/knex — pull request #474 by myndzi (2014-09-10 20:54:55+00:00)
Title: Fix sqlite3 rename column

This turned more into a general refactor of the column name replacement code. Besides the problems I've mentioned previously, I realized/encountered a couple more to do with self-referencing foreign keys. A general search and replace on the strings is undesirable unless we can guarantee that nothing bad will happen, which is also I assume why the replacement strings were qualified with commas and stuff. The new method breaks the query into a few pieces and performs replacements only in appropriate places. It does NOT handle expressions in the query flow, since they can basically be just any SQL, but this shouldn't matter for where/how it's being used?

Cases tested: Do nothing if no match, replace column name in string only in the column definition, and not matching string in a foreign key reference to a different table, replace column name in string and self-referencing foreign key