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.
8 -- Sets up a trigger for the given table to automatically set a column called
9 -- `updated_at` whenever the row is modified (unless `updated_at` was included
10 -- in the modified columns)
15 -- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
17 -- SELECT diesel_manage_updated_at('users');
19 CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
21 EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
22 FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
26 CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
29 NEW IS DISTINCT FROM OLD AND
30 NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
32 NEW.updated_at := current_timestamp;