Skip to content

Commit 006e6cc

Browse files
Completely changed transactions schema as per new designs
1 parent c04459b commit 006e6cc

File tree

1 file changed

+63
-17
lines changed

1 file changed

+63
-17
lines changed

db/queries/transactions.sql

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,86 @@
1-
-- name: StoreTransactionPQ :one
1+
-- name: CreateTransactionPQ :one
22
INSERT INTO transactions_archive (
3-
id, session_id, action, resource, permissions, status, error, output, created_at
3+
id,
4+
session_id,
5+
timestamp,
6+
operation,
7+
target_path,
8+
entries,
9+
status,
10+
error_msg,
11+
output,
12+
executed_by,
13+
duration_ms
414
) VALUES (
5-
$1, $2, $3, $4, $5, $6, $7, $8, $9
15+
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11
616
) RETURNING *;
717

818
-- name: GetTransactionPQ :one
9-
SELECT * FROM transactions_archive
19+
SELECT * FROM transactions_archive
1020
WHERE id = $1;
1121

1222
-- name: GetTransactionsBySessionPQ :many
13-
SELECT * FROM transactions_archive
23+
SELECT * FROM transactions_archive
1424
WHERE session_id = $1
15-
ORDER BY created_at DESC;
25+
ORDER BY timestamp DESC;
1626

1727
-- name: GetSuccessfulTransactionsPQ :many
18-
SELECT * FROM transactions_archive
28+
SELECT * FROM transactions_archive
1929
WHERE session_id = $1 AND status = 'success'
20-
ORDER BY created_at DESC;
30+
ORDER BY timestamp DESC;
2131

2232
-- name: GetFailedTransactionsPQ :many
23-
select * from transactions_archive
24-
where session_id = $1 and status = 'failure'
25-
order by created_at desc;
33+
SELECT * FROM transactions_archive
34+
WHERE session_id = $1 AND status = 'failed'
35+
ORDER BY timestamp DESC;
2636

2737
-- name: GetPendingTransactionsPQ :many
28-
select * from transactions_archive
29-
where session_id = $1 and status = 'pending'
30-
order by created_at desc;
38+
SELECT * FROM transactions_archive
39+
WHERE session_id = $1 AND status = 'pending'
40+
ORDER BY timestamp DESC;
41+
42+
-- name: GetTransactionsByOperationPQ :many
43+
SELECT * FROM transactions_archive
44+
WHERE session_id = $1 AND operation = $2
45+
ORDER BY timestamp DESC;
46+
47+
-- name: GetTransactionsByPathPQ :many
48+
SELECT * FROM transactions_archive
49+
WHERE session_id = $1 AND target_path = $2
50+
ORDER BY timestamp DESC;
51+
52+
-- name: UpdateTransactionStatusPQ :one
53+
UPDATE transactions_archive
54+
SET
55+
status = $2,
56+
error_msg = $3,
57+
output = $4,
58+
duration_ms = $5
59+
WHERE id = $1
60+
RETURNING *;
3161

3262
-- name: DeleteTransactionPQ :exec
33-
DELETE FROM transactions_archive WHERE id = $1;
63+
DELETE FROM transactions_archive
64+
WHERE id = $1;
3465

3566
-- name: DeleteTransactionsBySessionPQ :exec
36-
DELETE FROM transactions_archive WHERE session_id = $1;
67+
DELETE FROM transactions_archive
68+
WHERE session_id = $1;
3769

3870
-- name: CountTransactionsByStatusPQ :one
39-
SELECT COUNT(*) FROM transactions_archive
71+
SELECT COUNT(*) FROM transactions_archive
4072
WHERE session_id = $1 AND status = $2;
73+
74+
-- name: CountTransactionsByOperationPQ :one
75+
SELECT COUNT(*) FROM transactions_archive
76+
WHERE session_id = $1 AND operation = $2;
77+
78+
-- name: GetTransactionStatsPQ :one
79+
SELECT
80+
COUNT(*) as total_transactions,
81+
COUNT(CASE WHEN status = 'success' THEN 1 END) as successful_transactions,
82+
COUNT(CASE WHEN status = 'failed' THEN 1 END) as failed_transactions,
83+
COUNT(CASE WHEN status = 'pending' THEN 1 END) as pending_transactions,
84+
AVG(duration_ms) as avg_duration_ms
85+
FROM transactions_archive
86+
WHERE session_id = $1;

0 commit comments

Comments
 (0)