updated password reset requests. Fixes #452

This commit is contained in:
Cam 2024-01-18 11:14:32 -06:00
parent 53940d51ab
commit 2b3b6ed012
No known key found for this signature in database
GPG Key ID: 367B7C7EBD84A8BD
3 changed files with 25 additions and 1 deletions

View File

@ -17,7 +17,7 @@ type PasswordResetRequest struct {
}
func (str *Store) CreatePasswordResetRequest(prr *PasswordResetRequest, tx *sqlx.Tx) (int, error) {
stmt, err := tx.Prepare("insert into password_reset_requests (account_id, token) values ($1, $2) ON CONFLICT(account_id) DO UPDATE SET token=$2 returning id")
stmt, err := tx.Prepare("insert into password_reset_requests (account_id, token) values ($1, $2) returning id")
if err != nil {
return 0, errors.Wrap(err, "error preparing password_reset_requests insert statement")
}

View File

@ -0,0 +1,7 @@
-- +migrate Up
-- remove the old unique index (users might need multiple password resets)
ALTER TABLE password_reset_requests DROP CONSTRAINT password_reset_requests_account_id_key;
-- add new constraint which doesnt mind having multiple resets for account ids
ALTER TABLE password_reset_requests ADD CONSTRAINT password_reset_requests_account_id_key FOREIGN KEY (account_id) REFERENCES accounts (id) on delete cascade;

View File

@ -0,0 +1,17 @@
-- +migrate Up
alter table password_reset_requests rename to password_reset_requests_old;
CREATE TABLE password_reset_requests (
id integer primary key,
token string not null unique,
created_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now')),
updated_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now')),
account_id integer not null constraint fk_accounts_password_reset_requests references accounts on delete cascade,
deleted boolean not null default(false),
constraint chk_token check(token <> '')
);
insert into password_reset_requests select * from password_reset_requests_old;
drop table password_reset_requests_old;