schema

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pluralize

func Pluralize(name string) string

func QualifyPackage

func QualifyPackage(pkgPath string) string

func SaveSnapshot

func SaveSnapshot(path string, snap *Snapshot) error

func ToSnakeCase

func ToSnakeCase(in string) string

Types

type Builder

type Builder struct {
	Root string
}

func NewBuilder

func NewBuilder(root string) *Builder

func (*Builder) Build

func (b *Builder) Build(ctx context.Context) (*Schema, error)

type Column

type Column struct {
	Name          string
	GoName        string
	Type          Type
	Nullable      bool
	PrimaryKey    bool
	Unique        bool
	Identity      bool
	AutoIncrement bool
	Default       string
	Generated     string
	SoftDelete    bool
	CreatedAt     bool
	UpdatedAt     bool
	DeletedAt     bool
	CreatedBy     bool
	UpdatedBy     bool
	DeletedBy     bool
	Scope         ScopeKind
	Tags          map[string]string
}

func (Column) IsAuditField

func (c Column) IsAuditField() bool

func (Column) IsScopeField

func (c Column) IsScopeField() bool

func (Column) TagsString

func (c Column) TagsString() string

type Constraint

type Constraint struct {
	Name              string
	Kind              ConstraintKind
	Columns           []string
	ReferencedTable   string
	ReferencedColumns []string
	OnDelete          string
	OnUpdate          string
	Expression        string
	Metadata          map[string]string
}

type ConstraintKind

type ConstraintKind string
const (
	ConstraintPrimaryKey ConstraintKind = "primary_key"
	ConstraintUnique     ConstraintKind = "unique"
	ConstraintForeignKey ConstraintKind = "foreign_key"
	ConstraintCheck      ConstraintKind = "check"
)

type Diff

type Diff struct {
	Operations []Operation
}

func Compare

func Compare(expected, actual *Schema) (*Diff, error)

func (Diff) Empty

func (d Diff) Empty() bool

func (Diff) String

func (d Diff) String() string

type EnumType

type EnumType struct {
	Name     string
	Values   []string
	Metadata map[string]string
}

type Index

type Index struct {
	Name       string
	Columns    []string
	Unique     bool
	Expression string
	Where      string
	Method     string
	Metadata   map[string]string
}

type Inspector

type Inspector interface {
	Inspect(ctx context.Context, db *sql.DB, schemaName string) (*Schema, error)
}

type Operation

type Operation struct {
	Kind       OperationKind
	Table      string
	TableDef   *Table
	Column     *Column
	Previous   *Column
	Index      *Index
	Constraint *Constraint
}

type OperationKind

type OperationKind string
const (
	OpCreateTable      OperationKind = "create_table"
	OpDropTable        OperationKind = "drop_table"
	OpAddColumn        OperationKind = "add_column"
	OpDropColumn       OperationKind = "drop_column"
	OpAlterColumn      OperationKind = "alter_column"
	OpCreateIndex      OperationKind = "create_index"
	OpDropIndex        OperationKind = "drop_index"
	OpCreateConstraint OperationKind = "create_constraint"
	OpDropConstraint   OperationKind = "drop_constraint"
)

type PostgresInspector

type PostgresInspector struct{}

func (PostgresInspector) Inspect

func (PostgresInspector) Inspect(ctx context.Context, db *sql.DB, schemaName string) (*Schema, error)

type Schema

type Schema struct {
	Name    string
	Version int
	Tables  []*Table
	Enums   []*EnumType
	Views   []*View
}

func (*Schema) Clone

func (s *Schema) Clone() *Schema

func (*Schema) Sort

func (s *Schema) Sort()

func (*Schema) Validate

func (s *Schema) Validate() error

type ScopeKind

type ScopeKind string
const (
	ScopeNone         ScopeKind = ""
	ScopeCompany      ScopeKind = "company"
	ScopeTenant       ScopeKind = "tenant"
	ScopeOrganization ScopeKind = "organization"
	ScopeWorkspace    ScopeKind = "workspace"
	ScopeWarehouse    ScopeKind = "warehouse"
	ScopeUser         ScopeKind = "user"
)

type Snapshot

type Snapshot struct {
	GeneratedAt time.Time `json:"generated_at"`
	Schema      *Schema   `json:"schema"`
}

func LoadSnapshot

func LoadSnapshot(path string) (*Snapshot, error)

type Table

type Table struct {
	Name        string
	GoTypeName  string
	PackageName string
	Columns     []*Column
	Indexes     []*Index
	Constraints []*Constraint
	Comments    []string
	Metadata    map[string]string
}

type Type

type Type struct {
	Name       string
	Kind       TypeKind
	Length     int
	Precision  int
	Scale      int
	Nullable   bool
	ArrayOf    *Type
	EnumValues []string
	Metadata   map[string]string
}

type TypeKind

type TypeKind string
const (
	TypeUnknown TypeKind = "unknown"
	TypeBool    TypeKind = "bool"
	TypeInt     TypeKind = "int"
	TypeFloat   TypeKind = "float"
	TypeString  TypeKind = "string"
	TypeBytes   TypeKind = "bytes"
	TypeTime    TypeKind = "time"
	TypeUUID    TypeKind = "uuid"
	TypeJSON    TypeKind = "json"
	TypeArray   TypeKind = "array"
	TypeEnum    TypeKind = "enum"
	TypeCustom  TypeKind = "custom"
)

type View

type View struct {
	Name         string
	SQL          string
	Materialized bool
	Metadata     map[string]string
}

Jump to

Keyboard shortcuts

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