catalog

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlterationType

type AlterationType int

AlterationType represents alteration type.

const (
	// AddColumn is a constant value for add column.
	AddColumn AlterationType = iota
	// DropColumn is a constant value for drop column.
	DropColumn
	// ModifyColumn is a constant value for modify column.
	ModifyColumn
	// RenameColumn is a constant value for rename column.
	RenameColumn
	// AddIndex is a constant value for add index.
	AddIndex
	// DropIndex is a constant value for drop index.
	DropIndex
)

type Catalog

type Catalog struct {
	DefaultSchema string
	Schemas       map[string]*Schema
	// contains filtered or unexported fields
}

Catalog represents catalog.

func NewCatalog

func NewCatalog(defaultSchema string) *Catalog

NewCatalog creates a new catalog.

func (*Catalog) AddEnum

func (c *Catalog) AddEnum(schemaName string, enum *Enum) error

AddEnum performs the add enum operation.

func (*Catalog) AddTable

func (c *Catalog) AddTable(schemaName string, table *Table) error

AddTable performs the add table operation.

func (*Catalog) AlterTable

func (c *Catalog) AlterTable(
	schemaName, tableName string,
	alteration TableAlteration,
) error

AlterTable performs the alter table operation.

func (*Catalog) CreateSchema

func (c *Catalog) CreateSchema(name string) (*Schema, error)

CreateSchema performs the create schema operation.

func (*Catalog) DropTable

func (c *Catalog) DropTable(schemaName, tableName string) error

DropTable performs the drop table operation.

func (*Catalog) GetSchema

func (c *Catalog) GetSchema(name string) (*Schema, error)

GetSchema returns schema.

func (*Catalog) GetTable

func (c *Catalog) GetTable(schemaName, tableName string) (*Table, error)

GetTable returns table.

func (*Catalog) ListTables

func (c *Catalog) ListTables(schemaName string) ([]*Table, error)

ListTables performs the list tables operation.

func (*Catalog) RenameTable

func (c *Catalog) RenameTable(schemaName, oldName, newName string) error

RenameTable performs the rename table operation.

type Column

type Column struct {
	Name            string
	DataType        string
	IsNullable      bool
	IsArray         bool
	Length          *int32
	Precision       *int32
	Scale           *int32
	DefaultVal      *string
	CreatedBy       string // migration file that added this column
	ModifiedBy      string // migration file that last modified this column
	IsPrimaryKey    bool
	IsUnique        bool
	IsAutoIncrement bool
	ForeignKey      *ForeignKey // nil if not a foreign key
}

Column represents column.

func NewColumn

func NewColumn(name, dataType string) *Column

NewColumn creates a new column.

func (*Column) Clone

func (c *Column) Clone() *Column

Clone performs the clone operation.

func (*Column) SetArray

func (c *Column) SetArray() *Column

SetArray sets array.

func (*Column) SetAutoIncrement added in v1.0.0

func (c *Column) SetAutoIncrement() *Column

SetAutoIncrement sets auto increment.

func (*Column) SetCreatedBy

func (c *Column) SetCreatedBy(migrationFile string) *Column

SetCreatedBy sets created by.

func (*Column) SetDefault

func (c *Column) SetDefault(defaultValue string) *Column

SetDefault sets default.

func (*Column) SetForeignKey added in v1.0.0

func (c *Column) SetForeignKey(referencedTable, referencedColumn string) *Column

SetForeignKey sets foreign key.

func (*Column) SetLength

func (c *Column) SetLength(length int32) *Column

SetLength sets length.

func (*Column) SetModifiedBy

func (c *Column) SetModifiedBy(migrationFile string) *Column

SetModifiedBy sets modified by.

func (*Column) SetNotNull

func (c *Column) SetNotNull() *Column

SetNotNull sets not null.

func (*Column) SetPrecisionScale

func (c *Column) SetPrecisionScale(precision, scale int32) *Column

SetPrecisionScale sets precision scale.

func (*Column) SetPrimaryKey

func (c *Column) SetPrimaryKey() *Column

SetPrimaryKey sets primary key.

func (*Column) SetUnique

func (c *Column) SetUnique() *Column

SetUnique sets unique.

func (*Column) ValidatePrimaryKeyDatatype

func (c *Column) ValidatePrimaryKeyDatatype(databaseType, migrationFile string) error

ValidatePrimaryKeyDatatype performs the validate primary key datatype operation.

type Enum

type Enum struct {
	Name      string
	Values    []string
	CreatedBy string
}

Enum represents enum.

type ForeignKey added in v1.0.0

type ForeignKey struct {
	ReferencedTable  string
	ReferencedColumn string
}

ForeignKey represents foreign key.

type Index

type Index struct {
	Name      string
	Columns   []string
	IsUnique  bool
	CreatedBy string
}

Index represents index.

type Schema

type Schema struct {
	Name   string
	Tables map[string]*Table
	Enums  map[string]*Enum
}

Schema represents schema.

type Table

type Table struct {
	Schema    string
	Name      string
	Columns   []*Column
	Indexes   []*Index
	CreatedBy string // migration file that created this table
}

Table represents table.

func NewTable

func NewTable(schema, name string) *Table

NewTable creates a new table.

func (*Table) AddColumn

func (t *Table) AddColumn(column *Column) error

AddColumn performs the add column operation.

func (*Table) AddIndex

func (t *Table) AddIndex(index *Index) error

AddIndex performs the add index operation.

func (*Table) Clone

func (t *Table) Clone() *Table

Clone performs the clone operation.

func (*Table) DropColumn

func (t *Table) DropColumn(name string) error

DropColumn performs the drop column operation.

func (*Table) DropIndex

func (t *Table) DropIndex(name string) error

DropIndex performs the drop index operation.

func (*Table) GetColumn

func (t *Table) GetColumn(name string) (*Column, error)

GetColumn returns column.

func (*Table) GetPrimaryKeyColumns

func (t *Table) GetPrimaryKeyColumns() []*Column

GetPrimaryKeyColumns returns primary key columns.

func (*Table) ModifyColumn

func (t *Table) ModifyColumn(name string, newColumn *Column) error

ModifyColumn performs the modify column operation.

func (*Table) RenameColumn

func (t *Table) RenameColumn(oldName, newName string) error

RenameColumn performs the rename column operation.

func (*Table) SetCreatedBy

func (t *Table) SetCreatedBy(migrationFile string) *Table

SetCreatedBy sets created by.

type TableAlteration

type TableAlteration struct {
	Type      AlterationType
	Column    *Column
	OldName   string
	NewName   string
	IndexName string
	IndexDef  *Index
}

TableAlteration represents table alteration.

Jump to

Keyboard shortcuts

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