database-sqlite
БесплатноБез исполняемых скриптовНе проверенSQLite best practices, connection management, and migration system for PolyFlup.
от Niller2005★ 18 звёзд на GitHubОб этом скилле
Database Best Practices
Connection Management
ALWAYS use the db_connection() context manager:
from src.data.db_connection import db_connection
with db_connection() as conn:
c = conn.cursor()
c.execute("SELECT * FROM trades")
# Commit happens automatically on success
- NEVER call
conn.commit()manually. - Deadlock Prevention: When calling write functions (like
execute_trade) from within an existing transaction, MUST pass the active cursor.
Migration System
The migration system tracks versions in the schema_version table.
Adding a New Migration:
- Create a migration function in
src/data/migrations.py. - Register it in the
MIGRATIONSlist. - Update the base schema in
src/data/database.py.
Rules:
- Check if columns/indices exist before creating.
- Migrations must be idempotent.
- Never delete or modify existing migrations.
Schema Overview
Main table: trades
- Core Fields:
id,timestamp,symbol,side,entry_price,size,bet_usd,edge - Order Tracking:
order_id,order_status(entry and hedge orders tracked separately) - Settlement:
settled,settled_at,exited_early,final_outcome,exit_price,pnl_usd,roi_pct - Timing:
window_start,window_end - Market Data:
slug,token_id,p_yes,best_bid,best_ask,imbalance,funding_bias - Bayesian Comparison (v0.5.0+):
additive_confidence,additive_bias,bayesian_confidence,bayesian_bias,market_prior_p_up - Atomic Hedging (v0.6.0+): Each side of atomic pair stored as separate trade row with linked
trade_idfor P&L tracking
Key Database Patterns
Position Queries (Atomic Hedging)
# Get open positions (both entry and hedge sides)
c.execute("""
SELECT id, symbol, token_id, side, entry_price, size, bet_usd,
edge, window_end, order_id, order_status
FROM trades
WHERE settled = 0 AND exited_early = 0
AND datetime(window_end) > datetime(?)
""", (now.isoformat(),))
Trade Updates (Emergency Liquidation)
# Update position after emergency sell
c.execute("""
UPDATE trades
SET exited_early = 1, exit_price = ?,
pnl_usd = ?, roi_pct = ?, settled_at = ?
WHERE id = ?
""", (exit_price, pnl_usd, roi_pct, now.isoformat(), trade_id))
Settlement
# Settle position with exit data
c.execute("""
UPDATE trades
SET settled = 1, exited_early = 1, exit_price = ?,
pnl_usd = ?, roi_pct = ?, settled_at = ?
WHERE id = ?
""", (exit_price, pnl_usd, roi_pct, now.isoformat(), trade_id))
WAL Mode
- Database uses Write-Ahead Logging (WAL) mode for better concurrency
- Enabled on initialization:
PRAGMA journal_mode=WAL - Allows concurrent readers while writes are in progress
Migration History
- Migration 007 (v0.5.0): Added Bayesian confidence comparison columns (
additive_confidence,additive_bias,bayesian_confidence,bayesian_bias,market_prior_p_up) for A/B testing - Migration 006 (v0.4.x): Added raw signal score columns (
up_total,down_total,momentum_score,momentum_dir,flow_score,flow_dir,divergence_score,divergence_dir,vwm_score,vwm_dir,pm_mom_score,pm_mom_dir,adx_score,adx_dir,lead_lag_bonus) for confidence formula calibration - Migration 005: Added
last_scale_in_atcolumn for tracking scale-in timing - Migration 004: Added
reversal_triggered_atcolumn for timing reversals - Migration 003: Added
reversal_triggeredcolumn for reversal tracking - Migration 002: Added timestamp verification
- Migration 001: Added
scale_in_order_idcolumn for tracking pending scale-in orders
Установить database-sqlite в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл database-sqlite?
SQLite best practices, connection management, and migration system for PolyFlup.
Как установить скилл database-sqlite?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл database-sqlite запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic