-
Notifications
You must be signed in to change notification settings - Fork 32
GH-601: Introduce SentPayable Table #609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
75bd22c
GH-601: introduce sent_payable table
utkarshg6 343fff2
GH-601: test that table with certain columns were created during migr…
utkarshg6 3cab9fd
GH-601: resuse code to test fields of table
utkarshg6 44b61ba
GH-601: migrate utils code
utkarshg6 307008d
GH-601: trigger actions
utkarshg6 1671249
GH-601: fix test constants_have_correct_values
utkarshg6 43488d8
Merge branch 'master' into GH-601
utkarshg6 0628d7a
GH-601: review changes
utkarshg6 9a10880
GH-601: move constant to database/test_utils.rs
utkarshg6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
95 changes: 95 additions & 0 deletions
95
node/src/database/db_migrations/migrations/migration_10_to_11.rs
This file contains hidden or 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,95 @@ | ||
| use crate::database::db_migrations::db_migrator::DatabaseMigration; | ||
| use crate::database::db_migrations::migrator_utils::DBMigDeclarator; | ||
|
|
||
| #[allow(non_camel_case_types)] | ||
| pub struct Migrate_10_to_11; | ||
|
|
||
| impl DatabaseMigration for Migrate_10_to_11 { | ||
| fn migrate<'a>( | ||
| &self, | ||
| declaration_utils: Box<dyn DBMigDeclarator + 'a>, | ||
| ) -> rusqlite::Result<()> { | ||
| let sql_statement = "create table if not exists sent_payable ( | ||
| rowid integer primary key, | ||
| tx_hash text not null, | ||
| receiver_address text not null, | ||
| amount_high_b integer not null, | ||
| amount_low_b integer not null, | ||
| timestamp integer not null, | ||
| gas_price_wei integer not null, | ||
| nonce integer not null, | ||
| status text not null, | ||
| retried integer not null | ||
| )"; | ||
|
|
||
| declaration_utils.execute_upon_transaction(&[&sql_statement]) | ||
| } | ||
|
|
||
| fn old_version(&self) -> usize { | ||
| 10 | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::database::db_initializer::{ | ||
| DbInitializationConfig, DbInitializer, DbInitializerReal, DATABASE_FILE, | ||
| }; | ||
| use crate::test_utils::database_utils::{ | ||
| assert_create_table_stm_contains_all_parts, assert_table_exists, | ||
| bring_db_0_back_to_life_and_return_connection, make_external_data, | ||
| }; | ||
| use masq_lib::test_utils::logging::{init_test_logging, TestLogHandler}; | ||
| use masq_lib::test_utils::utils::ensure_node_home_directory_exists; | ||
| use std::fs::create_dir_all; | ||
|
|
||
| #[test] | ||
| fn migration_from_10_to_11_is_applied_correctly() { | ||
| init_test_logging(); | ||
| let dir_path = ensure_node_home_directory_exists( | ||
| "db_migrations", | ||
| "migration_from_10_to_11_is_properly_set", | ||
| ); | ||
| create_dir_all(&dir_path).unwrap(); | ||
| let db_path = dir_path.join(DATABASE_FILE); | ||
| let _ = bring_db_0_back_to_life_and_return_connection(&db_path); | ||
| let subject = DbInitializerReal::default(); | ||
|
|
||
| let result = subject.initialize_to_version( | ||
| &dir_path, | ||
| 10, | ||
| DbInitializationConfig::create_or_migrate(make_external_data()), | ||
| ); | ||
|
|
||
| assert!(result.is_ok()); | ||
|
|
||
| let result = subject.initialize_to_version( | ||
| &dir_path, | ||
| 11, | ||
| DbInitializationConfig::create_or_migrate(make_external_data()), | ||
| ); | ||
|
|
||
| let connection = result.unwrap(); | ||
| assert_table_exists(connection.as_ref(), "sent_payable"); | ||
| let expected_key_words: &[&[&str]] = &[ | ||
| &["rowid", "integer", "primary", "key"], | ||
| &["tx_hash", "text", "not", "null"], | ||
| &["receiver_address", "text", "not", "null"], | ||
| &["amount_high_b", "integer", "not", "null"], | ||
| &["amount_low_b", "integer", "not", "null"], | ||
| &["timestamp", "integer", "not", "null"], | ||
| &["gas_price_wei", "integer", "not", "null"], | ||
| &["nonce", "integer", "not", "null"], | ||
| &["status", "text", "not", "null"], | ||
| &["retried", "integer", "not", "null"], | ||
| ]; | ||
utkarshg6 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert_create_table_stm_contains_all_parts( | ||
| &*connection, | ||
| "sent_payable", | ||
| expected_key_words, | ||
| ); | ||
| TestLogHandler::new().assert_logs_contain_in_order(vec![ | ||
| "DbMigrator: Database successfully migrated from version 10 to 11", | ||
| ]); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.