Documentation
¶
Overview ¶
Package migrate provides internal utilities for database schema migrations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterTypeMapper ¶ added in v0.3.0
func RegisterTypeMapper(t reflect.Type, m TypeMapper)
RegisterTypeMapper registers a custom Go-type → SQL-type mapping. The public API in package quark forwards to this; the registry lives here because internal/migrate.SQLType is the only consumer and we want the lookup to stay close to the lookup site.
Pointer types are stripped before registration: registering for time.Duration also covers *time.Duration. Re-registering the same type overwrites the previous mapper.
func SQLType ¶
SQLType maps Go types to SQL types for the given dialect name.
When isPK is true the column DDL includes the PRIMARY KEY constraint. The exact type depends on the Go field kind:
- int / int64 → dialect-native auto-increment (SERIAL, AUTO_INCREMENT, IDENTITY…)
- string → VARCHAR(36) PRIMARY KEY — UUID-friendly; no auto-increment
- anything else → its natural SQL type + PRIMARY KEY (no auto-increment)
func SQLTypeWithOpts ¶ added in v0.3.0
func SQLTypeWithOpts(dialectName string, t reflect.Type, opts TypeOptions) string
SQLTypeWithOpts is the extended form of SQLType that propagates the field's sizing hints to the type mapper. It is the preferred entry point for the migrate / sync layers; SQLType remains as a convenience wrapper for callers that don't (yet) have TypeOptions.
Types ¶
type TypeMapper ¶ added in v0.3.0
type TypeMapper func(dialect string, opts TypeOptions) string
TypeMapper produces a dialect-specific SQL type for a Go type. The caller supplies the dialect name (lower-case: "postgres", "mysql", ...) and the sizing hints from the field's tag. Implementations should fall back to sensible defaults if Size/Precision/Scale are zero.
func LookupTypeMapper ¶ added in v0.3.0
func LookupTypeMapper(t reflect.Type) TypeMapper
LookupTypeMapper returns the registered mapper for t (pointer stripped). Returns nil if no mapping is registered.