feat(assets): add native Go asset/file loader for migrate-apply (#7) #8
No Reviewers
Labels
Clear labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Breaking change that won't be backward compatible
Something is not working
Documentation changes
Improve existing functionality
New functionality
This is security issue
Issue or pull request related to testing
Priority
Critical
The priority is critical
Priority
High
The priority is high
Priority
Low
The priority is low
Priority
Medium
The priority is medium
Reviewed
Confirmed
Issue has been confirmed
Reviewed
Duplicate
This issue or pull request already exists
Reviewed
Invalid
Invalid issue
Reviewed
Won't Fix
This issue won't be fixed
Status
Abandoned
Somebody has started to work on this but abandoned work
Status
Blocked
Something is blocking this issue or pull request
Status
Need More Info
Feedback is required to reproduce issue or to continue work
Breaking change that won't be backward compatible
Something is not working
Documentation changes
Improve existing functionality
New functionality
This is security issue
Issue or pull request related to testing
Priority
Critical
1
The priority is critical
Priority
High
2
The priority is high
Priority
Low
4
The priority is low
Priority
Medium
3
The priority is medium
Reviewed
Confirmed
1
Issue has been confirmed
Reviewed
Duplicate
2
This issue or pull request already exists
Reviewed
Invalid
3
Invalid issue
Reviewed
Won't Fix
3
This issue won't be fixed
Status
Abandoned
3
Somebody has started to work on this but abandoned work
Status
Blocked
1
Something is blocking this issue or pull request
Status
Need More Info
2
Feedback is required to reproduce issue or to continue work
No labels
Milestone
No items
No Milestone
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: wdevs/relspecgo#8
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Implements a native Go asset loader (
relspec assets) that loads local binary and text files into PostgreSQL by binding file bytes as native pgx query parameters — never as SQL text literals.Closes #7.
Key design points
assets.yaml) colocated with asset files describes each entry: source file path, SQL call with:bytes/:filename/:paramnamed placeholders, and an optional staticparamsmap.[]bytevia pgx, so binary files (images, docx, etc.) pass through untouched with no base64/escaping round-trip.{priority}_{sequence}_{name}pattern already used byrelspec scripts, so asset-loading steps can be correctly interleaved with SQL scripts in amigrate-applypipeline.../) are silently skipped to prevent directory escape.::typecast syntax is temporarily masked before placeholder substitution so::textis never misread as a placeholder.New commands
Tests
14 unit tests covering:
::castprotection, unknown, binary byte-exact)Run:
go test ./pkg/assetloader/... -v -raceVerification
Implements a new `relspec assets` command (list/execute subcommands) that loads local binary and text asset files into PostgreSQL by binding file bytes as native pgx query parameters — never as SQL text literals — so binary data stays byte-exact with no escaping overhead. Key design points: - YAML manifest (assets.yaml) colocated with files describes each entry: file path, SQL call with :bytes/:filename/:param named placeholders, and optional static params map. - Placeholder substitution converts :name to positional $N params; PostgreSQL ::cast syntax is protected before substitution to avoid false matches. - Directory scan follows the existing {priority}_{sequence}_{name} naming convention, enabling asset-loading steps to be correctly interleaved with relspec scripts execute in a migrate-apply pipeline. - Symlink components and path traversal (../) are silently skipped to prevent directory escape attacks. - 14 unit tests cover manifest loading, directory scanning, ordering, symlink skipping, path traversal rejection, placeholder substitution edge cases (repeated, cast protection, binary byte-exact, unknown). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>Merged