package updates import ( "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" ) var userThrottleMigrations = []*gormigrate.Migration{ { ID: "202609220006_create_user_throttle", Migrate: func(tx *gorm.DB) error { return execStmts(tx, []string{ `CREATE TABLE user_throttle ( id SERIAL PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES users(id), ip_address TEXT, attempts INTEGER NOT NULL DEFAULT 0, is_suspended BOOLEAN NOT NULL DEFAULT FALSE, suspended_at TIMESTAMPTZ, is_banned BOOLEAN NOT NULL DEFAULT FALSE, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() )`, `CREATE INDEX user_throttle_user_ip ON user_throttle (user_id, ip_address)`, }) }, Rollback: func(tx *gorm.DB) error { return tx.Exec(`DROP TABLE IF EXISTS user_throttle`).Error }, }, } func init() { Register(userThrottleMigrations...) }