PsqlTetris (PsqlTetris v0.1.1)

View Source

PostgreSQL column-tetris formatter for Ecto migrations.

This package ships a Mix.Tasks.Format plugin (PsqlTetris.Formatter) that rewrites Ecto migration files so the resulting table's on-disk column layout wastes as few padding bytes as possible. PostgreSQL aligns column values on natural boundaries and slips padding in between, and a "tetris-friendly" column order keeps those gaps small.

See PsqlTetris.Formatter for installation and configuration. You can also call optimize_migration/1 directly on a migration source string.

Summary

Functions

Reorders the columns of every create table / alter table block in the given Elixir migration source string.

Functions

optimize_migration(source)

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

Reorders the columns of every create table / alter table block in the given Elixir migration source string.

Example

source = """
defmodule MyApp.Repo.Migrations.CreateUsers do
  use Ecto.Migration

  def change do
    create table(:users) do
      add :active, :boolean, null: false
      add :email, :string
      add :id_num, :bigint
    end
  end
end
"""

PsqlTetris.optimize_migration(source) |> IO.puts()