-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the way to migrate whole databse with
--dump {PATH}
argument (
#977) Dump whole schemas and data by generating SQL with --dump {PATH} option gluesql --path ~/gluedata --dump ./dump.sql -- dump.sql CREATE TABLE User (id INT, name TEXT); CREATE INDEX User_id ON User (id); .. INSERT INTO User VALUES (1, 'Foo'), (2, 'Bar') .. .. Import database gluesql --path ~/newdata --execute ./dump.sql
- Loading branch information
Showing
15 changed files
with
551 additions
and
64 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# GlueSQL project files | ||
/data/ | ||
/pkg/rust/data/ | ||
/cli/tmp/ | ||
/storages/**/data/ | ||
/storages/**/tmp/ | ||
/reports/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
fn main() { | ||
gluesql_cli::run(); | ||
gluesql_cli::run().unwrap(); | ||
} |
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,60 @@ | ||
use { | ||
gluesql_cli::dump_database, | ||
gluesql_core::{ | ||
prelude::Glue, | ||
store::{Store, Transaction}, | ||
}, | ||
gluesql_sled_storage::{sled, SledStorage}, | ||
std::{fs::File, io::Read, path::PathBuf}, | ||
}; | ||
|
||
#[tokio::test] | ||
async fn dump_and_import() { | ||
let data_path = "tmp/src"; | ||
let dump_path = PathBuf::from("tmp/dump.sql"); | ||
|
||
let config = sled::Config::default().path(data_path).temporary(true); | ||
let source_storage = SledStorage::try_from(config).unwrap(); | ||
let mut source_glue = Glue::new(source_storage); | ||
|
||
let sqls = vec![ | ||
"CREATE TABLE User (id INT, name TEXT);", | ||
"CREATE INDEX User_id ON User (id);", | ||
"INSERT INTO User SELECT N, 'a' FROM SERIES(101);", | ||
]; | ||
|
||
for sql in sqls { | ||
source_glue.execute(sql).unwrap(); | ||
} | ||
|
||
let sql = "SELECT * FROM User;"; | ||
let source_data = source_glue.execute(sql).unwrap(); | ||
|
||
let source_storage = dump_database(source_glue.storage.unwrap(), dump_path.clone()).unwrap(); | ||
|
||
let data_path = "tmp/target"; | ||
let config = sled::Config::default().path(data_path).temporary(true); | ||
let target_storage = SledStorage::try_from(config).unwrap(); | ||
let mut target_glue = Glue::new(target_storage); | ||
|
||
let mut sqls = String::new(); | ||
File::open(dump_path) | ||
.unwrap() | ||
.read_to_string(&mut sqls) | ||
.unwrap(); | ||
|
||
for sql in sqls.split(';').filter(|sql| !sql.trim().is_empty()) { | ||
target_glue.execute(sql).unwrap(); | ||
} | ||
|
||
let target_data = target_glue.execute(sql).unwrap(); | ||
assert_eq!(source_data, target_data); | ||
|
||
let (source_storage, _) = source_storage.begin(true).await.unwrap(); | ||
let source_schemas = source_storage.fetch_all_schemas().await.unwrap(); | ||
|
||
let (target_storage, _) = target_glue.storage.unwrap().begin(true).await.unwrap(); | ||
let target_schemas = target_storage.fetch_all_schemas().await.unwrap(); | ||
|
||
assert_eq!(source_schemas, target_schemas); | ||
} |
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
Oops, something went wrong.