migration

package
v0.77.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 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 MigrateAgentNetworkSettingsToDomain added in v0.77.0

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

MigrateAgentNetworkSettingsToDomain reshapes agent_network_settings from the legacy (cluster, subdomain) identity columns to (domain, proxy_address): domain becomes `<subdomain>.<cluster>` — the endpoint hostname the old columns derived — and proxy_address becomes the cluster address, preserving which proxy serves the account. Runs before AutoMigrate, which then creates the unique index on the freshly backfilled domain column.

A legacy row missing either half cannot be given an endpoint; the old bootstrap always wrote both, so such a row indicates corruption and the migration fails loudly rather than leaving an empty domain to collide with the unique index confusingly.

The transaction is real only on sqlite and postgres, where DDL is transactional. MySQL implicitly commits around every ALTER TABLE, so there each step stands alone; what makes an interrupted run resumable on MySQL is that every step is guarded by the schema state it changes — the entry check fires while either legacy column remains, the adds skip existing columns, the backfill and its loud-failure check run only while the legacy cluster column exists (they provably completed before any drop), and each drop skips what is already gone.

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