Available on crate feature
neon only.Expand description
Neon branches as an environment source (feature neon).
An instance can be bound to a branch of a Neon project. The branch then supplies what the
plan’s Neon-hosted placements need (see
Plan::neon_requirements): its Postgres,
its object storage and the URLs of the functions deployed on it. Everything goes through the
Neon CLI behind NeonControl: NeonCli runs neon, and FakeNeon (feature
testing) stands in for it in tests. A pure compose environment never touches it.
bindchecks the branch against the plan’s requirements (a missing function is an error then, not at start), creates the databases and buckets it lacks, and mints a storage credential on the branch for the instance. A child branch inherits its parent’s credentials, so reusing one would leak access into every later branch; each binding mints its own, andunbindrevokes it.NeonBranchSourceis theSourcean instance takes the branch’s overlay from:DATABASE_URL,DATABASE_URL_UNPOOLED,PG*, theNEON_S3_*storage coordinates and each function’s<SLUG>_FUNCTION_URL.- Branches trestle creates (
create_owned_branch) carry an ownership annotation and an expiry. Only owned branches are reset or deleted (reset_owned_branch,delete_owned_branch).
See docs/neon.md for what the CLI prints.
Structs§
- Branch
- A branch of a Neon project.
- Connection
- A branch’s Postgres connection, as
neon connection-string --extendedprints it. - Create
Branch - How to create a branch.
- Fake
Neon - One Neon project in memory, behaving as the spike found the real one does (
docs/neon.md): a new branch copies its parent’s functions, buckets and credentials at creation, a reset leaves functions alone, and annotations are kept. Every change is recorded (calls). - Function
- A function deployed on a branch.
- Neon
Binding - An instance’s binding to a Neon branch: its
SourceBindingconfig forNEON_SOURCE, written bybind. It holds no secret, only where the storage credential’s secret is kept. - Neon
Branch Source - The overlay of the Neon branch an instance is bound to (its source config is a
NeonBinding): - NeonCli
- The Neon CLI (
neon, orneonctl), run with--output json. Signed in the way the CLI is (~/.config/neon, shared with the terminal) or withNEON_API_KEY. - Storage
- A branch’s object storage, as
neon api /projects/<p>/branches/<b>/storagereturns it. - Storage
Credential - A storage credential minted on a branch: the S3 access key id is its
token_id. - Storage
Credential Ref - A storage credential as a binding refers to it: its id (the S3 access key id) and where its secret lives.
Enums§
Constants§
- INSTANCE_
ANNOTATION - The annotation key naming the instance a trestle-created branch was made for.
- NEON_
SOURCE - The name instances bind the Neon source by.
- OWNER
- The value of
OWNER_ANNOTATIONon a trestle-created branch. - OWNER_
ANNOTATION - The annotation key that marks a branch as created by trestle.
Traits§
- Neon
Control - What trestle asks of Neon, per project.
NeonCliruns the Neon CLI;FakeNeon(featuretesting) is an in-memory stand-in.
Functions§
- bind
- Bind an instance to the branch
name_or_idofproject, for a plan that needsreq: - create_
owned_ branch - Create a branch owned by trestle: annotated with
OWNER_ANNOTATION(and theinstance, when it is made for one) and expiring atexpires_at. - delete_
owned_ branch - Delete the branch
name_or_id, if trestle created it. - expires_
in - An RFC 3339 timestamp
ttlfrom now, forCreateBranch::expires_at. - find_
branch - The branch
name_or_idof the project. - locate_
neon - Where the Neon CLI is, in order:
explicit,$NEON_CLI,neononPATH, the Homebrew prefixes and~/.npm-global/bin, a login shell’scommand -v neon, then the same forneonctl. An app started from the Finder has launchd’sPATH, which holds none of them, hence the fixed places and the login shell. - reset_
owned_ branch - Reset the branch
name_or_idto its parent, if trestle created it. - unbind
- Undo
bind: revoke the binding’s storage credential, if it has one.