37 lines
819 B
MySQL
37 lines
819 B
MySQL
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||
|
|
||
|
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
||
|
RETURNS TRIGGER AS $$
|
||
|
BEGIN
|
||
|
NEW.updated_at = (extract(epoch from now()) * 1000);
|
||
|
RETURN NEW;
|
||
|
END;
|
||
|
$$ language 'plpgsql';
|
||
|
|
||
|
|
||
|
CREATE OR REPLACE FUNCTION update_state_changed_at_column()
|
||
|
RETURNS TRIGGER AS $$
|
||
|
BEGIN
|
||
|
IF OLD.state != NEW.state THEN
|
||
|
NEW.state_changed_at = (extract(epoch from now()) * 1000);
|
||
|
ELSE
|
||
|
NEW.state_changed_at = NEW.state_changed_at;
|
||
|
END IF;
|
||
|
RETURN NEW;
|
||
|
END;
|
||
|
$$ language 'plpgsql';
|
||
|
|
||
|
|
||
|
CREATE OR REPLACE FUNCTION update_active_changed_at_column()
|
||
|
RETURNS TRIGGER AS $$
|
||
|
BEGIN
|
||
|
IF OLD.active != NEW.active THEN
|
||
|
NEW.active_changed_at = (extract(epoch from now()) * 1000);
|
||
|
ELSE
|
||
|
NEW.active_changed_at = NEW.active_changed_at;
|
||
|
END IF;
|
||
|
RETURN NEW;
|
||
|
END;
|
||
|
$$ language 'plpgsql';
|
||
|
|