1# Chapter 18: pgrx-schema, the install SQL read out of the library
2
3`CREATE EXTENSION postjevsql` runs an install script,
4`postjevsql--0.0.1.sql`, that declares every function, type and table the
5extension has. Nobody writes that script. pgrx works it out from the Rust:
6each `#[pg_extern]` and `extension_sql!` leaves a description of itself in
7the compiled library, in a section of the `.so` called `.pgrxsc`. Under
8cargo, `cargo pgrx schema` reads those descriptions and writes the script.
9
10Under buck there is no cargo-pgrx, so this tool does that one part of its
11job. It opens the built `.so` as an object file, finds the schema section,
12decodes the entities, puts the control file at the root of them, and asks
13pgrx's own `pgrx-sql-entity-graph` to write the SQL: the library
14cargo-pgrx writes its scripts with.
15
16```mermaid
17flowchart LR
18  rs["pg_extern functions and extension_sql! blocks in lib.rs"] -->|"rustc"| so["postjevsql.so, with a .pgrxsc section"]
19  so --> PS["pgrx-schema"]
20  ctl["postjevsql.control"] --> PS
21  PS --> sql["share/extension/postjevsql--0.0.1.sql"]
22```
23
24    pgrx-schema <lib-name> <lib.so> <control-file> <out.sql>
25
26> **Try it.** `nix develop -c buck2 build //crates/postjevsql:ext
27> --show-output`, then open `share/extension/postjevsql--0.0.1.sql` in the
28> tree it prints. Every `REVOKE` in it came from one `extension_sql!` block.
29
30## For the people who maintain it
31
32| Path | What |
33| --- | --- |
34| [src/](src/) | The tool. Chapter 19. |
35| [BUCK](BUCK) | `:pgrx-schema`, a binary run by `//crates/postjevsql:ext`. |
36| [Cargo.toml](Cargo.toml) | Generated by `tools/cargo-gen` (chapter 20). |
37
38← Previous: [Chapter 17, tools/](../) · Up: [tools](../) · Next: [Chapter 19, pgrx-schema/src/](src/) →