migration

package
v0.76.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: BSD-3-Clause, AGPL-3.0 Imports: 15 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackfillPublicIDs added in v0.75.0

func BackfillPublicIDs[T any](ctx context.Context, db *gorm.DB) error

func CleanupOrphanedResources added in v0.68.2

func CleanupOrphanedResources[T any, R any](ctx context.Context, db *gorm.DB, fkColumn string) error

CleanupOrphanedResources deletes rows from the table of model T where the foreign key column (fkColumn) references a row in the table of model R that no longer exists.

func CreateIndexIfNotExists added in v0.50.0

func CreateIndexIfNotExists[T any](ctx context.Context, db *gorm.DB, indexName string, columns ...string) error

func DropIndex added in v0.43.2

func DropIndex[T any](ctx context.Context, db *gorm.DB, indexName string) error

func FoldCostAggregatesIntoBuckets added in v0.75.1

func FoldCostAggregatesIntoBuckets[T any](ctx context.Context, db *gorm.DB) error

FoldCostAggregatesIntoBuckets migrates a per-request cost table from the old "stored aggregate" shape (cost_usd + cache_cost_usd columns) to the per-bucket breakdown, where the total and cache portion are derived on read instead.

The fold preserves both aggregates exactly for historical rows: the cache total moves into cached_input_cost_usd and the remainder into input_cost_usd, so a row's derived total and cache cost still match what it reported before the upgrade. The finer split is genuinely unknown for those rows — the old schema never recorded a read/write or input/output division — so it is lumped rather than guessed; only rows written after the upgrade carry a true four-way split.

Dropping the columns before folding would zero every historical row's cost, so the update runs first and the drop only happens once it succeeds. A table with no cost_usd column has already been migrated (or was created fresh) and is skipped.

func GetColumnName added in v0.36.0

func GetColumnName(db *gorm.DB, column string) string

func MigrateFieldFromGobToJSON

func MigrateFieldFromGobToJSON[T any, S any](ctx context.Context, db *gorm.DB, fieldName string) error

MigrateFieldFromGobToJSON migrates a column from Gob encoding to JSON encoding. T is the type of the model that contains the field to be migrated. S is the type of the field to be migrated.

func MigrateJsonToTable added in v0.53.0

func MigrateJsonToTable[T any](ctx context.Context, db *gorm.DB, columnName string, mapperFunc func(accountID string, id string, value string) any) error

func MigrateNetIPFieldFromBlobToJSON added in v0.27.5

func MigrateNetIPFieldFromBlobToJSON[T any](ctx context.Context, db *gorm.DB, fieldName string, indexName string) error

MigrateNetIPFieldFromBlobToJSON migrates a Net IP column from Blob encoding to JSON encoding. T is the type of the model that contains the field to be migrated.

func MigrateNewField added in v0.36.0

func MigrateNewField[T any](ctx context.Context, db *gorm.DB, columnName string, defaultValue any) error

func MigrateSetupKeyToHashedSetupKey added in v0.31.0

func MigrateSetupKeyToHashedSetupKey[T any](ctx context.Context, db *gorm.DB) error

func RemoveDuplicatePeerKeys added in v0.62.2

func RemoveDuplicatePeerKeys(ctx context.Context, db *gorm.DB) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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