Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd helpers for dealing with timestamps #91
Comments
sgrif
added
enhancement
accepted
labels
Jan 13, 2016
This comment has been minimized.
|
Unsure if this is too much, but I think I'd also like to have something like |
This comment has been minimized.
|
Did you want to set |
This comment has been minimized.
|
We can handle that via |
This comment has been minimized.
|
Alright, and you wanted a procedure like this? CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
BEGIN
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE INSERT OR UPDATE ON %s FOR EACH ROW EXECUTE PROCEDURE set_updated_at()', _tbl);
END;
$$ LANGUAGE plpgsql; |
This comment has been minimized.
|
I guess it should just be |
This comment has been minimized.
|
Oh yeah, had that one written prior to your response haha. Apologies if this is obvious, but where do you imagine these helpers existing? Should the |
This comment has been minimized.
|
There's currently no Rust DSL, though we may add one in the future as use cases arise. I'm fine with creating this as part of the migrations code, as long as it has a sufficiently specific name. The actual code for creating these should probably live on the |
This comment has been minimized.
|
I've been looking into what exactly would it take to implement this, constrained by the SQL format of migrations. If they wanted to, a user could write valid SQL with alternating capitals and one word per line, and it'd be accepted by Pg. So implementing a check for the phrase I also thought about a pseudo-DSL using SQL comments, but a good design of that basically means implementing the foundation of a DSL entirely. |
This comment has been minimized.
|
We shouldn't do any sort of magic around this, the user should set the trigger themselves. We just need to provide the function for them. |
sgrif commentedJan 13, 2016
created_atdoesn't need anything from us, we can just haveDEFAULT current_timestamp.updated_atrequires a trigger, but we shouldn't require our users to write that. We can use the same procedure for pretty much every table:We should provide that so users don't have to write it repeatedly