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 openshare/extension/postjevsql--0.0.1.sqlin the tree it prints. EveryREVOKEin it came from oneextension_sql!block.
For the people who maintain it
| Path | What |
|---|---|
| src/ | The tool. Chapter 19. |
| BUCK | :pgrx-schema, a binary run by //crates/postjevsql:ext. |
| Cargo.toml | Generated by tools/cargo-gen (chapter 20). |
← Previous: Chapter 17, tools/ · Up: tools · Next: Chapter 19, pgrx-schema/src/ →