Skip to content

Commit 05d4ba4

Browse files
Defined SQL Schema for sqlc
1 parent ea27f08 commit 05d4ba4

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

db/schema.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- database schema for sqlc code generation for archival PostgreSQL
2+
3+
CREATE TABLE sessions_archive (
4+
id UUID PRIMARY KEY,
5+
username TEXT NOT NULL,
6+
ip TEXT,
7+
user_agent TEXT,
8+
status TEXT CHECK (status IN ('active', 'expired')) NOT NULL,
9+
created_at TIMESTAMP NOT NULL,
10+
last_active_at TIMESTAMP NOT NULL,
11+
expiry TIMESTAMP NOT NULL,
12+
completed_count INTEGER DEFAULT 0,
13+
failed_count INTEGER DEFAULT 0,
14+
archived_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
15+
);
16+
17+
CREATE TABLE transactions_archive (
18+
id UUID PRIMARY KEY,
19+
session_id UUID REFERENCES sessions_archive(id) ON DELETE CASCADE,
20+
status TEXT CHECK (status IN ('success', 'failure')) NOT NULL,
21+
output TEXT,
22+
created_at TIMESTAMP NOT NULL
23+
);
24+
25+
-- indexes
26+
CREATE INDEX idx_transactions_session_id ON transactions_archive(session_id);
27+
CREATE INDEX idx_sessions_archive_time ON sessions_archive(archived_at DESC);

0 commit comments

Comments
 (0)