Documentation
¶
Index ¶
- func AutoMigrate(index string, dst ...interface{}) error
- func ClearIndexCache()
- func Connect() (*gorm.DB, error)
- func DB() *gorm.DB
- func EnsureColumns(model interface{}, fields ...string) error
- func EnsureTables(dst ...interface{}) error
- func GetIndexHeight(name string) (uint64, error)
- func LoadDBFromEnv() (*gorm.DB, error)
- func SetDB(gormDB *gorm.DB)
- func UpdateIndexHeight(name string, height uint64) error
- func UpdateIndexHeightByTx(tx *gorm.DB, name string, height uint64) error
- type BaseModel
- type IndexHeight
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoMigrate ¶ added in v1.4.0
AutoMigrate run auto migration for given models
func ClearIndexCache ¶ added in v1.18.0
func ClearIndexCache()
ClearIndexCache clears the in-memory index height cache, intended for testing only.
func EnsureColumns ¶ added in v1.19.0
EnsureColumns adds any of the named fields that the model declares but the live table lacks, without touching existing data.
This is the column-level counterpart to EnsureTables, and it exists for the same reason: AutoMigrate only drops and recreates at index height 0, and VERSION is informational — nothing in the runner reacts to a bump. So a column added to a model in a release simply never appears on a database that is already past height 0, and the plugin's next INSERT fails with `column "..." does not exist`, which the runner retries forever. The index then sits at a fixed height with no indication of why.
fields are Go struct field names (GORM resolves them to column names). Adding a column is safe to repeat and safe to run before the plugin writes: the column is created with the model's declared default.
func EnsureTables ¶ added in v1.18.2
func EnsureTables(dst ...interface{}) error
EnsureTables creates any of the given tables that don't already exist, without dropping any data. Intended for tables introduced after a plugin was first deployed: AutoMigrate's drop-then-recreate only runs at index height 0, so on upgrade new tables would otherwise never be created.
Safe to call alongside AutoMigrate: at height 0 the tables AutoMigrate just created exist already, so EnsureTables is a no-op; at height > 0 AutoMigrate is a no-op and EnsureTables creates only what's missing.
func GetIndexHeight ¶
func LoadDBFromEnv ¶ added in v1.4.0
func UpdateIndexHeight ¶
Types ¶
type IndexHeight ¶
type IndexHeight struct {
ID uint32 `gorm:"primary_key;auto_increment"`
Name string `gorm:"size:128;not null;unique"`
Height uint64 `sql:"type:bigint"`
}
func (*IndexHeight) ByName ¶
func (m *IndexHeight) ByName(name string) (*IndexHeight, error)