diff --git a/init.sql b/init.sql index 67600e5..33c1cc8 100644 --- a/init.sql +++ b/init.sql @@ -2,9 +2,29 @@ CREATE TABLE IF NOT EXISTS users ( id SERIAL PRIMARY KEY, email VARCHAR(255) NOT NULL UNIQUE, hashed_password VARCHAR(255) NOT NULL, - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP + failed_attempts INTEGER NOT NULL DEFAULT 0, + is_locked BOOLEAN NOT NULL DEFAULT FALSE, + locked_at TIMESTAMP, + last_failed_at TIMESTAMP, + is_active BOOLEAN NOT NULL DEFAULT TRUE, + is_superuser BOOLEAN NOT NULL DEFAULT FALSE, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); +CREATE OR REPLACE FUNCTION update_updated_at_column() +RETURNS TRIGGER AS $$ +BEGIN + NEW.updated_at = NOW(); + RETURN NEW; +END; +$$ language 'plpgsql'; + +CREATE TRIGGER update_users_updated_at +BEFORE UPDATE ON users +FOR EACH ROW +EXECUTE FUNCTION update_updated_at_column(); + CREATE TABLE IF NOT EXISTS otps ( id SERIAL PRIMARY KEY, email VARCHAR(255) NOT NULL UNIQUE,