-- 1. Enable necessary extensions CREATE EXTENSION IF NOT EXISTS "pgcrypto"; CREATE EXTENSION IF NOT EXISTS "citext"; -- 2. Define the Users table CREATE TABLE "public"."Users" ( "id" UUID PRIMARY KEY DEFAULT gen_random_uuid(), "username" CITEXT UNIQUE NOT NULL, "email" CITEXT UNIQUE NOT NULL, "hashed_password" TEXT NOT NULL, "created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(), "updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW() ); -- 3. Create the function to update the timestamp CREATE OR REPLACE FUNCTION update_updated_at_column() RETURNS TRIGGER AS $$ BEGIN NEW.updated_at = NOW(); RETURN NEW; END; $$ language 'plpgsql'; -- 4. Create the trigger and attach it to the Users table CREATE TRIGGER update_users_updated_at BEFORE UPDATE ON "public"."Users" FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();