Documentation
¶
Overview ¶
Package types defines the shared schema data structures used throughout makemigrations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ValidFieldTypes = map[string]bool{ "varchar": true, "text": true, "integer": true, "bigint": true, "float": true, "decimal": true, "boolean": true, "date": true, "timestamp": true, "time": true, "uuid": true, "json": true, "jsonb": true, "serial": true, "bytes": true, "foreign_key": true, "many_to_many": true, "text[]": true, }
ValidFieldTypes represents valid YAML field types
Functions ¶
func IsValidDatabase ¶
IsValidDatabase checks if a database type is valid
func IsValidFieldType ¶
IsValidFieldType checks if a field type is valid
Types ¶
type Database ¶
type Database struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
MigrationVersion string `yaml:"migration_version,omitempty"`
}
Database represents the database metadata
type DatabaseType ¶
type DatabaseType string
DatabaseType represents supported database types
const ( DatabasePostgreSQL DatabaseType = "postgresql" DatabaseMySQL DatabaseType = "mysql" DatabaseSQLServer DatabaseType = "sqlserver" DatabaseSQLite DatabaseType = "sqlite" DatabaseRedshift DatabaseType = "redshift" DatabaseClickHouse DatabaseType = "clickhouse" DatabaseTiDB DatabaseType = "tidb" DatabaseVertica DatabaseType = "vertica" DatabaseYDB DatabaseType = "ydb" DatabaseTurso DatabaseType = "turso" DatabaseStarRocks DatabaseType = "starrocks" DatabaseAuroraDSQL DatabaseType = "auroradsql" )
DatabaseType constants enumerate the supported database backends.
func ParseDatabaseType ¶
func ParseDatabaseType(db string) (DatabaseType, error)
ParseDatabaseType parses a string into a DatabaseType
type Defaults ¶
type Defaults map[DatabaseType]map[string]string
Defaults represents default value mappings per database type. It is a map from DatabaseType to a map of symbolic default keys to SQL expressions.
func (Defaults) ForProvider ¶
func (d Defaults) ForProvider(dbType DatabaseType) map[string]string
ForProvider returns the defaults map for the given database type, or nil.
func (Defaults) SetForProvider ¶
func (d Defaults) SetForProvider(dbType DatabaseType, defaults map[string]string)
SetForProvider sets the defaults map for the given database type. The receiver must be a non-nil map (use make(Defaults) or Defaults{} first).
func (*Defaults) UnmarshalYAML ¶
UnmarshalYAML implements custom YAML unmarshaling so that YAML keys (lowercase strings like "postgresql") are converted to DatabaseType keys.
type Field ¶
type Field struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
PrimaryKey bool `yaml:"primary_key,omitempty"`
Nullable *bool `yaml:"nullable,omitempty"`
Default string `yaml:"default,omitempty"`
Length int `yaml:"length,omitempty"`
Precision int `yaml:"precision,omitempty"`
Scale int `yaml:"scale,omitempty"`
AutoCreate bool `yaml:"auto_create,omitempty"`
AutoUpdate bool `yaml:"auto_update,omitempty"`
ForeignKey *ForeignKey `yaml:"foreign_key,omitempty"`
ManyToMany *ManyToMany `yaml:"many_to_many,omitempty"`
}
Field represents a database field/column definition
func (*Field) IsNullable ¶
IsNullable returns the nullable value, defaulting to true if not set
func (*Field) SetNullable ¶
SetNullable sets the nullable field
type ForeignKey ¶
type ForeignKey struct {
Table string `yaml:"table"`
OnDelete string `yaml:"on_delete"`
OnUpdate string `yaml:"on_update,omitempty"`
}
ForeignKey represents a foreign key relationship
type Index ¶
type Index struct {
Name string `yaml:"name"`
Fields []string `yaml:"fields"`
Unique bool `yaml:"unique,omitempty"`
// Method specifies the index access method (e.g. BTREE, HASH, GIN, GIST, BRIN for PostgreSQL).
// Leave empty to use the database default (usually BTREE).
// Not supported by SQLite or SQL Server — silently ignored on those providers.
Method string `yaml:"method,omitempty"`
// Where is a partial index predicate expression. Only rows satisfying this
// condition are included in the index. Leave empty for a full index.
// Not supported by MySQL — silently ignored on that provider.
Where string `yaml:"where,omitempty"`
// ForeignKey is an informational annotation (e.g. "auth_user.id") indicating
// which FK relationship this index supports. Generated by Builder tooling.
// It does not affect SQL generation.
ForeignKey string `yaml:"foreign_key,omitempty"`
// FromFK marks indexes auto-generated for foreign key columns. These are
// managed automatically by AddForeignKey/DropForeignKey and excluded from
// schema diffs and generated migration code.
FromFK bool `yaml:"from_fk,omitempty"`
}
Index represents a database index definition
type ManyToMany ¶
type ManyToMany struct {
Table string `yaml:"table"`
}
ManyToMany represents a many-to-many relationship
type Schema ¶
type Schema struct {
Database Database `yaml:"database"`
Include []Include `yaml:"include,omitempty"`
Defaults Defaults `yaml:"defaults"`
TypeMappings TypeMappings `yaml:"type_mappings"`
Tables []Table `yaml:"tables"`
}
Schema represents a YAML schema file structure
func (*Schema) GetTableByName ¶
GetTableByName finds a table by name in the schema
type Table ¶
type Table struct {
Name string `yaml:"name"`
Fields []Field `yaml:"fields"`
Indexes []Index `yaml:"indexes,omitempty"`
}
Table represents a database table definition
func (*Table) GetFieldByName ¶
GetFieldByName finds a field by name in the table
func (*Table) GetPrimaryKeyField ¶
GetPrimaryKeyField returns the primary key field if it exists
func (*Table) HasPrimaryKey ¶
HasPrimaryKey checks if the table has a primary key field
type TypeMappings ¶
type TypeMappings map[DatabaseType]map[string]string
TypeMappings represents custom SQL type overrides per database. Values are SQL type strings. For parameterised types use Go template syntax: "DECIMAL({{.Precision}},{{.Scale}})" or "VARCHAR({{.Length}})". It is a map from DatabaseType to a map of abstract type names to SQL type strings.
func (TypeMappings) ForProvider ¶
func (tm TypeMappings) ForProvider(dbType DatabaseType) map[string]string
ForProvider returns the type mapping overrides for the given database type, or nil.
func (TypeMappings) SetForProvider ¶
func (tm TypeMappings) SetForProvider(dbType DatabaseType, mappings map[string]string)
SetForProvider sets the type mappings for the given database type. The receiver must be a non-nil map (use make(TypeMappings) or TypeMappings{} first).
func (*TypeMappings) UnmarshalYAML ¶
func (tm *TypeMappings) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements custom YAML unmarshaling so that YAML keys (lowercase strings like "postgresql") are converted to DatabaseType keys.