migrate

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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

func SQLType(dialectName string, t reflect.Type, isPK bool) string

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.

type TypeOptions added in v0.3.0

type TypeOptions struct {
	Size      int
	Precision int
	Scale     int
	IsPK      bool
}

TypeOptions carry the SQL-type sizing hints parsed from a struct's db tag, e.g. db:"name,size=512" or db:"price,precision=18,scale=4". A zero value means "use the dialect default".

Jump to

Keyboard shortcuts

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