0.7.2
This commit is contained in:
@@ -218,7 +218,18 @@ pub(crate) async fn ensure_schema(database: &crate::KbDatabase) -> Result<(), cr
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
let result = create_kb_dex_decoded_events_table(pool).await;
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
let result = create_kb_idx_dex_decoded_events_transaction_id(pool).await;
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
let result = create_kb_uq_dex_decoded_events_transaction_instruction_event(pool).await;
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -240,6 +251,21 @@ async fn execute_sqlite_schema_statement(
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates the persisted schema version metadata entry.
|
||||
async fn update_schema_version_metadata(
|
||||
database: &crate::KbDatabase,
|
||||
) -> Result<(), crate::KbError> {
|
||||
let schema_version = crate::KbDbMetadataDto::new(
|
||||
"schema_version".to_string(),
|
||||
env!("CARGO_PKG_VERSION").to_string(),
|
||||
);
|
||||
let upsert_result = crate::upsert_db_metadata(database, &schema_version).await;
|
||||
match upsert_result {
|
||||
Ok(_) => Ok(()),
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates `kb_db_metadata`.
|
||||
async fn create_kb_db_metadata_table(pool: &sqlx::SqlitePool) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
@@ -1073,9 +1099,7 @@ CREATE TABLE IF NOT EXISTS kb_chain_slots (
|
||||
}
|
||||
|
||||
/// Creates `kb_chain_transactions`.
|
||||
async fn create_kb_chain_transactions_table(
|
||||
pool: &sqlx::SqlitePool,
|
||||
) -> Result<(), crate::KbError> {
|
||||
async fn create_kb_chain_transactions_table(pool: &sqlx::SqlitePool) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_chain_transactions_table",
|
||||
@@ -1115,9 +1139,7 @@ ON kb_chain_transactions (slot)
|
||||
}
|
||||
|
||||
/// Creates `kb_chain_instructions`.
|
||||
async fn create_kb_chain_instructions_table(
|
||||
pool: &sqlx::SqlitePool,
|
||||
) -> Result<(), crate::KbError> {
|
||||
async fn create_kb_chain_instructions_table(pool: &sqlx::SqlitePool) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_chain_instructions_table",
|
||||
@@ -1174,17 +1196,60 @@ ON kb_chain_instructions (program_id)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Updates the persisted schema version metadata entry.
|
||||
async fn update_schema_version_metadata(
|
||||
database: &crate::KbDatabase,
|
||||
) -> Result<(), crate::KbError> {
|
||||
let schema_version = crate::KbDbMetadataDto::new(
|
||||
"schema_version".to_string(),
|
||||
env!("CARGO_PKG_VERSION").to_string(),
|
||||
);
|
||||
let upsert_result = crate::upsert_db_metadata(database, &schema_version).await;
|
||||
match upsert_result {
|
||||
Ok(_) => Ok(()),
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
/// Creates `kb_dex_decoded_events`.
|
||||
async fn create_kb_dex_decoded_events_table(pool: &sqlx::SqlitePool) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_dex_decoded_events_table",
|
||||
r#"
|
||||
CREATE TABLE IF NOT EXISTS kb_dex_decoded_events (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
transaction_id INTEGER NOT NULL,
|
||||
instruction_id INTEGER NULL,
|
||||
protocol_name TEXT NOT NULL,
|
||||
program_id TEXT NOT NULL,
|
||||
event_kind TEXT NOT NULL,
|
||||
pool_account TEXT NULL,
|
||||
lp_mint TEXT NULL,
|
||||
token_a_mint TEXT NULL,
|
||||
token_b_mint TEXT NULL,
|
||||
market_account TEXT NULL,
|
||||
payload_json TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
FOREIGN KEY(transaction_id) REFERENCES kb_chain_transactions(id),
|
||||
FOREIGN KEY(instruction_id) REFERENCES kb_chain_instructions(id)
|
||||
)
|
||||
"#,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Creates index on `kb_dex_decoded_events(transaction_id)`.
|
||||
async fn create_kb_idx_dex_decoded_events_transaction_id(
|
||||
pool: &sqlx::SqlitePool,
|
||||
) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_idx_dex_decoded_events_transaction_id",
|
||||
r#"
|
||||
CREATE INDEX IF NOT EXISTS kb_idx_dex_decoded_events_transaction_id
|
||||
ON kb_dex_decoded_events (transaction_id)
|
||||
"#,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Creates unique index on `(transaction_id, instruction_id, event_kind)`.
|
||||
async fn create_kb_uq_dex_decoded_events_transaction_instruction_event(
|
||||
pool: &sqlx::SqlitePool,
|
||||
) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_uq_dex_decoded_events_transaction_instruction_event",
|
||||
r#"
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS kb_uq_dex_decoded_events_transaction_instruction_event
|
||||
ON kb_dex_decoded_events (transaction_id, instruction_id, event_kind)
|
||||
"#,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user