config

package
v1.85.4-souhl.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultDocPath = "dbdoc"
View Source
const DefaultERFormat = "svg"

DefaultERFormat is the default ER diagram format.

View Source
const SchemaFileName = "schema.json"

Variables

View Source
var DefaultConfigFilePaths = []string{".tbls.yml", "tbls.yml", ".tbls.yaml", "tbls.yaml"}
View Source
var DefaultERDistance = 1

DefaultERDistance is the default distance between tables that display relations in the ER.

View Source
var SupportERFormat = []string{"png", "jpg", "svg", "mermaid"}

Functions

This section is empty.

Types

type AdditionalComment

type AdditionalComment struct {
	Table              string              `yaml:"table"`
	TableComment       string              `yaml:"tableComment,omitempty"`
	ColumnComments     map[string]string   `yaml:"columnComments,omitempty"`
	ColumnLabels       map[string][]string `yaml:"columnLabels,omitempty"`
	IndexComments      map[string]string   `yaml:"indexComments,omitempty"`
	ConstraintComments map[string]string   `yaml:"constraintComments,omitempty"`
	TriggerComments    map[string]string   `yaml:"triggerComments,omitempty"`
	// ◆ <column名: maskingType>
	MaskingTypes map[string]string `yaml:"maskingTypes,omitempty"`
	Labels       []string          `yaml:"labels,omitempty"`
}

AdditionalComment is the struct for table relation from yaml.

type AdditionalRelation

type AdditionalRelation struct {
	Table             string   `yaml:"table"`
	Columns           []string `yaml:"columns"`
	Cardinality       string   `yaml:"cardinality,omitempty"`
	ParentTable       string   `yaml:"parentTable"`
	ParentColumns     []string `yaml:"parentColumns"`
	ParentCardinality string   `yaml:"parentCardinality,omitempty"`
	Def               string   `yaml:"def,omitempty"`
	Override          bool     `yaml:"override,omitempty"`
}

AdditionalRelation is the struct for table relation from yaml.

type ColumnCount

type ColumnCount struct {
	Enabled bool     `yaml:"enabled"`
	Max     int      `yaml:"max"`
	Exclude []string `yaml:"exclude"`
}

ColumnCount checks table column count.

func (ColumnCount) Check

func (r ColumnCount) Check(s *schema.Schema, exclude []string) []RuleWarn

Check table column count.

func (ColumnCount) IsEnabled

func (r ColumnCount) IsEnabled() bool

IsEnabled return Rule is enabled or not.

type Config

type Config struct {
	Name   string   `yaml:"name"`
	Desc   string   `yaml:"desc,omitempty"`
	Labels []string `yaml:"labels,omitempty"`
	DSN    DSN      `yaml:"dsn"`
	// Directory of schema document
	DocPath                string                 `yaml:"docPath"`
	Format                 Format                 `yaml:"format,omitempty"`
	ER                     ER                     `yaml:"er,omitempty"`
	Include                []string               `yaml:"include,omitempty"`
	Exclude                []string               `yaml:"exclude,omitempty"`
	Distance               int                    `yaml:"distance,omitempty"`
	Lint                   Lint                   `yaml:"lint,omitempty"`
	LintExclude            []string               `yaml:"lintExclude,omitempty"`
	Viewpoints             []Viewpoint            `yaml:"viewpoints,omitempty"`
	Relations              []AdditionalRelation   `yaml:"relations,omitempty"`
	Comments               []AdditionalComment    `yaml:"comments,omitempty"`
	Dict                   dict.Dict              `yaml:"dict,omitempty"`
	Templates              Templates              `yaml:"templates,omitempty"`
	DetectVirtualRelations DetectVirtualRelations `yaml:"detectVirtualRelations,omitempty"`
	BaseURL                string                 `yaml:"baseUrl,omitempty"`
	RequiredVersion        string                 `yaml:"requiredVersion,omitempty"`
	DisableOutputSchema    bool                   `yaml:"disableOutputSchema,omitempty"`
	MergedDict             dict.Dict              `yaml:"-"`

	// Path of config file
	Path string `yaml:"-"`
	// contains filtered or unexported fields
}

Config is tbls config.

func New

func New() (*Config, error)

New return Config.

func (*Config) FilterTables

func (c *Config) FilterTables(s *schema.Schema) error

FilterTables filter tables from schema.Schema using include: and exclude: and includeLabels.

func (*Config) Load

func (c *Config) Load(configPath string, options ...Option) error

Load config with all method.

func (*Config) LoadConfig

func (c *Config) LoadConfig(in []byte) (err error)

LoadConfig load config from []byte.

func (*Config) LoadConfigFile

func (c *Config) LoadConfigFile(path string) (err error)

LoadConfigFile load config file.

func (*Config) LoadEnviron

func (c *Config) LoadEnviron() error

LoadEnviron load environment variables.

func (*Config) LoadOption

func (c *Config) LoadOption(options ...Option) error

LoadOptions load options.

func (*Config) MaskedDSN

func (c *Config) MaskedDSN() (string, error)

MaskedDSN return DSN mask password.

func (*Config) MergeAdditionalData

func (c *Config) MergeAdditionalData(s *schema.Schema) error

MergeAdditionalData merge relations: comments: to schema.Schema.

func (*Config) ModifySchema

func (c *Config) ModifySchema(s *schema.Schema) error

ModifySchema modify schema.Schema by config.

func (*Config) NeedToGenerateERImages

func (c *Config) NeedToGenerateERImages() bool

func (*Config) SchemaFilePath

func (c *Config) SchemaFilePath() string

type DSN

type DSN struct {
	URL     string            `yaml:"url"`
	Headers map[string]string `yaml:"headers,omitempty"`
}

func (DSN) MarshalYAML

func (d DSN) MarshalYAML() ([]byte, error)

func (*DSN) UnmarshalYAML

func (d *DSN) UnmarshalYAML(data []byte) error

type DetectVirtualRelations

type DetectVirtualRelations struct {
	Enabled  bool   `yaml:"enabled,omitempty"`
	Strategy string `yaml:"strategy,omitempty"`
}

type Dot

type Dot struct {
	Schema string `yaml:"schema,omitempty"`
	Table  string `yaml:"table,omitempty"`
}

Dot holds the paths to the dot template files. If populated the files are used to override the default ones.

type DuplicateRelations

type DuplicateRelations struct {
	Enabled bool `yaml:"enabled"`
}

DuplicateRelations checks duplicate table relations.

func (DuplicateRelations) Check

func (r DuplicateRelations) Check(s *schema.Schema, exclude []string) []RuleWarn

Check duplicate table relations.

func (DuplicateRelations) IsEnabled

func (r DuplicateRelations) IsEnabled() bool

IsEnabled return Rule is enabled or not.

type ER

type ER struct {
	Skip            bool             `yaml:"skip,omitempty"`
	Format          string           `yaml:"format,omitempty"`
	Comment         bool             `yaml:"comment,omitempty"`
	HideDef         bool             `yaml:"hideDef,omitempty"`
	ShowColumnTypes *ShowColumnTypes `yaml:"showColumnTypes,omitempty"`
	Distance        *int             `yaml:"distance,omitempty"`
	Font            string           `yaml:"font,omitempty"`
}

ER is er setting.

type Format

type Format struct {
	Adjust                   bool     `yaml:"adjust,omitempty"`
	Sort                     bool     `yaml:"sort,omitempty"`
	Number                   bool     `yaml:"number,omitempty"`
	ShowOnlyFirstParagraph   bool     `yaml:"showOnlyFirstParagraph,omitempty"`
	HideColumnsWithoutValues []string `yaml:"hideColumnsWithoutValues,omitempty"`
}

Format is document format setting.

func (Format) MarshalYAML

func (f Format) MarshalYAML() ([]byte, error)

func (*Format) UnmarshalYAML

func (f *Format) UnmarshalYAML(data []byte) error

type LabelStyleBigQuery

type LabelStyleBigQuery struct {
	Enabled bool     `yaml:"enabled"`
	Exclude []string `yaml:"exclude"`
}

LabelStyleBigQuery checks if labels are in BigQuery style ( https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements ).

func (LabelStyleBigQuery) Check

func (r LabelStyleBigQuery) Check(s *schema.Schema, exclude []string) []RuleWarn

Check if labels are in BigQuery style.

func (LabelStyleBigQuery) IsEnabled

func (r LabelStyleBigQuery) IsEnabled() bool

IsEnabled return Rule is enabled or not.

type Lint

type Lint struct {
	RequireTableComment      RequireTableComment      `yaml:"requireTableComment"`
	RequireColumnComment     RequireColumnComment     `yaml:"requireColumnComment"`
	RequireIndexComment      RequireIndexComment      `yaml:"requireIndexComment"`
	RequireConstraintComment RequireConstraintComment `yaml:"requireConstraintComment"`
	RequireTriggerComment    RequireTriggerComment    `yaml:"requireTriggerComment"`
	RequireTableLabels       RequireTableLabels       `yaml:"requireTableLabels"`
	UnrelatedTable           UnrelatedTable           `yaml:"unrelatedTable"`
	ColumnCount              ColumnCount              `yaml:"columnCount"`
	RequireColumns           RequireColumns           `yaml:"requireColumns"`
	DuplicateRelations       DuplicateRelations       `yaml:"duplicateRelations"`
	RequireForeignKeyIndex   RequireForeignKeyIndex   `yaml:"requireForeignKeyIndex"`
	LabelStyleBigQuery       LabelStyleBigQuery       `yaml:"labelStyleBigQuery"`
	RequireViewpoints        RequireViewpoints        `yaml:"requireViewpoints"`
	// ◆ 追加
	RequireMaskingTypes RequireMaskingTypes `yaml:"requireMaskingTypes"`
}

Lint is the struct for lint config.

type MD

type MD struct {
	Index     string `yaml:"index,omitempty"`
	Table     string `yaml:"table,omitempty"`
	Viewpoint string `yaml:"viewpoint,omitempty"`
	Enum      string `yaml:"enum,omitempty"`
}

MD holds the paths to the markdown template files. If populated the files are used to override the default ones.

type Mermaid

type Mermaid struct {
	Schema string `yaml:"schema,omitempty"`
	Table  string `yaml:"table,omitempty"`
}

Mermaid holds the paths to the Mermaid template files. If populated the files are used to override the default ones.

type Namer

type Namer func(string) string

Namer is a function type which is given a string and return a string.

type NamingStrategy

type NamingStrategy struct {
	ParentTable  Namer
	ParentColumn Namer
}

NamingStrategy represents naming strategies.

func SelectNamingStrategy

func SelectNamingStrategy(name string) (*NamingStrategy, error)

SelectNamingStrategy sets the naming strategy.

func (*NamingStrategy) ParentColumnName

func (ns *NamingStrategy) ParentColumnName(name string) string

ParentColumnName alters the given name by Column.

func (*NamingStrategy) ParentTableName

func (ns *NamingStrategy) ParentTableName(name string) string

ParentTableName alters the given name by Table.

type Option

type Option func(*Config) error

Option function change Config.

func Adjust

func Adjust(adjust bool) Option

Adjust return Option set Config.Format.Adjust.

func BaseURL

func BaseURL(baseURL string) Option

BaseURL return Option set Config.BaseURL.

func DSNURL

func DSNURL(dsn string) Option

DSNURL return Option set Config.DSN.URL.

func Distance

func Distance(distance int) Option

Distance return Option set Config.Distance.

func DocPath

func DocPath(docPath string) Option

DocPath return Option set Config.DocPath.

func ERFormat

func ERFormat(erFormat string) Option

ERFormat return Option set Config.ER.Format.

func ERSkip

func ERSkip(skip bool) Option

ERSkip return Option set Config.ER.Skip.

func Exclude

func Exclude(e []string) Option

Exclude return Option set Config.Exclude.

func Include

func Include(i []string) Option

Include return Option set Config.Include.

func IncludeLabels

func IncludeLabels(l []string) Option

IncludeLabels return Option set Config.includeLabels.

func Sort

func Sort(sort bool) Option

Sort return Option set Config.Format.Sort.

type PUML

type PUML struct {
	Schema string `yaml:"schema,omitempty"`
	Table  string `yaml:"table,omitempty"`
}

PUML holds the paths to the PlantUML template files. If populated the files are used to override the default ones.

type RequireColumnComment

type RequireColumnComment struct {
	Enabled       bool     `yaml:"enabled"`
	AllOrNothing  bool     `yaml:"allOrNothing"`
	Exclude       []string `yaml:"exclude"`
	ExcludeTables []string `yaml:"excludeTables"`
}

RequireColumnComment checks column comment.

func (RequireColumnComment) Check

func (r RequireColumnComment) Check(s *schema.Schema, exclude []string) []RuleWarn

Check column comment.

func (RequireColumnComment) IsEnabled

func (r RequireColumnComment) IsEnabled() bool

IsEnabled return Rule is enabled or not.

type RequireColumns

type RequireColumns struct {
	Enabled bool                   `yaml:"enabled"`
	Columns []RequireColumnsColumn `yaml:"columns"`
}

RequireColumns checks if the table has specified columns.

func (RequireColumns) Check

func (r RequireColumns) Check(s *schema.Schema, exclude []string) []RuleWarn

Check the existence of a table columns.

func (RequireColumns) IsEnabled

func (r RequireColumns) IsEnabled() bool

IsEnabled return Rule is enabled or not.

type RequireColumnsColumn

type RequireColumnsColumn struct {
	Name    string   `yaml:"name"`
	Exclude []string `yaml:"exclude"`
}

RequireColumnsColumn is required column.

type RequireConstraintComment

type RequireConstraintComment struct {
	Enabled       bool     `yaml:"enabled"`
	AllOrNothing  bool     `yaml:"allOrNothing"`
	Exclude       []string `yaml:"exclude"`
	ExcludeTables []string `yaml:"excludeTables"`
}

RequireConstraintComment checks constraint comment.

func (RequireConstraintComment) Check

func (r RequireConstraintComment) Check(s *schema.Schema, exclude []string) []RuleWarn

Check constraint comment.

func (RequireConstraintComment) IsEnabled

func (r RequireConstraintComment) IsEnabled() bool

IsEnabled return Rule is enabled or not.

type RequireForeignKeyIndex

type RequireForeignKeyIndex struct {
	Enabled bool     `yaml:"enabled"`
	Exclude []string `yaml:"exclude"`
}

RequireForeignKeyIndex checks if the foreign key columns have an index.

func (RequireForeignKeyIndex) Check

func (r RequireForeignKeyIndex) Check(s *schema.Schema, exclude []string) []RuleWarn

Check if the foreign key columns have an index.

func (RequireForeignKeyIndex) IsEnabled

func (r RequireForeignKeyIndex) IsEnabled() bool

IsEnabled return Rule is enabled or not.

type RequireIndexComment

type RequireIndexComment struct {
	Enabled       bool     `yaml:"enabled"`
	AllOrNothing  bool     `yaml:"allOrNothing"`
	Exclude       []string `yaml:"exclude"`
	ExcludeTables []string `yaml:"excludeTables"`
}

RequireIndexComment checks index comment.

func (RequireIndexComment) Check

func (r RequireIndexComment) Check(s *schema.Schema, exclude []string) []RuleWarn

Check index comment.

func (RequireIndexComment) IsEnabled

func (r RequireIndexComment) IsEnabled() bool

IsEnabled return Rule is enabled or not.

type RequireMaskingTypes

type RequireMaskingTypes struct {
	Enabled       bool     `yaml:"enabled"`
	AllOrNothing  bool     `yaml:"allOrNothing"`
	Exclude       []string `yaml:"exclude"`
	ExcludeTables []string `yaml:"excludeTables"`
}

◆ マスキング種別必須ルール ----------------------------------------------

func (RequireMaskingTypes) Check

func (r RequireMaskingTypes) Check(s *schema.Schema, exclude []string) []RuleWarn

func (RequireMaskingTypes) IsEnabled

func (r RequireMaskingTypes) IsEnabled() bool

type RequireTableComment

type RequireTableComment struct {
	Enabled      bool     `yaml:"enabled"`
	AllOrNothing bool     `yaml:"allOrNothing"`
	Exclude      []string `yaml:"exclude"`
}

RequireTableComment checks table comment.

func (RequireTableComment) Check

func (r RequireTableComment) Check(s *schema.Schema, exclude []string) []RuleWarn

Check table comment.

func (RequireTableComment) IsEnabled

func (r RequireTableComment) IsEnabled() bool

IsEnabled return Rule is enabled or not.

type RequireTableLabels

type RequireTableLabels struct {
	Enabled      bool     `yaml:"enabled"`
	AllOrNothing bool     `yaml:"allOrNothing"`
	Exclude      []string `yaml:"exclude"`
}

RequireTableLabels checks table labels.

func (RequireTableLabels) Check

func (r RequireTableLabels) Check(s *schema.Schema, exclude []string) []RuleWarn

Check table labels.

func (RequireTableLabels) IsEnabled

func (r RequireTableLabels) IsEnabled() bool

IsEnabled return Rule is enabled or not.

type RequireTriggerComment

type RequireTriggerComment struct {
	Enabled       bool     `yaml:"enabled"`
	AllOrNothing  bool     `yaml:"allOrNothing"`
	Exclude       []string `yaml:"exclude"`
	ExcludeTables []string `yaml:"excludeTables"`
}

RequireTriggerComment checks trigger comment.

func (RequireTriggerComment) Check

func (r RequireTriggerComment) Check(s *schema.Schema, exclude []string) []RuleWarn

Check trigger comment.

func (RequireTriggerComment) IsEnabled

func (r RequireTriggerComment) IsEnabled() bool

IsEnabled return Rule is enabled or not.

type RequireViewpoints

type RequireViewpoints struct {
	Enabled bool     `yaml:"enabled"`
	Exclude []string `yaml:"exclude"`
}

RequireViewpoints checks if the table is included in any viewpoints.

func (RequireViewpoints) Check

func (r RequireViewpoints) Check(s *schema.Schema, exclude []string) []RuleWarn

Check if the table is included in any viewpoints.

func (RequireViewpoints) IsEnabled

func (r RequireViewpoints) IsEnabled() bool

IsEnabled return Rule is enabled or not.

type Rule

type Rule interface {
	IsEnabled() bool
	Check(schema *schema.Schema, exclude []string) []RuleWarn
}

Rule is interfece of `tbls lint` cop.

type RuleWarn

type RuleWarn struct {
	Target  string
	Message string
}

RuleWarn is struct of Rule error.

type ShowColumnTypes

type ShowColumnTypes struct {
	Related bool `yaml:"related,omitempty"`
	Primary bool `yaml:"primary,omitempty"`
}

ShowColumnTypes is show column setting for ER diagram.

type Templates

type Templates struct {
	MD      MD      `yaml:"md,omitempty"`
	Dot     Dot     `yaml:"dot,omitempty"`
	PUML    PUML    `yaml:"puml,omitempty"`
	Mermaid Mermaid `yaml:"mermaid,omitempty"`
}

Templates holds the configurations to override the default templates used to render the schema and the docs.

type UnrelatedTable

type UnrelatedTable struct {
	Enabled      bool     `yaml:"enabled"`
	AllOrNothing bool     `yaml:"allOrNothing"`
	Exclude      []string `yaml:"exclude"`
}

UnrelatedTable checks isolated table.

func (UnrelatedTable) Check

func (r UnrelatedTable) Check(s *schema.Schema, exclude []string) []RuleWarn

Check table relation.

func (UnrelatedTable) IsEnabled

func (r UnrelatedTable) IsEnabled() bool

IsEnabled return Rule is enabled or not.

type Viewpoint

type Viewpoint struct {
	Name     string           `yaml:"name,omitempty"`
	Desc     string           `yaml:"desc,omitempty"`
	Labels   []string         `yaml:"labels,omitempty"`
	Tables   []string         `yaml:"tables,omitempty"`
	Groups   []ViewpointGroup `yaml:"groups,omitempty"`
	Distance int              `yaml:"distance,omitempty"`
}

type ViewpointGroup

type ViewpointGroup struct {
	Name   string   `yaml:"name,omitempty"`
	Desc   string   `yaml:"desc,omitempty"`
	Labels []string `yaml:"labels,omitempty"`
	Tables []string `yaml:"tables,omitempty"`
	Color  string   `yaml:"color,omitempty"`
}

Jump to

Keyboard shortcuts

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