1 -- This file was automatically created by Diesel to setup helper functions
2 -- and other internal bookkeeping. This file is safe to edit, any future
3 -- changes will be added to existing projects as new migrations.
4 -- Sets up a trigger for the given table to automatically set a column called
5 -- `updated_at` whenever the row is modified (unless `updated_at` was included
6 -- in the modified columns)
11 -- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
13 -- SELECT diesel_manage_updated_at('users');
15 CREATE OR REPLACE FUNCTION diesel_manage_updated_at (_tbl regclass)
19 EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
20 FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
25 CREATE OR REPLACE FUNCTION diesel_set_updated_at ()
29 IF (NEW IS DISTINCT FROM OLD AND NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at) THEN
30 NEW.updated_at := CURRENT_TIMESTAMP;