This commit is contained in:
2026-04-30 10:50:37 +02:00
parent 523bbe0860
commit 37d54887d6
16 changed files with 1495 additions and 9 deletions

View File

@@ -322,6 +322,18 @@ pub(crate) async fn ensure_schema(database: &crate::KbDatabase) -> Result<(), cr
if let Err(error) = result {
return Err(error);
}
let result = create_kb_pair_candles_table(pool).await;
if let Err(error) = result {
return Err(error);
}
let result = create_kb_idx_pair_candles_pair_timeframe(pool).await;
if let Err(error) = result {
return Err(error);
}
let result = create_kb_idx_pair_candles_bucket(pool).await;
if let Err(error) = result {
return Err(error);
}
Ok(())
}
}
@@ -1788,3 +1800,61 @@ ON kb_wallet_holdings(token_id)
)
.await
}
async fn create_kb_pair_candles_table(pool: &sqlx::SqlitePool) -> Result<(), crate::KbError> {
execute_sqlite_schema_statement(
pool,
"create_kb_pair_candles_table",
r#"
CREATE TABLE IF NOT EXISTS kb_pair_candles (
id INTEGER PRIMARY KEY AUTOINCREMENT,
pair_id INTEGER NOT NULL,
timeframe_seconds INTEGER NOT NULL,
bucket_start_unix INTEGER NOT NULL,
bucket_end_unix INTEGER NOT NULL,
open_price_quote_per_base REAL NOT NULL,
high_price_quote_per_base REAL NOT NULL,
low_price_quote_per_base REAL NOT NULL,
close_price_quote_per_base REAL NOT NULL,
trade_count INTEGER NOT NULL,
buy_count INTEGER NOT NULL,
sell_count INTEGER NOT NULL,
base_volume_raw TEXT NULL,
quote_volume_raw TEXT NULL,
first_trade_signature TEXT NULL,
last_trade_signature TEXT NULL,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL,
UNIQUE(pair_id, timeframe_seconds, bucket_start_unix),
FOREIGN KEY(pair_id) REFERENCES kb_pairs(id) ON DELETE CASCADE
)
"#,
)
.await
}
async fn create_kb_idx_pair_candles_pair_timeframe(
pool: &sqlx::SqlitePool,
) -> Result<(), crate::KbError> {
execute_sqlite_schema_statement(
pool,
"create_kb_idx_pair_candles_pair_timeframe",
r#"
CREATE INDEX IF NOT EXISTS kb_idx_pair_candles_pair_timeframe
ON kb_pair_candles(pair_id, timeframe_seconds)
"#,
)
.await
}
async fn create_kb_idx_pair_candles_bucket(pool: &sqlx::SqlitePool) -> Result<(), crate::KbError> {
execute_sqlite_schema_statement(
pool,
"create_kb_idx_pair_candles_bucket",
r#"
CREATE INDEX IF NOT EXISTS kb_idx_pair_candles_bucket
ON kb_pair_candles(bucket_start_unix)
"#,
)
.await
}