0.7.9
This commit is contained in:
@@ -230,6 +230,30 @@ pub(crate) async fn ensure_schema(database: &crate::KbDatabase) -> Result<(), cr
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
let result = create_kb_launch_surfaces_table(pool).await;
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
let result = create_kb_launch_surface_keys_table(pool).await;
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
let result = create_kb_idx_launch_surface_keys_surface_id(pool).await;
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
let result = create_kb_launch_attributions_table(pool).await;
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
let result = create_kb_idx_launch_attributions_surface_id(pool).await;
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
let result = create_kb_idx_launch_attributions_pool_id(pool).await;
|
||||
if let Err(error) = result {
|
||||
return Err(error);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1253,3 +1277,118 @@ ON kb_dex_decoded_events (transaction_id, instruction_id, event_kind)
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn create_kb_launch_surfaces_table(pool: &sqlx::SqlitePool) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_launch_surfaces_table",
|
||||
r#"
|
||||
CREATE TABLE IF NOT EXISTS kb_launch_surfaces (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
code TEXT NOT NULL UNIQUE,
|
||||
name TEXT NOT NULL,
|
||||
protocol_family TEXT NULL,
|
||||
is_enabled INTEGER NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL
|
||||
)
|
||||
"#,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn create_kb_launch_surface_keys_table(
|
||||
pool: &sqlx::SqlitePool,
|
||||
) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_launch_surface_keys_table",
|
||||
r#"
|
||||
CREATE TABLE IF NOT EXISTS kb_launch_surface_keys (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
launch_surface_id INTEGER NOT NULL,
|
||||
match_kind TEXT NOT NULL,
|
||||
match_value TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
FOREIGN KEY(launch_surface_id) REFERENCES kb_launch_surfaces(id) ON DELETE CASCADE,
|
||||
UNIQUE(match_kind, match_value)
|
||||
)
|
||||
"#,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn create_kb_idx_launch_surface_keys_surface_id(
|
||||
pool: &sqlx::SqlitePool,
|
||||
) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_idx_launch_surface_keys_surface_id",
|
||||
r#"
|
||||
CREATE INDEX IF NOT EXISTS kb_idx_launch_surface_keys_surface_id
|
||||
ON kb_launch_surface_keys(launch_surface_id)
|
||||
"#,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn create_kb_launch_attributions_table(
|
||||
pool: &sqlx::SqlitePool,
|
||||
) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_launch_attributions_table",
|
||||
r#"
|
||||
CREATE TABLE IF NOT EXISTS kb_launch_attributions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
launch_surface_id INTEGER NOT NULL,
|
||||
transaction_id INTEGER NOT NULL,
|
||||
decoded_event_id INTEGER NOT NULL UNIQUE,
|
||||
pool_id INTEGER NULL,
|
||||
pair_id INTEGER NULL,
|
||||
matched_key_id INTEGER NULL,
|
||||
protocol_name TEXT NOT NULL,
|
||||
match_kind TEXT NOT NULL,
|
||||
matched_value TEXT NOT NULL,
|
||||
attributed_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
FOREIGN KEY(launch_surface_id) REFERENCES kb_launch_surfaces(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(transaction_id) REFERENCES kb_chain_transactions(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(decoded_event_id) REFERENCES kb_dex_decoded_events(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(pool_id) REFERENCES kb_pools(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY(pair_id) REFERENCES kb_pairs(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY(matched_key_id) REFERENCES kb_launch_surface_keys(id) ON DELETE SET NULL
|
||||
)
|
||||
"#,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn create_kb_idx_launch_attributions_surface_id(
|
||||
pool: &sqlx::SqlitePool,
|
||||
) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_idx_launch_attributions_surface_id",
|
||||
r#"
|
||||
CREATE INDEX IF NOT EXISTS kb_idx_launch_attributions_surface_id
|
||||
ON kb_launch_attributions(launch_surface_id)
|
||||
"#,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn create_kb_idx_launch_attributions_pool_id(
|
||||
pool: &sqlx::SqlitePool,
|
||||
) -> Result<(), crate::KbError> {
|
||||
execute_sqlite_schema_statement(
|
||||
pool,
|
||||
"create_kb_idx_launch_attributions_pool_id",
|
||||
r#"
|
||||
CREATE INDEX IF NOT EXISTS kb_idx_launch_attributions_pool_id
|
||||
ON kb_launch_attributions(pool_id)
|
||||
"#,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user