0.7.19
This commit is contained in:
@@ -310,6 +310,18 @@ pub(crate) async fn ensure_schema(database: &crate::KbDatabase) -> Result<(), cr
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
let result = create_kb_wallet_holdings_table(pool).await;
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
let result = create_kb_idx_wallet_holdings_wallet_id(pool).await;
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
let result = create_kb_idx_wallet_holdings_token_id(pool).await;
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1713,3 +1725,66 @@ CREATE TABLE IF NOT EXISTS kb_pair_metrics (
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn create_kb_wallet_holdings_table(pool: &sqlx::SqlitePool) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_wallet_holdings_table",
|
||||
r#"
|
||||
CREATE TABLE IF NOT EXISTS kb_wallet_holdings (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
wallet_id INTEGER NOT NULL,
|
||||
token_id INTEGER NOT NULL,
|
||||
first_transaction_id INTEGER NOT NULL,
|
||||
last_transaction_id INTEGER NOT NULL,
|
||||
last_decoded_event_id INTEGER NULL,
|
||||
last_pool_id INTEGER NULL,
|
||||
last_pair_id INTEGER NULL,
|
||||
last_role TEXT NULL,
|
||||
balance_raw TEXT NULL,
|
||||
last_slot_observed INTEGER NULL,
|
||||
source_kind INTEGER NOT NULL,
|
||||
source_endpoint_name TEXT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
UNIQUE(wallet_id, token_id),
|
||||
FOREIGN KEY(wallet_id) REFERENCES kb_wallets(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(token_id) REFERENCES kb_tokens(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(first_transaction_id) REFERENCES kb_chain_transactions(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(last_transaction_id) REFERENCES kb_chain_transactions(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(last_decoded_event_id) REFERENCES kb_dex_decoded_events(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY(last_pool_id) REFERENCES kb_pools(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY(last_pair_id) REFERENCES kb_pairs(id) ON DELETE SET NULL
|
||||
)
|
||||
"#,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn create_kb_idx_wallet_holdings_wallet_id(
|
||||
pool: &sqlx::SqlitePool,
|
||||
) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_idx_wallet_holdings_wallet_id",
|
||||
r#"
|
||||
CREATE INDEX IF NOT EXISTS kb_idx_wallet_holdings_wallet_id
|
||||
ON kb_wallet_holdings(wallet_id)
|
||||
"#,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn create_kb_idx_wallet_holdings_token_id(
|
||||
pool: &sqlx::SqlitePool,
|
||||
) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_idx_wallet_holdings_token_id",
|
||||
r#"
|
||||
CREATE INDEX IF NOT EXISTS kb_idx_wallet_holdings_token_id
|
||||
ON kb_wallet_holdings(token_id)
|
||||
"#,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user