-
Notifications
You must be signed in to change notification settings - Fork 24
Command to migrate DB data from v1.0.0 to v2.0.0
#77
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
Merged
josecelano
merged 53 commits into
develop
from
issue-56-db-migration-command-from-v1-to-v2
Nov 30, 2022
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
c3414da
feat: add target dir to .gitignore
josecelano 5d6dec0
refactor: allow adding more binaries
josecelano 7513df0
refactor: add scaffolding for database migration command
josecelano b92fb08
feat: [#56] transfer categories from db v1.0.0 to v2.0.0
josecelano 996c7d1
refactor: [#56] rename command al dirs
josecelano d590972
refactor: [#56] move upgrader from main upgrade mod to specific versi…
josecelano d1059f5
feat: [#56] trasnfer user data from v1.0.0 to v2.0.0
josecelano cf09283
docs: [#56] update README for integration tests
josecelano 01921ed
fix: [#56] triggering recompilation on migration changes
josecelano d9b4e87
feat: [#56] transfer user password from v1.0.0 to v2.0.0
josecelano dd949fa
feat: [#56] transfer tracker keys from v1.0.0 to v2.0.0
josecelano 35f1e37
fix: [#56} default user registration date with time
josecelano 8d26faa
fix: [#78] parsing keys from tracker
josecelano 0b3aefa
feat: [#56] transfer torrents (1/4 tables) from v1.0.0 to v2.0.0
josecelano 03e4bef
feat: [#56] remove unused scripts and write basic upgrage guide
josecelano 3fea6ea
feat: [#56] trasnfer torrents (2/4 tables) from v1.0.0 to v2.0.0
josecelano 8bdf32f
feat: [#56] trasnfer torrents (3/4 tables) from v1.0.0 to v2.0.0
josecelano 21174d4
feat: [#56] trasnfer torrents (4/4 tables) from v1.0.0 to v2.0.0
josecelano 99edf52
feat: imported users have importation date instead of registrataion date
josecelano 7152654
refactor: [#56] rename structs for DB records
josecelano b9bf405
feat: [#56] improve command output
josecelano 6bb4c53
refactor: extract struct TorrentRecordV2
josecelano 72dc139
refactor: reformat sql queries
josecelano 309e141
fix: take torrent private flag from torrent file
josecelano f620e05
fix: [#56] announce list has precedence over announce
josecelano 693994f
feat: add new dependency text_colorizer
josecelano aabc3ef
feat: the upgrader command takes args
josecelano 217fae2
feat: [#56] take source DB in upgrader command from args
josecelano 7f0a7ea
fix: open source db in read-only mode in upgarder
josecelano 44927e5
test: [#56] WIP. scaffolding to test upgrader command
josecelano 6188b10
refactor: extract mod sqlite_v1_0_0 in tests
josecelano f993107
tests: [#56] for users table in upgrader
josecelano 5d0def2
refactor: [#56] tests for upgrader
josecelano 0a58b6c
fix: [#56] bio and avatar is user profile should be NULL for imported…
josecelano 8d74e66
tests: [#56] for users profile and auth tables in upgrader
josecelano eef980c
tests: [#56] for tracker keys table in upgrader
josecelano f0f581f
tests: [#56] for torrents table in upgrader
josecelano cd95987
refactor: [#56] rename mod and variables
josecelano 0063289
tests: [#56] for torrents info and announce urls tables in upgrader
josecelano 750969d
refactor: [#56] rename methods
josecelano 82b84a3
refactor: [#56] extract test configuration
josecelano afffaef
tests: [#56] for torrents files table in upgrader
josecelano ee01e7b
test: [#56] for torrent files table in upgrader (new case)
josecelano e23d948
refactor: remove duplication in tests
josecelano e1790f6
refactor: [#56] extract mods in upgrader
josecelano b9a8bf9
fix: [#56] remove comment
josecelano 38fee53
test: [#56] new test for password verification
josecelano b29d4d7
fix: [#56] db migration for imported users
josecelano 8b761c8
feat: [#56] keep category id in DB migration script
josecelano b400962
fix: format
josecelano e8d984d
refactor: [#56] rename destiny DB to target DB
josecelano 19d054e
refactor: [#56] rename test mods to follow prod mods
josecelano 5a7d875
feat: [#56] console command to import tracker stats for all torrents
josecelano 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| /.env | ||
| /data.db* | ||
| /config.toml | ||
| /uploads/ | ||
| /data.db* | ||
| /data_v2.db* | ||
| /target | ||
| /uploads/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // generated by `sqlx migrate build-script` | ||
| fn main() { | ||
| // trigger recompilation when a new migration is added | ||
| println!("cargo:rerun-if-changed=migrations"); | ||
| } |
1 change: 1 addition & 0 deletions
1
migrations/mysql/20221109092556_torrust_user_date_registered_allow_null.sql
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 @@ | ||
| ALTER TABLE torrust_users CHANGE date_registered date_registered DATETIME DEFAULT NULL |
1 change: 1 addition & 0 deletions
1
migrations/mysql/20221109095718_torrust_user_add_date_imported.sql
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 @@ | ||
| ALTER TABLE torrust_users ADD COLUMN date_imported DATETIME DEFAULT NULL |
11 changes: 11 additions & 0 deletions
11
migrations/sqlite3/20221109092556_torrust_user_date_registered_allow_null.sql
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,11 @@ | ||
| CREATE TABLE IF NOT EXISTS torrust_users_new ( | ||
| user_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
| date_registered TEXT DEFAULT NULL, | ||
| administrator BOOL NOT NULL DEFAULT FALSE | ||
| ); | ||
|
|
||
| INSERT INTO torrust_users_new SELECT * FROM torrust_users; | ||
|
|
||
| DROP TABLE torrust_users; | ||
|
|
||
| ALTER TABLE torrust_users_new RENAME TO torrust_users |
1 change: 1 addition & 0 deletions
1
migrations/sqlite3/20221109095718_torrust_user_add_date_imported.sql
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 @@ | ||
| ALTER TABLE torrust_users ADD COLUMN date_imported TEXT DEFAULT NULL |
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,10 @@ | ||
| //! Import Tracker Statistics command. | ||
| //! It imports the number of seeders and leechers for all torrent from the linked tracker. | ||
| //! You can execute it with: `cargo run --bin import_tracker_statistics` | ||
|
|
||
| use torrust_index_backend::console::commands::import_tracker_statistics::run_importer; | ||
|
|
||
| #[actix_web::main] | ||
| async fn main() { | ||
| run_importer().await; | ||
| } |
File renamed without changes.
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,10 @@ | ||
| //! Upgrade command. | ||
| //! It updates the application from version v1.0.0 to v2.0.0. | ||
| //! You can execute it with: `cargo run --bin upgrade ./data.db ./data_v2.db ./uploads` | ||
|
|
||
| use torrust_index_backend::upgrades::from_v1_0_0_to_v2_0_0::upgrader::run_upgrader; | ||
|
|
||
| #[actix_web::main] | ||
| async fn main() { | ||
| run_upgrader().await; | ||
| } |
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,86 @@ | ||
| //! It imports statistics for all torrents from the linked tracker. | ||
|
|
||
| use std::env; | ||
| use std::sync::Arc; | ||
|
|
||
| use derive_more::{Display, Error}; | ||
| use text_colorizer::*; | ||
|
|
||
| use crate::config::Configuration; | ||
| use crate::databases::database::connect_database; | ||
| use crate::tracker::TrackerService; | ||
|
|
||
| const NUMBER_OF_ARGUMENTS: usize = 0; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct Arguments {} | ||
|
|
||
| #[derive(Debug, Display, PartialEq, Error)] | ||
| #[allow(dead_code)] | ||
| pub enum ImportError { | ||
| #[display(fmt = "internal server error")] | ||
| WrongNumberOfArgumentsError, | ||
| } | ||
|
|
||
| fn parse_args() -> Result<Arguments, ImportError> { | ||
| let args: Vec<String> = env::args().skip(1).collect(); | ||
|
|
||
| if args.len() != NUMBER_OF_ARGUMENTS { | ||
| eprintln!( | ||
| "{} wrong number of arguments: expected {}, got {}", | ||
| "Error".red().bold(), | ||
| NUMBER_OF_ARGUMENTS, | ||
| args.len() | ||
| ); | ||
| print_usage(); | ||
| return Err(ImportError::WrongNumberOfArgumentsError); | ||
| } | ||
|
|
||
| Ok(Arguments {}) | ||
| } | ||
|
|
||
| fn print_usage() { | ||
| eprintln!( | ||
| "{} - imports torrents statistics from linked tracker. | ||
|
|
||
| cargo run --bin upgrade SOURCE_DB_FILE DESTINY_DB_FILE TORRENT_UPLOAD_DIR | ||
|
|
||
| For example: | ||
|
|
||
| cargo run --bin import_tracker_statistics | ||
|
|
||
| ", | ||
| "Upgrader".green() | ||
| ); | ||
| } | ||
|
|
||
| pub async fn run_importer() { | ||
| import(&parse_args().unwrap()).await; | ||
| } | ||
|
|
||
| pub async fn import(_args: &Arguments) { | ||
| println!("Importing statistics from linked tracker ..."); | ||
|
|
||
| let cfg = match Configuration::load_from_file().await { | ||
| Ok(config) => Arc::new(config), | ||
| Err(error) => { | ||
| panic!("{}", error) | ||
| } | ||
| }; | ||
|
|
||
| let settings = cfg.settings.read().await; | ||
|
|
||
| let tracker_url = settings.tracker.url.clone(); | ||
|
|
||
| eprintln!("Tracker url: {}", tracker_url.green()); | ||
|
|
||
| let database = Arc::new( | ||
| connect_database(&settings.database.connect_url) | ||
| .await | ||
| .expect("Database error."), | ||
| ); | ||
|
|
||
| let tracker_service = Arc::new(TrackerService::new(cfg.clone(), database.clone())); | ||
|
|
||
| tracker_service.update_torrents().await.unwrap(); | ||
| } | ||
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 @@ | ||
| pub mod import_tracker_statistics; |
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 @@ | ||
| pub mod commands; |
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
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.