Files
sm-user-plugin/updates/202610210001_add_users_email_verified_at.go
Jakub Zych add1f7a806 feat: users.email_verified_at records a proved address (mail activation, reset code)
- additive migration 202610210001_add_users_email_verified_at (ADD COLUMN IF NOT EXISTS, no backfill, no-op rollback)
- User.EmailVerifiedAt (json:"-", not fillable)
- VerifyActivationCode and ResetPassword stamp it in the write that activates or stores the password
2026-10-21 13:53:19 +02:00

34 lines
1.2 KiB
Go

package updates
import (
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)
// usersEmailVerifiedAtMigrations adds users.email_verified_at, the time the
// account's owner proved control of the address: a mailed activation code or
// a completed reset-code password reset (D-27). Social sign-in matching links
// a verified provider's identity onto an existing account only when it is set.
//
// The migration writes no rows: accounts that exist before it runs have no
// recorded proof (no backfill, D-26). A users table that already carries the
// column (a Laravel-derived schema) keeps it and its values, which mean the
// same thing. The rollback is a no-op for the same reason: the shared users
// column may predate this plugin.
var usersEmailVerifiedAtMigrations = []*gormigrate.Migration{
{
ID: "202610210001_add_users_email_verified_at",
Migrate: func(tx *gorm.DB) error {
return tx.Exec(`ALTER TABLE users ADD COLUMN IF NOT EXISTS email_verified_at TIMESTAMPTZ NULL`).Error
},
Rollback: func(*gorm.DB) error {
// No-op: the shared users column may predate the plugin.
return nil
},
},
}
func init() {
Register(usersEmailVerifiedAtMigrations...)
}