schemalock

package
v0.3.26 Latest Latest
Warning

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

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

Documentation

Overview

Package schemalock owns the deterministic, backend-independent database schema artifact consumed by compiler integrations and command-line tools.

Index

Constants

View Source
const FormatVersion = 1

Variables

This section is empty.

Functions

func ConstraintKey

func ConstraintKey(primary bool, columns []string) string

func Equal

func Equal(left, right *Lock) (bool, error)

func ForeignKeyKey

func ForeignKeyKey(column, table, referencedColumn string) string

Types

type Column

type Column struct {
	// DatabaseType is used while parsing SQL but is intentionally omitted from
	// the lock. The lock records the portable type contract, while sqldef owns
	// database-specific details such as varchar lengths and storage aliases.
	DatabaseType string `json:"-"`
	Type         string `json:"type"`
	Nullable     bool   `json:"nullable"`
	PrimaryKey   bool   `json:"primaryKey,omitempty"`
	HasDefault   bool   `json:"hasDefault,omitempty"`
	Generated    bool   `json:"generated,omitempty"`
}

type ForeignKey

type ForeignKey struct {
	Column           string `json:"column"`
	ReferencedTable  string `json:"referencedTable"`
	ReferencedColumn string `json:"referencedColumn"`
}

type Lock

type Lock struct {
	FormatVersion int              `json:"formatVersion"`
	Adapter       string           `json:"adapter"`
	Tables        map[string]Table `json:"tables"`
}

func New

func New(adapter string) *Lock

func ParseSQL

func ParseSQL(adapter string, source []byte) (*Lock, error)

func Read

func Read(path string) (*Lock, error)

func (*Lock) Bytes

func (l *Lock) Bytes() ([]byte, error)

func (*Lock) Validate

func (l *Lock) Validate() error

func (*Lock) ValidateAdapter

func (l *Lock) ValidateAdapter() error

func (*Lock) Write

func (l *Lock) Write(path string) error

type Table

type Table struct {
	Columns           map[string]Column           `json:"columns"`
	ForeignKeys       map[string]ForeignKey       `json:"foreignKeys,omitempty"`
	UniqueConstraints map[string]UniqueConstraint `json:"uniqueConstraints,omitempty"`
}

type UniqueConstraint

type UniqueConstraint struct {
	Columns []string `json:"columns"`
	Primary bool     `json:"primary,omitempty"`
}

Jump to

Keyboard shortcuts

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