diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-10-31 22:06:00 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-10-31 22:06:00 +0300 |
| commit | 4210c9b38f9053f6720a6bebaadefd24c542eaa9 (patch) | |
| tree | 5b0061e23cf91291ed9e5f387766148d45103591 /backend/database/functions.sql | |
| parent | chore: change repo name to lphub (diff) | |
| download | lphub-4210c9b38f9053f6720a6bebaadefd24c542eaa9.tar.gz lphub-4210c9b38f9053f6720a6bebaadefd24c542eaa9.tar.bz2 lphub-4210c9b38f9053f6720a6bebaadefd24c542eaa9.zip | |
backend: better auth check, audit logging
Diffstat (limited to 'backend/database/functions.sql')
| -rw-r--r-- | backend/database/functions.sql | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/backend/database/functions.sql b/backend/database/functions.sql index ca33a60..6a6f6d2 100644 --- a/backend/database/functions.sql +++ b/backend/database/functions.sql | |||
| @@ -1,3 +1,17 @@ | |||
| 1 | CREATE OR REPLACE FUNCTION log_audit() RETURNS TRIGGER AS $$ | ||
| 2 | BEGIN | ||
| 3 | INSERT INTO audit (table_name, operation_type, old_data, new_data, changed_by) | ||
| 4 | VALUES ( | ||
| 5 | TG_TABLE_NAME, | ||
| 6 | TG_OP, | ||
| 7 | CASE WHEN TG_OP = 'DELETE' OR TG_OP = 'UPDATE' THEN row_to_json(OLD) ELSE NULL END, | ||
| 8 | CASE WHEN TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN row_to_json(NEW) ELSE NULL END, | ||
| 9 | current_setting('app.user_id')::TEXT | ||
| 10 | ); | ||
| 11 | RETURN NULL; | ||
| 12 | END; | ||
| 13 | $$ LANGUAGE plpgsql; | ||
| 14 | |||
| 1 | CREATE OR REPLACE FUNCTION get_rankings_singleplayer() | 15 | CREATE OR REPLACE FUNCTION get_rankings_singleplayer() |
| 2 | RETURNS TABLE ( | 16 | RETURNS TABLE ( |
| 3 | steam_id TEXT, | 17 | steam_id TEXT, |