variable

package
v1.0.0-alpha.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package variable holds the dialect-independent row shape, query options and domain mapping for the variables table.

A variable row is one domain.Variable: a value entered by one owner under one name. The owner is the project and, optionally, one of its environments. An environment that is not addressed is stored as the empty string rather than NULL, which keeps the natural key usable as a primary key; only the project is required, and see the postgres migration for why.

Both owner columns carry a foreign key. The environment reaches its through a generated column (NULLIF of environment_id), which is what lets the empty string stay an address while an id that no environment answers to is still refused by the database. That column is deliberately not bound in Schema: it is derived and never written, and every statement addresses environment_id.

The environment is addressed by id, not by the name the wire carries: the name is resolved once at the edge, so a rename does not have to rewrite every row that points at the environment.

Unlike the settings table this replaces, there is no ladder and no final flag, so storage never collapses rows -- and never has to. A read admits one owner exactly (VisibleTo, which is domain.VariableOwner.HasAccessTo pushed into SQL), and the primary key makes a name unique within it, so a name yields at most one row.

Index

Constants

This section is empty.

Variables

View Source
var Schema = database.NewSchema(map[VariableStorageField]database.FieldBinding[VariableStorage]{
	VariableStorageFieldName: {
		SQLName:  "name",
		Accessor: func(v *VariableStorage) any { return v.Name },
		Coerce:   database.CoerceString,
	},
	VariableStorageFieldProjectID: {
		SQLName:  "project_id",
		Accessor: func(v *VariableStorage) any { return v.ProjectID },
		Coerce:   database.CoerceString,
	},
	VariableStorageFieldEnvironmentID: {
		SQLName:  "environment_id",
		Accessor: func(v *VariableStorage) any { return v.EnvironmentID },
		Coerce:   database.CoerceString,
	},
	VariableStorageFieldValue: {
		SQLName:  "value",
		Accessor: func(v *VariableStorage) any { return v.Value },
		Coerce:   database.CoerceJSON[any],
	},
	VariableStorageFieldIsSecret: {
		SQLName:  "is_secret",
		Accessor: func(v *VariableStorage) any { return v.IsSecret },
		Coerce:   database.CoerceBool,
	},
	VariableStorageFieldCreatedAt: {
		SQLName:  "created_at",
		Accessor: func(v *VariableStorage) any { return v.CreatedAt },
		Coerce:   database.CoerceTime,
	},
	VariableStorageFieldModifiedAt: {
		SQLName:  "modified_at",
		Accessor: func(v *VariableStorage) any { return v.ModifiedAt },
		Coerce:   database.CoerceTime,
	},
})

Schema binds variable filter/order fields. Both owner columns are NOT NULL (environment_id with an empty-string default), so none of the keyset null handling applies.

Functions

func ByName

ByName gives the read a total order that does not depend on physical row order, so the same owner reading the same table twice gets the same slice. Name alone is enough to be total: the read admits one owner, and the primary key makes a name unique within it.

func RowToDomain

func RowToDomain(row *VariableStorage) *domain.Variable

RowToDomain converts one row into the domain variable.

func ToDomain

func ToDomain(rows []*VariableStorage) []*domain.Variable

ToDomain converts scanned rows, preserving the order they were scanned in.

func VisibleTo

VisibleTo restricts the variables table to the rows owner entered, optionally narrowed to names. It is domain.VariableOwner.HasAccessTo pushed into SQL: every owner column has to match exactly.

Equality, not the "unset means inherited" form: an owner is an address, not a position in a ladder, so a name at an owner is one row rather than a set to rank (ADR 062 §4).

Filtering here rather than after the scan is what keeps another environment's variable out of a read. The domain predicate is not applied a second time, so unlike the settings ladder this replaced, an unfiltered caller is not safe -- every read goes through here.

Types

type VariableStorage

type VariableStorage struct {
	Name          string
	ProjectID     string
	EnvironmentID string
	Value         any
	IsSecret      bool
	CreatedAt     time.Time
	ModifiedAt    time.Time
}

VariableStorage is the row shape. It mirrors domain.Variable with the owner tuple flattened onto the row and the two row timestamps added, neither of which the domain type carries.

type VariableStorageField

type VariableStorageField uint8
const (
	VariableStorageFieldName VariableStorageField = iota
	VariableStorageFieldProjectID
	VariableStorageFieldEnvironmentID
	VariableStorageFieldValue
	VariableStorageFieldIsSecret
	VariableStorageFieldCreatedAt
	VariableStorageFieldModifiedAt
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL