Add native asset/file loader for binding local files as query parameters during migrate-apply #7
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
Related to #6, but proposing a different (preferred) design after more thought.
We need to load local binary/text asset files (e.g. report template
.md/.docxfiles undersql/vault/borg/data/templates/finance/) into Postgres columns (bytea/text) as part ofmake migrate-apply, alongside the existingrelspec scripts executeseeds/scripts pipeline.#6 proposed a SQL-comment
@embeddirective that gets textually inlined into the.sqlfile before execution. On reflection that's the weaker design: it still round-trips binary data through a SQL text literal (base64/dollar-quoting), which is exactly the kind of encoding/escaping surface area we're trying to avoid, and it couples file-reading logic into the SQL-text preprocessing step.Proposed feature instead: a native Go asset loader
Add a new loader/writer path (e.g.
relspec assets executealongside the existingrelspec scripts execute) that:assets.yamlcolocated with the asset files) describing, per file: the source file path, and the SQL statement/function call to invoke for it, with named placeholders for "file bytes" and "filename" (and any static extra columns/params the manifest supplies).pgxwith the file's bytes bound as a real query parameter ($1::byteaetc.) — never converted to a SQL text literal, so no base64/escaping, no size-related SQL parsing issues, and binary files stay byte-exact.[priority]_[sequence]_[name]ordering convention already used for.sqlscripts/seeds, so asset-loading steps can be interleaved correctly withscripts executein a singlemigrate-applyrun.Example manifest shape (illustrative, not prescriptive)
(
:bytesbound as[]bytevia pgx,:filenameas the base name offile— exact placeholder syntax up to whoever implements it, could reuse whatever variable-substitution conventionfuncspec/sqlexecalready has internally.)Relationship to #6
This supersedes #6 as our preferred direction — recommend closing #6 in favor of this one, or keeping both open as alternatives if there's a simpler use case elsewhere that still wants the lighter-weight
@embedtext-inlining behavior. Leaving that call to the maintainer.Workaround in the meantime
Same as noted in #6: generate the seed
.sqlliterals from source assets via a small script invoked beforemake migrate-apply, committed as a generated file, until native support exists.Implementation complete. PR #8: #8 — Branch: issue-7-native-asset-loader — Commit:
60c5cc40b2— All 14 unit tests pass, make build and make test clean.