-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1511 from zcash/sqlite_legacy_support
Support older sqlite versions.
- Loading branch information
Showing
8 changed files
with
168 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
zcash_client_sqlite/src/wallet/init/migrations/support_legacy_sqlite.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//! Modifies definitions to avoid keywords that may not be available in older SQLite versions. | ||
use std::collections::HashSet; | ||
|
||
use rusqlite; | ||
use schemer; | ||
use schemer_rusqlite::RusqliteMigration; | ||
use uuid::Uuid; | ||
|
||
use crate::wallet::init::{migrations::tx_retrieval_queue, WalletMigrationError}; | ||
|
||
pub(super) const MIGRATION_ID: Uuid = Uuid::from_u128(0x156d8c8f_2173_4b59_89b6_75697d5a2103); | ||
|
||
const DEPENDENCIES: &[Uuid] = &[tx_retrieval_queue::MIGRATION_ID]; | ||
|
||
pub(super) struct Migration; | ||
|
||
impl schemer::Migration for Migration { | ||
fn id(&self) -> Uuid { | ||
MIGRATION_ID | ||
} | ||
|
||
fn dependencies(&self) -> HashSet<Uuid> { | ||
DEPENDENCIES.iter().copied().collect() | ||
} | ||
|
||
fn description(&self) -> &'static str { | ||
"Modifies definitions to avoid keywords that may not be available in older SQLite versions." | ||
} | ||
} | ||
|
||
impl RusqliteMigration for Migration { | ||
type Error = WalletMigrationError; | ||
|
||
fn up(&self, transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { | ||
transaction.execute_batch( | ||
r#" | ||
DROP VIEW v_tx_outputs; | ||
CREATE VIEW v_tx_outputs AS | ||
-- select all outputs received by the wallet | ||
SELECT transactions.txid AS txid, | ||
ro.pool AS output_pool, | ||
ro.output_index AS output_index, | ||
sent_notes.from_account_id AS from_account_id, | ||
ro.account_id AS to_account_id, | ||
NULL AS to_address, | ||
ro.value AS value, | ||
ro.is_change AS is_change, | ||
ro.memo AS memo | ||
FROM v_received_outputs ro | ||
JOIN transactions | ||
ON transactions.id_tx = ro.transaction_id | ||
-- join to the sent_notes table to obtain `from_account_id` | ||
LEFT JOIN sent_notes ON sent_notes.id = ro.sent_note_id | ||
UNION | ||
-- select all outputs sent from the wallet to external recipients | ||
SELECT transactions.txid AS txid, | ||
sent_notes.output_pool AS output_pool, | ||
sent_notes.output_index AS output_index, | ||
sent_notes.from_account_id AS from_account_id, | ||
NULL AS to_account_id, | ||
sent_notes.to_address AS to_address, | ||
sent_notes.value AS value, | ||
0 AS is_change, | ||
sent_notes.memo AS memo | ||
FROM sent_notes | ||
JOIN transactions | ||
ON transactions.id_tx = sent_notes.tx | ||
LEFT JOIN v_received_outputs ro ON ro.sent_note_id = sent_notes.id | ||
-- exclude any sent notes for which a row exists in the v_received_outputs view | ||
WHERE ro.account_id IS NULL | ||
"#, | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn down(&self, _: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { | ||
Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::wallet::init::migrations::tests::test_migrate; | ||
|
||
#[test] | ||
fn migrate() { | ||
test_migrate(&[super::MIGRATION_ID]); | ||
} | ||
} |