Skip to content

Commit

Permalink
cover sql nft tx history migration
Browse files Browse the repository at this point in the history
  • Loading branch information
laruh committed Sep 13, 2024
1 parent 661fc80 commit 68062f8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions mm2src/coins/nft/storage/sql_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fn create_schema_versions_sql() -> Result<String, SqlError> {
let sql = format!(
"CREATE TABLE IF NOT EXISTS {} (
table_name TEXT PRIMARY KEY,
version INTEGER NOT NULL,
version INTEGER NOT NULL
);",
safe_table_name.inner()
);
Expand Down Expand Up @@ -520,9 +520,16 @@ fn update_transfer_spam_by_token_addr_id(chain: &Chain) -> Result<String, SqlErr
Ok(sql)
}

/// Generates the SQL command to insert or update the schema version in the `schema_versions` table.
///
/// This function creates an SQL command that attempts to insert a new row with the specified
/// `table_name` and `version`. If a row with the same `table_name` already exists, the `version`
/// field is updated to the new value provided.
fn update_schema_version_sql(schema_versions: &SafeTableName) -> String {
format!(
"UPDATE {} SET version = ?1 WHERE table_name = ?2;",
"INSERT INTO {} (table_name, version)
VALUES (?1, ?2)
ON CONFLICT(table_name) DO UPDATE SET version = excluded.version;",
schema_versions.inner()
)
}
Expand Down Expand Up @@ -1443,8 +1450,8 @@ fn migrate_tx_history_table_schema(
sql_tx.execute(&rename_table_sql, [])?;

sql_tx.execute(&update_schema_version_sql(&schema_table), [
CURRENT_SCHEMA_VERSION_TX_HISTORY.to_string(),
history_table.inner().to_string(),
CURRENT_SCHEMA_VERSION_TX_HISTORY.to_string(),
])?;

sql_tx.commit()?;
Expand Down

0 comments on commit 68062f8

Please sign in to comment.