package database import ( entity "RenewCMS/internal/infrastructure/persistence/models" "gorm.io/gorm" ) const ( sourceRevisionColumn = "source_revision" untranslatedSourceValue = 0 ) func BackfillNullSourceRevisions(db *gorm.DB) error { migrator := db.Migrator() if !migrator.HasTable(&entity.Article{}) || !migrator.HasColumn(&entity.Article{}, sourceRevisionColumn) { return nil } return db.Unscoped().Model(&entity.Article{}).Where(sourceRevisionColumn+" IS NULL").UpdateColumn(sourceRevisionColumn, untranslatedSourceValue).Error }