Stage 04.1 - storage foundation with postgres

This commit is contained in:
2026-04-14 21:38:52 +03:00
parent 1deb676585
commit 65ecb95855
14 changed files with 431 additions and 2 deletions

44
app/src/storage/schema.py Normal file
View File

@@ -0,0 +1,44 @@
from __future__ import annotations
from src.storage.session import get_connection
DDL = [
'''
CREATE TABLE IF NOT EXISTS balance_snapshots (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
source TEXT NOT NULL,
payload_json JSONB NOT NULL
)
''',
'''
CREATE TABLE IF NOT EXISTS journal_events (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
level TEXT NOT NULL,
event_type TEXT NOT NULL,
message TEXT NOT NULL,
payload_json JSONB
)
''',
'''
CREATE TABLE IF NOT EXISTS order_drafts (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
symbol TEXT NOT NULL,
side TEXT NOT NULL,
order_type TEXT NOT NULL,
quantity NUMERIC(36, 18) NOT NULL,
status TEXT NOT NULL,
payload_json JSONB
)
'''
]
def init_schema() -> None:
with get_connection() as connection:
with connection.cursor() as cursor:
for statement in DDL:
cursor.execute(statement)