-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
created_at
/ updated_at
on relevant objects
Part of #29 as well as the ongoing room templates work
- Loading branch information
Showing
4 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
migrations/2024-11-27-092030_add_created_updated_at/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- This file should undo anything in `up.sql` | ||
|
||
ALTER TABLE rooms DROP COLUMN created_at; | ||
ALTER TABLE yamls DROP COLUMN created_at; | ||
ALTER TABLE room_templates DROP COLUMN created_at; | ||
|
||
ALTER TABLE rooms DROP COLUMN updated_at; | ||
ALTER TABLE yamls DROP COLUMN updated_at; | ||
ALTER TABLE room_templates DROP COLUMN updated_at; | ||
|
||
DROP TRIGGER set_updated_at ON rooms; | ||
DROP TRIGGER set_updated_at ON yamls; | ||
DROP TRIGGER set_updated_at ON room_templates; | ||
|
||
DROP FUNCTION set_updated_at; | ||
|
25 changes: 25 additions & 0 deletions
25
migrations/2024-11-27-092030_add_created_updated_at/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- Your SQL goes here | ||
|
||
ALTER TABLE rooms ADD COLUMN created_at TIMESTAMP NOT NULL DEFAULT NOW(); | ||
ALTER TABLE yamls ADD COLUMN created_at TIMESTAMP NOT NULL DEFAULT NOW(); | ||
ALTER TABLE room_templates ADD COLUMN created_at TIMESTAMP NOT NULL DEFAULT NOW(); | ||
|
||
ALTER TABLE rooms ADD COLUMN updated_at TIMESTAMP NOT NULL DEFAULT NOW(); | ||
ALTER TABLE yamls ADD COLUMN updated_at TIMESTAMP NOT NULL DEFAULT NOW(); | ||
ALTER TABLE room_templates ADD COLUMN updated_at TIMESTAMP NOT NULL DEFAULT NOW(); | ||
|
||
CREATE OR REPLACE FUNCTION set_updated_at() RETURNS trigger AS $$ | ||
BEGIN | ||
IF ( | ||
NEW IS DISTINCT FROM OLD AND | ||
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at | ||
) THEN | ||
NEW.updated_at := current_timestamp; | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
CREATE TRIGGER set_updated_at BEFORE UPDATE ON rooms FOR EACH ROW EXECUTE PROCEDURE set_updated_at(); | ||
CREATE TRIGGER set_updated_at BEFORE UPDATE ON yamls FOR EACH ROW EXECUTE PROCEDURE set_updated_at(); | ||
CREATE TRIGGER set_updated_at BEFORE UPDATE ON room_templates FOR EACH ROW EXECUTE PROCEDURE set_updated_at(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters