mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 02:41:35 +01:00
Fix triggers for last modified columns and changelog table
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
shellHook = ''
|
||||
alias dbmate="${pkgs.dbmate}/bin/dbmate --no-dump-schema --url postgres://postgres@localhost:15432/archtika?sslmode=disable"
|
||||
alias formatsql="${pkgs.pgformatter}/bin/pg_format -s 2 -f 2 -U 2 -i db/migrations/*.sql"
|
||||
alias dbconnect="${pkgs.postgresql_16}/bin/psql postgres://postgres@localhost:15432/archtika"
|
||||
'';
|
||||
};
|
||||
web = pkgs.mkShell {
|
||||
|
||||
@@ -9,10 +9,10 @@ BEGIN
|
||||
UPDATE
|
||||
internal.website
|
||||
SET
|
||||
last_modified_at = NEW.last_modified_at,
|
||||
last_modified_by = NEW.last_modified_by
|
||||
last_modified_at = CLOCK_TIMESTAMP(),
|
||||
last_modified_by = (CURRENT_SETTING('request.jwt.claims', TRUE)::JSON ->> 'user_id')::UUID
|
||||
WHERE
|
||||
id = NEW.website_id;
|
||||
id = COALESCE(NEW.website_id, OLD.website_id);
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
@@ -55,12 +55,12 @@ CREATE TRIGGER update_footer_last_modified
|
||||
EXECUTE FUNCTION internal.update_last_modified ();
|
||||
|
||||
CREATE TRIGGER update_legal_information_last_modified
|
||||
BEFORE INSERT OR UPDATE OR DELETE ON internal.legal_information
|
||||
BEFORE INSERT OR DELETE ON internal.legal_information
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION internal.update_last_modified ();
|
||||
|
||||
CREATE TRIGGER update_collab_last_modified
|
||||
BEFORE UPDATE ON internal.collab
|
||||
BEFORE INSERT OR UPDATE OR DELETE ON internal.collab
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION internal.update_last_modified ();
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ BEGIN
|
||||
IF TG_TABLE_NAME = 'website' THEN
|
||||
_website_id := NEW.id;
|
||||
ELSE
|
||||
_website_id := NEW.website_id;
|
||||
_website_id := COALESCE(NEW.website_id, OLD.website_id);
|
||||
END IF;
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
INSERT INTO internal.change_log (website_id, table_name, operation, new_value)
|
||||
@@ -42,7 +42,7 @@ LANGUAGE plpgsql
|
||||
SECURITY DEFINER;
|
||||
|
||||
CREATE TRIGGER website_track_changes
|
||||
AFTER INSERT OR UPDATE OR DELETE ON internal.website
|
||||
AFTER UPDATE ON internal.website
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION internal.track_changes ();
|
||||
|
||||
@@ -77,7 +77,7 @@ CREATE TRIGGER footer_track_changes
|
||||
EXECUTE FUNCTION internal.track_changes ();
|
||||
|
||||
CREATE TRIGGER legal_information_track_changes
|
||||
AFTER UPDATE ON internal.legal_information
|
||||
AFTER INSERT OR UPDATE OR DELETE ON internal.legal_information
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION internal.track_changes ();
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
<input
|
||||
type="date"
|
||||
name="publication-date"
|
||||
value={data.article.publication_date}
|
||||
value={data.article.publication_date ?? new Date().toISOString().split('T')[0]}
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
|
||||
Reference in New Issue
Block a user