schemameta

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSchemaMetadata

func GetSchemaMetadata(registry forma.SchemaRegistry, schemaID int16) (forma.SchemaAttributeCache, map[int16]string, error)

GetSchemaMetadata returns schema metadata and an attribute-id lookup table. The fast path returns registry-owned maps; callers must not mutate them.

func NewFileSchemaRegistry

func NewFileSchemaRegistry(pool *pgxpool.Pool, schemaTable string, schemaDir string) (forma.SchemaRegistry, error)

NewFileSchemaRegistry creates a new schema registry that reads schema mappings from a PostgreSQL table and loads attribute definitions from JSON files.

Parameters:

  • pool: PostgreSQL connection pool
  • schemaTable: Name of the schema_registry table (e.g., "schema_registry_1234567890")
  • schemaDir: Directory containing the *_attributes.json files

func NewFileSchemaRegistryContext

func NewFileSchemaRegistryContext(ctx context.Context, pool *pgxpool.Pool, schemaTable string, schemaDir string) (forma.SchemaRegistry, error)

func NewFileSchemaRegistryFromDirectory

func NewFileSchemaRegistryFromDirectory(schemaDir string) (forma.SchemaRegistry, error)

NewFileSchemaRegistryFromDirectory creates a schema registry that scans a directory for schema files and auto-assigns IDs (starting from 100). This mode does not require a database connection.

Parameters:

  • schemaDir: Directory containing the schema files (*.json and *_attributes.json)

Types

type DBPool

type DBPool interface {
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
}

DBPool is a minimal interface for the methods MetadataLoader needs.

type MetadataCache

type MetadataCache struct {
	// contains filtered or unexported fields
}

MetadataCache holds all metadata mappings for fast lookups

func NewMetadataCache

func NewMetadataCache() *MetadataCache

NewMetadataCache creates a new metadata cache

func (*MetadataCache) GetSchemaCache

func (mc *MetadataCache) GetSchemaCache(schemaName string) (forma.SchemaAttributeCache, bool)

GetSchemaCache retrieves the schema attribute cache for a schema (thread-safe). The returned map is the registry-owned snapshot — callers must treat it as read-only.

func (*MetadataCache) GetSchemaCacheByID

func (mc *MetadataCache) GetSchemaCacheByID(schemaID int16) (forma.SchemaAttributeCache, bool)

GetSchemaCacheByID is the schema-ID variant of GetSchemaCache; the same read-only contract applies.

func (*MetadataCache) GetSchemaID

func (mc *MetadataCache) GetSchemaID(schemaName string) (int16, bool)

GetSchemaID retrieves schema ID by name (thread-safe)

func (*MetadataCache) GetSchemaName

func (mc *MetadataCache) GetSchemaName(schemaID int16) (string, bool)

GetSchemaName retrieves schema name by ID (thread-safe)

func (*MetadataCache) ListSchemas

func (mc *MetadataCache) ListSchemas() []string

ListSchemas returns all schema names (thread-safe)

func (*MetadataCache) RegisterSchema

func (mc *MetadataCache) RegisterSchema(schemaName string, schemaID int16, cache forma.SchemaAttributeCache) error

func (*MetadataCache) RetiredAttributeIDs

func (mc *MetadataCache) RetiredAttributeIDs(schemaID int16) map[int16]string

RetiredAttributeIDs returns the schema's retired ledger entries as attributeID → attribute name (#341). Validation tooling only: it hands back neither forma.AttributeMetadata nor the live map, so it cannot become a read, write, flush, or projection path for a retired attribute — the invariant activeAttributeCache states. Returns nil for an unknown schema or one with no retired entries.

func (*MetadataCache) SchemaFingerprint

func (mc *MetadataCache) SchemaFingerprint(schemaID int16) (string, bool)

SchemaFingerprint returns the content fingerprint recorded at registration; plan-cache keys include it as the invalidation lever.

type MetadataLoader

type MetadataLoader struct {
	// contains filtered or unexported fields
}

MetadataLoader loads schema and attribute metadata from database and JSON files

func NewMetadataLoader

func NewMetadataLoader(pool DBPool, schemaTableName, schemaDirectory string) *MetadataLoader

NewMetadataLoader creates a new metadata loader

func (*MetadataLoader) LoadMetadata

func (ml *MetadataLoader) LoadMetadata(ctx context.Context) (*MetadataCache, error)

LoadMetadata loads all metadata and returns a cache

type SchemaMetadata

type SchemaMetadata struct {
	SchemaName    string                    `json:"schema_name"`
	SchemaID      int16                     `json:"schema_id"`
	SchemaVersion int                       `json:"schema_version"`
	Attributes    []forma.AttributeMetadata `json:"attributes"`
}

SchemaMetadata aggregates attribute mappings for a schema version.

Jump to

Keyboard shortcuts

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