50 lines
1.0 KiB
MySQL
50 lines
1.0 KiB
MySQL
|
|
||
|
|
||
|
-- now we set up the triggers
|
||
|
|
||
|
-- streams created_at
|
||
|
ALTER TABLE api.streams
|
||
|
ALTER created_at SET DEFAULT now();
|
||
|
|
||
|
DROP TRIGGER stream_created_at ON api.streams;
|
||
|
|
||
|
CREATE TRIGGER stream_created_at
|
||
|
BEFORE INSERT ON api.streams
|
||
|
FOR EACH ROW
|
||
|
EXECUTE PROCEDURE moddatetime (created_at);
|
||
|
|
||
|
|
||
|
-- streams updated_at
|
||
|
ALTER TABLE api.streams
|
||
|
ALTER updated_at SET DEFAULT now();
|
||
|
|
||
|
CREATE TRIGGER stream_updated_at
|
||
|
BEFORE UPDATE ON api.streams
|
||
|
FOR EACH ROW
|
||
|
EXECUTE PROCEDURE moddatetime (updated_at);
|
||
|
|
||
|
|
||
|
-- segments created_at
|
||
|
ALTER TABLE api.segments
|
||
|
ALTER created_at SET DEFAULT now();
|
||
|
|
||
|
DROP TRIGGER segment_created_at ON api.segments;
|
||
|
|
||
|
CREATE TRIGGER segment_created_at
|
||
|
BEFORE INSERT ON api.segments
|
||
|
FOR EACH ROW
|
||
|
EXECUTE PROCEDURE moddatetime(created_at);
|
||
|
|
||
|
|
||
|
-- segments updated_at
|
||
|
ALTER TABLE api.segments
|
||
|
ALTER updated_at SET DEFAULT now();
|
||
|
|
||
|
DROP TRIGGER segment_updated_at ON api.segments;
|
||
|
|
||
|
CREATE TRIGGER segment_updated_at
|
||
|
BEFORE UPDATE ON api.segments
|
||
|
FOR EACH ROW
|
||
|
EXECUTE PROCEDURE moddatetime(updated_at);
|
||
|
|