schema

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeFK = "FOREIGN KEY"
	TypePK = "PRIMARY KEY"
	TypeUQ = "UNIQUE"
)

Variables

View Source
var PatchDropDisable bool = false

Functions

func Funcs

func Funcs() map[string]interface{}

Types

type Column

type Column struct {
	Name            string         `json:"name"`
	Type            string         `json:"type"`
	Nullable        bool           `json:"nullable"`
	PrimaryKey      bool           `json:"pk"`
	Default         sql.NullString `json:"default"`
	Comment         string         `json:"comment"`
	ParentRelations []*Relation    `json:"-"`
	ChildRelations  []*Relation    `json:"-"`
}

Column is the struct for table column

func (*Column) Validate added in v1.1.0

func (c *Column) Validate() error

type Constraint

type Constraint struct {
	Name             string   `json:"name"`
	Type             string   `json:"type"`
	Def              string   `json:"def"`
	Check            string   `json:"check"`
	OnDelete         string   `json:"onDelete"`
	Table            *string  `json:"table"`
	ReferenceTable   *string  `json:"reference_table" yaml:"referenceTable"`
	Columns          []string `json:"columns"`
	ReferenceColumns []string `json:"reference_columns" yaml:"referenceColumns"`
	Comment          string   `json:"comment"`
}

Constraint is the struct for database constraint

func (*Constraint) Validate added in v1.1.0

func (c *Constraint) Validate() error

type Index

type Index struct {
	Name         string `json:"name"`
	IsPrimary    bool
	IsUnique     bool
	IsClustered  bool
	MethodName   string
	Def          string   `json:"def"`
	Table        *string  `json:"table"`
	Columns      []string `json:"columns"`
	Concurrently bool     `json:"concurrently,omitempty"`
	ColDef       string   `json:"coldef,omitempty"`
	With         string   `json:"with,omitempty"`
	Tablespace   string   `json:"tablespace,omitempty"`
	Where        string   `json:"where,omitempty"`
	Comment      string   `json:"comment"`
}

Index is the struct for database index

func (*Index) Validate added in v1.1.0

func (idx *Index) Validate() error

type PatchColumn

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

func (*PatchColumn) GenerateSQL

func (c *PatchColumn) GenerateSQL() []string

type PatchConstraint

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

func (*PatchConstraint) GenerateSQL

func (c *PatchConstraint) GenerateSQL() []string

type PatchIndex

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

func (*PatchIndex) GenerateSQL

func (i *PatchIndex) GenerateSQL() []string

type PatchRelation

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

func (*PatchRelation) GenerateSQL

func (r *PatchRelation) GenerateSQL() []string

type PatchSchema

type PatchSchema struct {
	CurrentSchema string
	// contains filtered or unexported fields
}

func (*PatchSchema) Build

func (s *PatchSchema) Build(from, to *Schema) error

func (*PatchSchema) GenerateSQL

func (t *PatchSchema) GenerateSQL() (ret []string)

type PatchTable

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

func (*PatchTable) GenerateSQL

func (t *PatchTable) GenerateSQL() []string

type PlantUML

type PlantUML struct {
	Distance int
}

PlantUML struct

func NewPlantUML

func NewPlantUML(distance int) *PlantUML

New return PlantUML

func (*PlantUML) OutputSchema

func (p *PlantUML) OutputSchema(wr io.Writer, s *Schema) error

OutputSchema output dot format for full relation.

type Relation

type Relation struct {
	Name          string    `json:"name"`
	Table         *Table    `json:"table"`
	Columns       []*Column `json:"columns"`
	ParentTable   *Table    `json:"parent_table" yaml:"parentTable"`
	ParentColumns []*Column `json:"parent_columns" yaml:"parentColumns"`
	OnDelete      string    `json:"onDelete"`
	Def           string    `json:"def"`
}

Relation is the struct for table relation

func (*Relation) Validate added in v1.1.0

func (r *Relation) Validate() error

type Schema

type Schema struct {
	Name          string      `json:"name"`
	Desc          string      `json:"desc"`
	Tables        []*Table    `json:"tables"`
	Relations     []*Relation `json:"relations"`
	CurrentSchema string      `json:"currentSchema"`
	SearchPaths   []string    `json:"searchPaths,omitempty"`
}

Schema is the struct for database schema

func (*Schema) FindRelation

func (s *Schema) FindRelation(tblName string, cs, pcs []*Column) (*Relation, error)

FindRelation ...

func (*Schema) FindTableByName

func (s *Schema) FindTableByName(name string) (*Table, error)

FindTableByName find table by table name

func (*Schema) LoadYaml

func (s *Schema) LoadYaml(r io.Reader) error

func (*Schema) MarshalYAML

func (s *Schema) MarshalYAML() ([]byte, error)

func (*Schema) NormalizeTableName

func (s *Schema) NormalizeTableName(name string) string

func (*Schema) NormalizeTableNames

func (s *Schema) NormalizeTableNames(names []string) []string

func (*Schema) Repair

func (s *Schema) Repair() error

Repair column relations

func (*Schema) SavePlantUml

func (s *Schema) SavePlantUml(wr io.Writer, distance int) error

func (*Schema) SaveYaml

func (s *Schema) SaveYaml(wr io.Writer) error

func (*Schema) Sort

func (s *Schema) Sort()

Sort schema tables, columns, relations, and constrains

func (*Schema) UnmarshalYAML

func (s *Schema) UnmarshalYAML(data []byte) error

func (*Schema) Validate added in v1.1.0

func (s *Schema) Validate() error

type Table

type Table struct {
	Name        string        `json:"name"`
	Type        string        `json:"type"`
	Comment     string        `json:"comment"`
	Columns     []*Column     `json:"columns"`
	Indexes     []*Index      `json:"indexes"`
	Constraints []*Constraint `json:"constraints"`
	Def         string        `json:"def"`
}

Table is the struct for database table

func (*Table) CollectTablesAndRelations

func (t *Table) CollectTablesAndRelations(distance int, root bool) ([]*Table, []*Relation, error)

func (*Table) FindColumnByName

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

FindColumnByName find column by column name

func (*Table) FindConstrainsByColumnName

func (t *Table) FindConstrainsByColumnName(name string) []*Constraint

FindConstrainsByColumnName find constraint by column name

func (*Table) FindConstraintByName

func (t *Table) FindConstraintByName(name string) (*Constraint, error)

FindConstraintByName find constraint by constraint name

func (*Table) FindIndexByName

func (t *Table) FindIndexByName(name string) (*Index, error)

FindIndexByName find index by index name

func (*Table) Validate added in v1.1.0

func (t *Table) Validate() error

type YamlColumn

type YamlColumn struct {
	Type       string  `yaml:"type"`
	Nullable   bool    `yaml:"nullable,omitempty"`
	PrimaryKey bool    `yaml:"pk,omitempty"`
	Default    *string `yaml:"default,omitempty"`
}

type YamlConstraint

type YamlConstraint struct {
	Type             string   `yaml:"type,omitempty"`
	Check            string   `json:"check,omitempty"`
	OnDelete         string   `json:"onDelete,omitempty"`
	ReferenceTable   string   `yaml:"referenceTable,omitempty"`
	Columns          []string `yaml:"columns,flow"`
	ReferenceColumns []string `yaml:"referenceColumns,flow,omitempty"`
}

type YamlIndex

type YamlIndex struct {
	IsPrimary    bool     `yaml:"isPrimary,omitempty"`
	IsUnique     bool     `yaml:"isUnique,omitempty"`
	IsClustered  bool     `yaml:"isClustered,omitempty"`
	Concurrently bool     `yaml:"concurrently,omitempty"`
	MethodName   string   `yaml:"method,omitempty"`
	Columns      []string `yaml:"columns,flow"`
	ColDef       string   `yaml:"coldef,omitempty"`
	With         string   `yaml:"with,omitempty"`
	Tablespace   string   `yaml:"tablespace,omitempty"`
	Where        string   `yaml:"where,omitempty"`
}

type YamlRelation

type YamlRelation struct {
	Name          string   `yaml:"name"`
	Columns       []string `yaml:"columns,flow"`
	ParentColumns []string `yaml:"parentColumns,flow"`
	OnDelete      string   `yaml:"onDelete,omitempty"`
}

type YamlSchema

type YamlSchema struct {
	Name   string                `yaml:"name"`
	Schema string                `yaml:"schema"`
	Tables map[string]*YamlTable `yaml:"tables"`
}

type YamlTable

type YamlTable struct {
	Type        string                     `yaml:"type,omitempty"`
	Columns     map[string]*YamlColumn     `yaml:"columns"`
	Indexes     map[string]*YamlIndex      `yaml:"indexes,omitempty"`
	Constraints map[string]*YamlConstraint `yaml:"constraints,omitempty"`
	Relations   map[string]*YamlRelation   `yaml:"relations,omitempty"` // key = parent table
	Def         string                     `yaml:"def,omitempty"`
}

Jump to

Keyboard shortcuts

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