19 lines
693 B
PL/PgSQL
19 lines
693 B
PL/PgSQL
-- Add updated_at column if it doesn't exist
|
|
ALTER TABLE icon_experts ADD COLUMN IF NOT EXISTS updated_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now());
|
|
|
|
-- Function to handle updating the updated_at timestamp
|
|
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
|
RETURNS TRIGGER AS $$
|
|
BEGIN
|
|
NEW.updated_at = timezone('utc'::text, now());
|
|
RETURN NEW;
|
|
END;
|
|
$$ language 'plpgsql';
|
|
|
|
-- Trigger to execute the function before each update
|
|
DROP TRIGGER IF EXISTS update_icon_experts_updated_at ON icon_experts;
|
|
CREATE TRIGGER update_icon_experts_updated_at
|
|
BEFORE UPDATE ON icon_experts
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION update_updated_at_column();
|