packages feed

pgstyle-0.1.2.0: CHANGELOG.md

# Changelog

## 0.1.2.0

* pgfmt is now pgstyle, since another project is called pgfmt: the package,
  the command, the library's modules (`PgStyle.*`), the flake's outputs
  (`pgstyle`, `pgstyle-kronor`), the release tarballs, and the repository,
  github.com/kronor-io/pgstyle. Nothing else about the command changes;
  replace `pgfmt` with `pgstyle` where you run it. Versions up to 0.1.1.0
  were released as pgfmt.

* Each release also pushes an image, `ghcr.io/kronor-io/pgstyle`, for
  `linux/amd64` and `linux/arm64`, tagged with the version and `latest`. It
  holds the release's static binary and nothing else:

      docker run --rm -v "$PWD:/work" -u "$(id -u):$(id -g)" ghcr.io/kronor-io/pgstyle --check migrations/*.sql

* The `syntax` backend no longer writes `select` twice for a subquery with
  an explicit `all` (`a in (select all b from u)`), which the parse-tree check
  caught as an error.

* `PgStyle.Layout` is split into modules along its sections: `Monad`,
  `Comments`, `Locations`, `Parens`, `Names`, `Expr`, `Dml` and `Ddl`.
  `docs/readability.md` says how the code is meant to read, and
  `scripts/check` checks what a tool can: fourmolu, and pgstyle's hopinion rules
  in `lint/`. CI runs it. The output is unchanged.

* The `syntax` backend lays out more of the tables, indexes and `alter
  table`s it used to leave to `libpg-query`: an index's `include (...)` and
  `with (...)`, on its `on` line; `alter constraint ... deferrable`; `primary
  key using index` and `unique using index`, which break before `using` if
  long; and `create table ... partition of ... for values ...`, each clause
  on a line of its own. On Kronor's migrations this lays out 25 more
  statements, changing 13 files (24 in upper case).

* The `syntax` backend lays out `create trigger`, `grant` and `revoke`. A
  trigger has each clause on a line of its own, at the statement's column,
  its `when` condition broken like a `check`'s if long. A `grant` or `revoke`
  stays on one line if it fits in 80 characters; otherwise `on` and `to` (or
  `from`) go on lines of their own, indented. On Kronor's migrations this
  lays out 882 more statements, all their triggers and grants, changing 151
  files (390 in upper case); none fails the parse-tree check, and formatting
  again changes nothing.

* The `syntax` backend lays out `create function` and `create procedure`:
  the arguments on the first line, or one per line with the comma at the end
  if they do not fit or have comments; each clause before the body on a line
  of its own, `as` ending the last; the body on the next line, as written (or
  as the PL/pgSQL pass formats it), its opening quote lined up with its
  closing one; the clauses after the body on its last line. Clauses keep their source order and words (`default`
  rather than `libpg-query`'s `=`). A SQL-standard body (`begin atomic ...
  end`, `return ...`) has its statements laid out. On Kronor's migrations this
  lays out 2,184 more statements, changing 1,586 files; none fails the
  parse-tree check, and formatting again changes nothing.

* The `syntax` backend lays out `create index` and `alter table` too, in the
  style they are usually written: an index's `on` and `where` on lines of
  their own (`using` only if written, which `libpg-query` adds), an `alter
  table`'s actions one per line with the comma at the end (keeping `drop
  column`'s `column`, which `libpg-query` drops). A long condition, in an
  index's `where` or a table's `check`, breaks at its top-level `and`s or
  `or`s, a long group in parentheses inside it on lines of its own. Names
  longer than PostgreSQL's 63 bytes, which its parse tree cuts short, are
  written as the source has them. On Kronor's migrations this lays out
  3,015 more statements, changing 746 files; none fails the parse-tree
  check, and formatting again changes nothing.

* The `syntax` backend lays out `create table`, `create view`, `create
  materialized view` and `create table ... as`, which went to `libpg-query`
  before. A table has one column or constraint per line with the comma at
  the end; it keeps the source's keywords, blank lines and comments between
  columns, writes types as `numeric(12, 2)` and references as `t(id)`, and
  breaks long checks at their top-level `and`s or `or`s and long foreign keys
  before `references`. A view's query is laid out like any `select`. Tables
  with `exclude`, storage options, `partition of` and the like still go to
  `libpg-query`. On Kronor's migrations this lays out 1,274 more statements,
  changing about 1,070 files; none fails the parse-tree check, and
  formatting again changes nothing.

* `values` rows go on one line each, `(1, 'a'),`, when every row of the list
  fits in 100 characters and none has a comment inside it; otherwise each
  row's values still go one per line. Lookup-table inserts now read as a
  table. On Kronor's migrations this changes 267 files, only in line breaks
  and spacing.
* A blank line between two `values` rows is kept, so groups of rows stay
  apart, as in `i18n.invoice_page`, the one file on Kronor's migrations it
  changes.

* The `syntax` backend lays out plain SQL statements with comments inside
  them, instead of leaving them as they are (or, with `--backend auto`, to
  `libpg-query`). Each comment goes where the layout breaks a line at its
  place in the source: one sharing a line with code ends the line before the
  break, one on a line of its own stays on one. A list with a comment in it
  (select targets, `set` assignments, call arguments, `in (...)`, `array[...]`,
  `values` rows and their items, insert columns, `group by`, `and`ed
  conditions) puts one item per line. A comment with no break at its place
  (inside an expression, or between the parts of a string continued over
  lines) still leaves the statement as it is. On Kronor's migrations, 177 of
  the 179 DML statements with comments inside are now laid out, along with
  statements with comments in PL/pgSQL bodies; statements without comments
  come out byte for byte the same. The hasql-th dialect still leaves
  statements with comments alone.
* A blank line before a comment on a line of its own is kept, so separate
  comments stay apart.
* Dollar-quoted strings (`$$...$$`, `$body$...$body$`) are kept as written
  instead of being rewritten as `'...'`, which doubled every quote in a
  multi-line job body. On Kronor's migrations these two changes touch 120
  files (mostly `timetable.add_job(...)` calls); nothing else changes.

## 0.1.1.0

* The `syntax` backend lays out plain SQL from libpg_query's parse tree
  (PostgreSQL 18's own parser) instead of postgresql-syntax's, in the same
  layout. On Kronor's migrations, every one of the 2,020 statements it formatted
  before (PL/pgSQL bodies included) comes out byte for byte the same, with
  `--keyword-case lower` and `upper`. It now also lays out DML that
  postgresql-syntax could not parse (`E'...'` strings, `varchar(n)` casts,
  column definition lists, `tablesample`, ...): 96 more statements there.
  Multi-line string literals are no longer re-indented, and numbers are kept
  as written (`1.50`), so statements the old renderer refused as changed now
  format. Statements it does not handle are still left to `libpg-query`. The
  hasql-th dialect still uses postgresql-syntax.
* The safety check compares each statement's parse tree, source positions
  aside, instead of SQL deparsed from it: two different trees the deparser
  prints alike no longer pass. On Kronor's 4,414 migrations the output is
  byte for byte the same as before. Error messages now quote the statement as
  written and as formatted, rather than the deparser's rendering of each.
* Formats the SQL in Haskell files' hasql-th quasiquotes: files ending in
  `.hs`, or stdin with `--haskell`. Comments, strings and character literals
  are skipped as GHC does; each quasiquote's SQL is replaced only if it parses
  back to the same postgresql-syntax AST, and the file must keep the same
  quasiquotes and the same text around them. `--quoter NAME` adds a quoter to
  hasql-th's. On Kronor's code it matches `hasql-th-format`, and also formats
  qualified quoters (`[TH.singletonStatement|`), which that tool skips.
* Builds against Hackage's postgresql-syntax. The hasql-th dialect is upstream
  hasql-th's; the `kronor-syntax` flag (`cabal.project.kronor`, or the flake's
  `pgfmt-kronor`) adds the Haskell targets and param fields of Kronor's fork.
* Builds with the same haskell.nix and nixpkgs as sqiff and sqint, so they
  share one GHC 9.12.4 in the kronor-open cache.

## 0.1.0.1

* Static Linux binaries for x86_64 and aarch64 on each GitHub release, with
  bash, zsh and fish completions. They are built against musl and run on any
  Linux distribution:

      curl -fsSL "https://github.com/kronor-io/pgfmt/releases/latest/download/pgfmt-$(uname -m)-linux.tar.xz" | tar -xJ -C ~/.local

## 0.1.0.0

First release.

* Formats PostgreSQL files statement by statement, and rewrites a statement
  only when libpg_query parses the new text to the same statement, with the
  same number of comments. Text between statements is copied byte for byte.
* Two backends: pgfmt's own renderer for DML, with leading commas, and
  libpg_query's pretty-printer for everything PostgreSQL parses, including all
  DDL. `--backend auto`, the default, uses the first where it can.
* `--check` for CI and pre-commit: names the files that are not formatted and
  exits 1, changing nothing.
* `--keyword-case lower|upper`, applied to every statement in the file,
  whichever backend laid it out. Identifiers are never changed.
* Formats the SQL statements inside PL/pgSQL function bodies, and keeps the new
  body only if it parses to the same PL/pgSQL.
* `SET` values keep their single quotes: `set lock_timeout to '50ms'` stays as
  it is. libpg_query 18.0.0 writes such values as quoted identifiers
  (`"50ms"`); the flake builds it with
  `nix/libpg_query-set-values-as-strings.patch`.
* `--dialect hasql-th` lets the `syntax` backend read hasql-th's quasiquote
  extensions, and the library exposes `PgFmt.Render.formatSql` for them.
* Builds with Nix for `x86_64-linux`, `aarch64-linux` and `aarch64-darwin`;
  binaries come from the kronor-open cache.