PsqlTetris.MigrationRewriter (PsqlTetris v0.1.1)

View Source

Text-level rewriter for Ecto migration source files.

Scans for create table(...) do ... end and alter table(...) do ... end blocks and reorders contiguous runs of add/2,3 calls inside them, using PsqlTetris.Optimizer.

A couple of deliberate choices worth knowing about:

  • The original file text is preserved everywhere except inside the bodies we explicitly touch. Comments, blank lines, timestamps(), modify/3, remove/2, index/2 and friends are passed through verbatim and act as barriers that split add runs into separate groups. The reason is intent: a comment or a blank line above a column is usually a deliberate grouping signal from the author, and we should not flatten it.
  • Type classification is done by parsing each add call with Code.string_to_quoted/1. If a call fails to parse (an unusual sigil or heredoc, say), it is left exactly where it was. Better untouched than misordered.

Summary

Functions

rewrite(source)

@spec rewrite(String.t()) :: String.t()