Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 1m40s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 42m16s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
package model
|
|
|
|
import "gorm.io/gorm"
|
|
|
|
const astraAutoSwitchMigrationKey = "migration.token_astra_auto_switch.v1"
|
|
|
|
// MigrateTokenAstraAutoSwitch preserves the pre-token-policy behavior for
|
|
// tokens that existed before the user-level switch was introduced. It is
|
|
// guarded by an Option marker so newly-created tokens (which default to false)
|
|
// are never promoted on a later restart.
|
|
func MigrateTokenAstraAutoSwitch() error {
|
|
return DB.Transaction(func(tx *gorm.DB) error {
|
|
var marker Option
|
|
if err := tx.Where(&Option{Key: astraAutoSwitchMigrationKey}).First(&marker).Error; err == nil {
|
|
return nil
|
|
} else if err != gorm.ErrRecordNotFound {
|
|
return err
|
|
}
|
|
if err := tx.Model(&Token{}).Where("deleted_at IS NULL").Update("astra_auto_switch", true).Error; err != nil {
|
|
return err
|
|
}
|
|
return tx.Create(&Option{Key: astraAutoSwitchMigrationKey, Value: "true"}).Error
|
|
})
|
|
}
|
|
|
|
// MigrateTokenAstraDetection preserves observation for existing tokens without
|
|
// resetting an explicit opt-out on subsequent starts.
|
|
func MigrateTokenAstraDetection() error {
|
|
return DB.Transaction(func(tx *gorm.DB) error {
|
|
const key = "migration.token_astra_detection.v1"
|
|
var marker Option
|
|
if err := tx.Where(&Option{Key: key}).First(&marker).Error; err == nil {
|
|
return nil
|
|
} else if err != gorm.ErrRecordNotFound {
|
|
return err
|
|
}
|
|
if err := tx.Model(&Token{}).Where("deleted_at IS NULL").Update("astra_detection_enabled", true).Error; err != nil {
|
|
return err
|
|
}
|
|
return tx.Create(&Option{Key: key, Value: "true"}).Error
|
|
})
|
|
}
|