diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2023-05-17 21:28:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-17 21:28:37 +0100 |
| commit | ca263834e93814105ca9ea77ab213cff0bc95faa (patch) | |
| tree | fc1b1a63a890899c4b002cb11001c5b42ce824d6 /atuin-server | |
| parent | validate usernames on registration (#982) (diff) | |
| download | atuin-ca263834e93814105ca9ea77ab213cff0bc95faa.zip | |
Restructure account commands to account subcommand (#984)
* Stop running triggers on history delete
* Move to account management dir
* Alter trigger function to only run for inserts
* wip
* Add atuin account subcommands, and re-org delete
* Clarify docs
* Delete silly dupe migration
* Um where did this come from
* Oops, insert only plz
Diffstat (limited to 'atuin-server')
| -rw-r--r-- | atuin-server/migrations/20230515221038_trigger-delete-only.sql | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/atuin-server/migrations/20230515221038_trigger-delete-only.sql b/atuin-server/migrations/20230515221038_trigger-delete-only.sql new file mode 100644 index 00000000..3d0bba52 --- /dev/null +++ b/atuin-server/migrations/20230515221038_trigger-delete-only.sql @@ -0,0 +1,30 @@ +-- We do not need to run the trigger on deletes, as the only time we are deleting history is when the user +-- has already been deleted +-- This actually slows down deleting all the history a good bit! + +create or replace function user_history_count() +returns trigger as +$func$ +begin + if (TG_OP='INSERT') then + update total_history_count_user set total = total + 1 where user_id = new.user_id; + + if not found then + insert into total_history_count_user(user_id, total) + values ( + new.user_id, + (select count(1) from history where user_id = new.user_id) + ); + end if; + end if; + + return NEW; -- this is actually ignored for an after trigger, but oh well +end; +$func$ +language plpgsql volatile -- pldfplplpflh +cost 100; -- default value + +create or replace trigger tg_user_history_count + after insert on history + for each row + execute procedure user_history_count(); |
