mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-23 10:51:09 +00:00
sys_migration already carries app_code; sys_menu and sys_api did not, so nothing said which application seeded a row - which is what an uninstall or an audit would have to ask. The migration adds the columns through the runtime models rather than cmd/migrate/migration/models, whose frozen ModelTime is wrong for anything ordered after the soft-delete conversion. Claude-Session: https://claude.ai/code/session_01HPTAw8b8tAdFNFn8rKdPYx
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package version
|
|
|
|
import (
|
|
"runtime"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
adminmodels "go-admin/app/admin/models"
|
|
"go-admin/cmd/migrate/migration"
|
|
common "go-admin/common/models"
|
|
)
|
|
|
|
// Add sys_menu.app_code and sys_api.app_code ahead of PRD 006 F9's Seeder.
|
|
//
|
|
// Every row a third-party application's migration writes through
|
|
// seed.SeedMenus must be attributable to the app that wrote it, so
|
|
// installing, auditing, or removing one application does not require
|
|
// guessing which rows belong to it - see go-admin-core's docs/contract.md,
|
|
// "Application-supplied menu and API entries", for the requirement this
|
|
// satisfies.
|
|
//
|
|
// Ordered after 1786700003000, so importing cmd/migrate/migration/models is
|
|
// banned here (see schema_coverage_test.go's
|
|
// TestPostConversionMigrationsAvoidFrozenSeedModels): AddColumn instead
|
|
// reads the runtime models' own gorm tags directly, which is also what
|
|
// makes the column this adds match the one the admin Seeder writes through
|
|
// those same structs.
|
|
func init() {
|
|
_, fileName, _, _ := runtime.Caller(0)
|
|
migration.Migrate.SetVersion(migration.GetFilename(fileName), _1786700006000AppCodeColumns)
|
|
}
|
|
|
|
func _1786700006000AppCodeColumns(db *gorm.DB, version string) error {
|
|
m := db.Migrator()
|
|
if !m.HasColumn(&adminmodels.SysMenu{}, "AppCode") {
|
|
if err := m.AddColumn(&adminmodels.SysMenu{}, "AppCode"); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if !m.HasColumn(&adminmodels.SysApi{}, "AppCode") {
|
|
if err := m.AddColumn(&adminmodels.SysApi{}, "AppCode"); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return db.Create(&common.Migration{Version: version}).Error
|
|
}
|