Chapter 18: pgrx-schema, the install SQL read out of the library

CREATE EXTENSION postjevsql runs an install script, postjevsql--0.0.1.sql, that declares every function, type and table the extension has. Nobody writes that script. pgrx works it out from the Rust: each #[pg_extern] and extension_sql! leaves a description of itself in the compiled library, in a section of the .so called .pgrxsc. Under cargo, cargo pgrx schema reads those descriptions and writes the script.

Under buck there is no cargo-pgrx, so this tool does that one part of its job. It opens the built .so as an object file, finds the schema section, decodes the entities, puts the control file at the root of them, and asks pgrx's own pgrx-sql-entity-graph to write the SQL: the library cargo-pgrx writes its scripts with.

flowchart LR
  rs["pg_extern functions and extension_sql! blocks in lib.rs"] -->|"rustc"| so["postjevsql.so, with a .pgrxsc section"]
  so --> PS["pgrx-schema"]
  ctl["postjevsql.control"] --> PS
  PS --> sql["share/extension/postjevsql--0.0.1.sql"]
pgrx-schema <lib-name> <lib.so> <control-file> <out.sql>

Try it. nix develop -c buck2 build //crates/postjevsql:ext --show-output, then open share/extension/postjevsql--0.0.1.sql in the tree it prints. Every REVOKE in it came from one extension_sql! block.

For the people who maintain it

PathWhat
src/The tool. Chapter 19.
BUCK:pgrx-schema, a binary run by //crates/postjevsql:ext.
Cargo.tomlGenerated by tools/cargo-gen (chapter 20).

← Previous: Chapter 17, tools/ · Up: tools · Next: Chapter 19, pgrx-schema/src/ →