add db migrations
This commit is contained in:
parent
568d8fd117
commit
a019e55c74
4 changed files with 27 additions and 4 deletions
|
@ -27,7 +27,7 @@ func CleanupLogins() {
|
|||
log.Printf("[CleanupLogins] Error deleting login transactions: %v\n", err)
|
||||
}
|
||||
|
||||
_, err = models.DB.NewDelete().Table("multifactor").Where("expiresat < NOW()").Where("active = false").Exec(context.Background())
|
||||
_, err = models.DB.NewDelete().Table("multifactor").Where("expires_at < NOW()").Where("active = false").Exec(context.Background())
|
||||
if err != nil {
|
||||
log.Printf("[CleanupLogins] Error deleting login transactions: %v\n", err)
|
||||
}
|
||||
|
|
23
migrations/20240506000001_mfa_rename_tables.go
Normal file
23
migrations/20240506000001_mfa_rename_tables.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
|
||||
db.ExecContext(context.Background(), `ALTER TABLE multifactor RENAME COLUMN expiresat TO expires_at`)
|
||||
db.ExecContext(context.Background(), `ALTER TABLE multifactor RENAME COLUMN totpurl TO totp_secret`)
|
||||
db.ExecContext(context.Background(), `ALTER TABLE users RENAME COLUMN lastlogin TO last_login`)
|
||||
db.ExecContext(context.Background(), `ALTER TABLE multifactor_scratchcodes RENAME COLUMN isused TO is_used`)
|
||||
return nil
|
||||
}, func(ctx context.Context, db *bun.DB) error {
|
||||
db.ExecContext(context.Background(), `ALTER TABLE multifactor RENAME COLUMN expires_at TO expiresat`)
|
||||
db.ExecContext(context.Background(), `ALTER TABLE multifactor RENAME COLUMN totp_secret TO totpurl`)
|
||||
db.ExecContext(context.Background(), `ALTER TABLE users RENAME COLUMN last_login TO lastlogin`)
|
||||
db.ExecContext(context.Background(), `ALTER TABLE multifactor_scratchcodes RENAME COLUMN is_used TO isused`)
|
||||
return nil
|
||||
})
|
||||
}
|
|
@ -25,8 +25,8 @@ type MFAConfig struct {
|
|||
bun.BaseModel `bun:"table:multifactor"`
|
||||
ID int64 `bun:"id,pk,autoincrement"`
|
||||
UserName string `bun:"username,notnull"`
|
||||
TOTPSecret string `bun:"totpurl,notnull"`
|
||||
ExpiresAt time.Time `bun:"expiresat,notnull"`
|
||||
TOTPSecret string `bun:"totp_secret,notnull"`
|
||||
ExpiresAt time.Time `bun:"expires_at,notnull"`
|
||||
Active bool `bun:"active,notnull"`
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ type User struct {
|
|||
bun.BaseModel `bun:"table:users"`
|
||||
UserName string `bun:"username,pk" json:"username"`
|
||||
Created time.Time `bun:"created,notnull,default:now()" json:"created"`
|
||||
LastLogin time.Time `bun:"lastlogin" json:"last_login"`
|
||||
LastLogin time.Time `bun:"last_login" json:"last_login"`
|
||||
PasswordSalt string `bun:"salt" json:"password_salt"`
|
||||
PasswordHash string `bun:"password" json:"password_hash"`
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue