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
This commit is contained in:
Jakub Zych
2026-10-21 13:53:19 +02:00
parent c7635c56e3
commit add1f7a806
6 changed files with 59 additions and 3 deletions

View File

@@ -0,0 +1,33 @@
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...)
}

View File

@@ -51,6 +51,7 @@ func TestCreateOrganisationsMigration(t *testing.T) {
"202610040003_create_frontend_permissions",
"202610050001_create_oauth_identities",
"202610160002_add_handle_to_users",
"202610210001_add_users_email_verified_at",
}
if len(ids) != len(want) {
t.Fatalf("history = %v", ids)
@@ -61,9 +62,9 @@ func TestCreateOrganisationsMigration(t *testing.T) {
}
}
// Handle, OAuth identities, the three admin migrations, API tokens, user groups, jwt blacklist,
// Email proof, handle, OAuth identities, the three admin migrations, API tokens, user groups, jwt blacklist,
// throttle, extend-users, then organisations.
for range 11 {
for range 12 {
if err := m.RollbackLast(); err != nil {
t.Fatal(err)
}