--up
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
  NEW.updated_at = NOW();
  RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON activity FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON composer_choices FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON composer_requests FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON conductor_requests FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON config_vals FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON device_tags FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON devices FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON embedded_strings FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON faq_answers FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON faq_questions FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON migrations FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON preset_tags FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON presets FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON projects FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON sample_packs FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON sample_tags FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON samples FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON service_quotas FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON shared_tracks_plays FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON signup_surveys FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON subscription_updates FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON track_preset_tags FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON track_presets FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON tracks_for_sharing FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON user_identities FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON users FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON voice_conversion_model_training_runs FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON voice_conversion_models FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();

CREATE TRIGGER set_timestamp
BEFORE UPDATE ON waiting_list_signups FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();
   
--down
DROP TRIGGER set_timestamp ON activity;
DROP TRIGGER set_timestamp ON composer_choices;
DROP TRIGGER set_timestamp ON composer_requests;
DROP TRIGGER set_timestamp ON conductor_requests;
DROP TRIGGER set_timestamp ON config_vals;
DROP TRIGGER set_timestamp ON device_tags;
DROP TRIGGER set_timestamp ON devices;
DROP TRIGGER set_timestamp ON embedded_strings;
DROP TRIGGER set_timestamp ON faq_answers;
DROP TRIGGER set_timestamp ON faq_questions;
DROP TRIGGER set_timestamp ON migrations;
DROP TRIGGER set_timestamp ON preset_tags;
DROP TRIGGER set_timestamp ON presets;
DROP TRIGGER set_timestamp ON projects;
DROP TRIGGER set_timestamp ON sample_packs;
DROP TRIGGER set_timestamp ON sample_tags;
DROP TRIGGER set_timestamp ON samples;
DROP TRIGGER set_timestamp ON service_quotas;
DROP TRIGGER set_timestamp ON shared_tracks_plays;
DROP TRIGGER set_timestamp ON signup_surveys;
DROP TRIGGER set_timestamp ON subscription_updates;
DROP TRIGGER set_timestamp ON track_preset_tags;
DROP TRIGGER set_timestamp ON track_presets;
DROP TRIGGER set_timestamp ON tracks_for_sharing;
DROP TRIGGER set_timestamp ON user_identities;
DROP TRIGGER set_timestamp ON users;
DROP TRIGGER set_timestamp ON voice_conversion_model_training_runs;
DROP TRIGGER set_timestamp ON voice_conversion_models;
DROP TRIGGER set_timestamp ON waiting_list_signups;

DROP FUNCTION update_updated_at_column();
