Documentation
¶
Index ¶
- func BackfillPublicIDs[T any](ctx context.Context, db *gorm.DB) error
- func CleanupOrphanedResources[T any, R any](ctx context.Context, db *gorm.DB, fkColumn string) error
- func CreateIndexIfNotExists[T any](ctx context.Context, db *gorm.DB, indexName string, columns ...string) error
- func DropIndex[T any](ctx context.Context, db *gorm.DB, indexName string) error
- func FoldCostAggregatesIntoBuckets[T any](ctx context.Context, db *gorm.DB) error
- func GetColumnName(db *gorm.DB, column string) string
- func MigrateAgentNetworkSettingsToDomain(ctx context.Context, db *gorm.DB) error
- func MigrateFieldFromGobToJSON[T any, S any](ctx context.Context, db *gorm.DB, fieldName string) error
- func MigrateJsonToTable[T any](ctx context.Context, db *gorm.DB, columnName string, ...) error
- func MigrateNetIPFieldFromBlobToJSON[T any](ctx context.Context, db *gorm.DB, fieldName string, indexName string) error
- func MigrateNewField[T any](ctx context.Context, db *gorm.DB, columnName string, defaultValue any) error
- func MigrateSetupKeyToHashedSetupKey[T any](ctx context.Context, db *gorm.DB) error
- func RemoveDuplicatePeerKeys(ctx context.Context, db *gorm.DB) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BackfillPublicIDs ¶ added in v0.75.0
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 FoldCostAggregatesIntoBuckets ¶ added in v0.75.1
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 MigrateAgentNetworkSettingsToDomain ¶ added in v0.77.0
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 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 MigrateSetupKeyToHashedSetupKey ¶ added in v0.31.0
Types ¶
This section is empty.