From caceae6a759772311d3a0aae0d6846f52abe51b3 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 4 Oct 2023 02:34:57 -0400 Subject: [PATCH] fix copying with diff --- martin-mbtiles/src/copier.rs | 164 ++++++++++-------- martin-mbtiles/src/errors.rs | 2 +- martin-mbtiles/src/queries.rs | 11 ++ martin-mbtiles/tests/mbtiles.rs | 74 ++++---- ...es__copy_and_convert@flat-cp-skip-agg.snap | 6 +- .../mbtiles__copy_and_convert@flat-cp.snap | 6 +- ...btiles__copy_and_convert@flat-to-flat.snap | 6 +- ...btiles__copy_and_convert@flat-to-hash.snap | 6 +- ...btiles__copy_and_convert@flat-to-norm.snap | 6 +- .../mbtiles__copy_and_convert@flat.snap | 6 +- ...es__copy_and_convert@hash-cp-skip-agg.snap | 6 +- .../mbtiles__copy_and_convert@hash-cp.snap | 6 +- ...btiles__copy_and_convert@hash-to-flat.snap | 6 +- ...btiles__copy_and_convert@hash-to-hash.snap | 6 +- ...btiles__copy_and_convert@hash-to-norm.snap | 6 +- .../mbtiles__copy_and_convert@hash.snap | 6 +- ...es__copy_and_convert@norm-cp-skip-agg.snap | 6 +- .../mbtiles__copy_and_convert@norm-cp.snap | 6 +- ...btiles__copy_and_convert@norm-to-flat.snap | 6 +- ...btiles__copy_and_convert@norm-to-hash.snap | 6 +- ...btiles__copy_and_convert@norm-to-norm.snap | 6 +- .../mbtiles__copy_and_convert@norm.snap | 6 +- .../mbtiles__copy_and_convert@orig.snap | 6 +- ...es__diff_and_apply@applied-flat-flat.snap} | 6 +- ...les__diff_and_apply@applied-flat-hash.snap | 41 +++++ ...les__diff_and_apply@applied-flat-norm.snap | 41 +++++ ...es__diff_and_apply@applied-hash-flat.snap} | 6 +- ...les__diff_and_apply@applied-hash-hash.snap | 49 ++++++ ...les__diff_and_apply@applied-hash-norm.snap | 49 ++++++ ...es__diff_and_apply@applied-norm-flat.snap} | 10 +- ...les__diff_and_apply@applied-norm-hash.snap | 86 +++++++++ ...les__diff_and_apply@applied-norm-norm.snap | 86 +++++++++ ...iles__diff_and_apply@delta-flat-flat.snap} | 4 +- ...tiles__diff_and_apply@delta-flat-hash.snap | 42 +++++ ...tiles__diff_and_apply@delta-flat-norm.snap | 42 +++++ ...tiles__diff_and_apply@delta-hash-flat.snap | 50 ++++++ ...iles__diff_and_apply@delta-hash-hash.snap} | 4 +- ...tiles__diff_and_apply@delta-hash-norm.snap | 50 ++++++ ...tiles__diff_and_apply@delta-norm-flat.snap | 85 +++++++++ ...iles__diff_and_apply@delta-norm-hash.snap} | 4 +- ...tiles__diff_and_apply@delta-norm-norm.snap | 84 +++++++++ .../mbtiles__diff_and_apply@flat_v1.snap | 6 +- .../mbtiles__diff_and_apply@flat_v2.snap | 6 +- .../mbtiles__diff_and_apply@hash_v1.snap | 6 +- .../mbtiles__diff_and_apply@hash_v2.snap | 6 +- .../mbtiles__diff_and_apply@norm_v1.snap | 6 +- .../mbtiles__diff_and_apply@norm_v2.snap | 6 +- .../mbtiles__diff_and_apply@orig_v1.snap | 6 +- .../mbtiles__diff_and_apply@orig_v2.snap | 6 +- 49 files changed, 945 insertions(+), 207 deletions(-) rename martin-mbtiles/tests/snapshots/{mbtiles__diff_and_apply@flat-applied-diff.snap => mbtiles__diff_and_apply@applied-flat-flat.snap} (88%) create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-flat-hash.snap create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-flat-norm.snap rename martin-mbtiles/tests/snapshots/{mbtiles__diff_and_apply@hash-applied-diff.snap => mbtiles__diff_and_apply@applied-hash-flat.snap} (83%) create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-hash-hash.snap create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-hash-norm.snap rename martin-mbtiles/tests/snapshots/{mbtiles__diff_and_apply@norm-applied-diff.snap => mbtiles__diff_and_apply@applied-norm-flat.snap} (86%) create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-norm-hash.snap create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-norm-norm.snap rename martin-mbtiles/tests/snapshots/{mbtiles__diff_and_apply@flat-diff_v2-v1.snap => mbtiles__diff_and_apply@delta-flat-flat.snap} (92%) create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-flat-hash.snap create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-flat-norm.snap create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-hash-flat.snap rename martin-mbtiles/tests/snapshots/{mbtiles__diff_and_apply@hash-diff_v2-v1.snap => mbtiles__diff_and_apply@delta-hash-hash.snap} (89%) create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-hash-norm.snap create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-norm-flat.snap rename martin-mbtiles/tests/snapshots/{mbtiles__diff_and_apply@norm-diff_v2-v1.snap => mbtiles__diff_and_apply@delta-norm-hash.snap} (94%) create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-norm-norm.snap diff --git a/martin-mbtiles/src/copier.rs b/martin-mbtiles/src/copier.rs index 7869625aa..006e67100 100644 --- a/martin-mbtiles/src/copier.rs +++ b/martin-mbtiles/src/copier.rs @@ -14,7 +14,7 @@ use crate::mbtiles::MbtType::{Flat, FlatWithHash, Normalized}; use crate::mbtiles::{detach_db, MbtType}; use crate::queries::{ create_flat_tables, create_flat_with_hash_tables, create_normalized_tables, - create_tiles_with_hash_view, + create_tiles_with_hash_view, is_empty_database, }; use crate::{MbtError, Mbtiles, AGG_TILES_HASH, AGG_TILES_HASH_IN_DIFF}; @@ -138,49 +138,48 @@ impl MbtileCopierInt { } pub async fn run(self) -> MbtResult { - // src file connection is not needed after this point, as it will be attached to the dst file + // src and diff file connections are not needed later, as they will be attached to the dst file let src_type = self.src_mbtiles.open_and_detect_type().await?; + let dif = if let Some(dif_file) = &self.options.diff_with_file { + let dif_file = Mbtiles::new(dif_file)?; + let dif_type = dif_file.open_and_detect_type().await?; + Some((dif_file, dif_type)) + } else { + None + }; + let mut conn = self.dst_mbtiles.open_or_new().await?; + let is_empty_db = is_empty_database(&mut conn).await?; + self.src_mbtiles.attach_to(&mut conn, "sourceDb").await?; + + let src_path = self.src_mbtiles.filepath(); + let dst_path = self.dst_mbtiles.filepath(); + let dst_type; + if let Some((dif_mbt, dif_type)) = &dif { + if !is_empty_db { + return Err(MbtError::NonEmptyTargetFile(self.options.dst_file)); + } + dst_type = self.options.dst_type.unwrap_or(src_type); + dif_mbt.attach_to(&mut conn, "diffDb").await?; + let dif_path = dif_mbt.filepath(); + info!("Comparing {src_path} ({src_type}) and {dif_path} ({dif_type}) into a new file {dst_path} ({dst_type})"); + } else if is_empty_db { + dst_type = self.options.dst_type.unwrap_or(src_type); + info!("Copying {src_path} ({src_type}) to a new file {dst_path} ({dst_type})"); + } else { + dst_type = self.dst_mbtiles.detect_type(&mut conn).await?; + info!("Copying {src_path} ({src_type}) to an existing file {dst_path} ({dst_type})"); + } - let is_empty = query!("SELECT 1 as has_rows FROM sqlite_schema LIMIT 1") - .fetch_optional(&mut conn) - .await? - .is_none(); - - let dst_type = if is_empty { - let dst_type = self.options.dst_type.unwrap_or(src_type); - info!( - "Copying {} ({src_type}) to a new file {} ({dst_type})", - self.options.src_file.display(), - self.options.dst_file.display() - ); + if is_empty_db { self.init_new_schema(&mut conn, src_type, dst_type).await?; - dst_type - } else if self.options.diff_with_file.is_some() { - return Err(MbtError::NonEmptyTargetFile(self.options.dst_file)); - } else { - let dst_type = self.dst_mbtiles.detect_type(&mut conn).await?; - info!( - "Copying {} ({src_type}) to an existing file {} ({dst_type})", - self.options.src_file.display(), - self.options.dst_file.display() - ); - self.src_mbtiles.attach_to(&mut conn, "sourceDb").await?; - dst_type - }; + } let (on_dupl, sql_cond) = self.get_on_duplicate_sql(dst_type); let (select_from, query_args) = { - let select_from = if let Some(dif_file) = &self.options.diff_with_file { - let dif_file = Mbtiles::new(dif_file)?; - let dif_type = dif_file.open_and_detect_type().await?; - info!( - "Copying only the data not found in {} ({dif_type})", - dif_file.filepath(), - ); - dif_file.attach_to(&mut conn, "diffDb").await?; - Self::get_select_from_with_diff(dst_type, dif_type) + let select_from = if let Some((_, dif_type)) = &dif { + Self::get_select_from_with_diff(dst_type, *dif_type) } else { Self::get_select_from(dst_type, src_type).to_string() }; @@ -198,30 +197,34 @@ impl MbtileCopierInt { // SAFETY: this is safe as long as handle_lock is valid let rusqlite_conn = unsafe { rusqlite::Connection::from_handle(handle) }?; + match dst_type { - Flat => rusqlite_conn.execute( - &format!("INSERT {on_dupl} INTO tiles {select_from} {sql_cond}"), - params_from_iter(query_args), - )?, - FlatWithHash => rusqlite_conn.execute( - &format!("INSERT {on_dupl} INTO tiles_with_hash {select_from} {sql_cond}"), - params_from_iter(query_args), - )?, + Flat => { + let sql = format!("INSERT {on_dupl} INTO tiles {select_from} {sql_cond}"); + debug!("Copying to {dst_type} with {sql} {query_args:?}"); + rusqlite_conn.execute(&sql, params_from_iter(query_args))? + } + FlatWithHash => { + let sql = + format!("INSERT {on_dupl} INTO tiles_with_hash {select_from} {sql_cond}"); + debug!("Copying to {dst_type} with {sql} {query_args:?}"); + rusqlite_conn.execute(&sql, params_from_iter(query_args))? + } Normalized => { - rusqlite_conn.execute( - &format!( - "INSERT {on_dupl} INTO map (zoom_level, tile_column, tile_row, tile_id) + let sql = format!( + "INSERT {on_dupl} INTO map (zoom_level, tile_column, tile_row, tile_id) SELECT zoom_level, tile_column, tile_row, hash as tile_id FROM ({select_from} {sql_cond})" - ), - params_from_iter(&query_args), - )?; - rusqlite_conn.execute( - &format!( - "INSERT OR IGNORE INTO images SELECT tile_data, hash FROM ({select_from})" - ), - params_from_iter(query_args), - )? + ); + debug!("Copying to {dst_type} with {sql} {query_args:?}"); + rusqlite_conn.execute(&sql, params_from_iter(&query_args))?; + let sql = format!( + "INSERT OR IGNORE INTO images (tile_id, tile_data) + SELECT hash as tile_id, tile_data + FROM ({select_from})" + ); + debug!("Copying to {dst_type} with {sql} {query_args:?}"); + rusqlite_conn.execute(&sql, params_from_iter(query_args))? } }; @@ -275,8 +278,6 @@ impl MbtileCopierInt { .await?; query!("VACUUM").execute(&mut *conn).await?; - self.src_mbtiles.attach_to(&mut *conn, "sourceDb").await?; - if src == dst { // DB objects must be created in a specific order: tables, views, triggers, indexes. debug!("Copying DB schema verbatim"); @@ -342,40 +343,49 @@ impl MbtileCopierInt { } fn get_select_from_with_diff(dst_type: MbtType, diff_type: MbtType) -> String { - let (hash_col_sql, new_tiles_with_hash) = if dst_type == Flat { + let (hash_col_sql, diff_tiles) = if dst_type == Flat { ("", "diffDb.tiles") } else { match diff_type { - Flat => (", hex(md5(tile_data)) as hash", "diffDb.tiles"), - FlatWithHash => (", new_tiles_with_hash.tile_hash as hash", "diffDb.tiles_with_hash"), - Normalized => (", new_tiles_with_hash.hash", + Flat => (", hex(md5(diffTiles.tile_data)) as hash", "diffDb.tiles"), + FlatWithHash => (", diffTiles.tile_hash as hash", "diffDb.tiles_with_hash"), + Normalized => (", diffTiles.hash", "(SELECT zoom_level, tile_column, tile_row, tile_data, map.tile_id AS hash FROM diffDb.map JOIN diffDb.images ON diffDb.map.tile_id = diffDb.images.tile_id)"), } }; - format!("SELECT COALESCE(sourceDb.tiles.zoom_level, new_tiles_with_hash.zoom_level) as zoom_level, - COALESCE(sourceDb.tiles.tile_column, new_tiles_with_hash.tile_column) as tile_column, - COALESCE(sourceDb.tiles.tile_row, new_tiles_with_hash.tile_row) as tile_row, - new_tiles_with_hash.tile_data as tile_data + format!( + "SELECT COALESCE(sourceTiles.zoom_level, diffTiles.zoom_level) as zoom_level + , COALESCE(sourceTiles.tile_column, diffTiles.tile_column) as tile_column + , COALESCE(sourceTiles.tile_row, diffTiles.tile_row) as tile_row + , diffTiles.tile_data as tile_data {hash_col_sql} - FROM sourceDb.tiles FULL JOIN {new_tiles_with_hash} AS new_tiles_with_hash - ON sourceDb.tiles.zoom_level = new_tiles_with_hash.zoom_level - AND sourceDb.tiles.tile_column = new_tiles_with_hash.tile_column - AND sourceDb.tiles.tile_row = new_tiles_with_hash.tile_row - WHERE (sourceDb.tiles.tile_data != new_tiles_with_hash.tile_data - OR sourceDb.tiles.tile_data ISNULL - OR new_tiles_with_hash.tile_data ISNULL)") + FROM sourceDb.tiles AS sourceTiles FULL JOIN {diff_tiles} AS diffTiles + ON sourceTiles.zoom_level = diffTiles.zoom_level + AND sourceTiles.tile_column = diffTiles.tile_column + AND sourceTiles.tile_row = diffTiles.tile_row + WHERE (sourceTiles.tile_data != diffTiles.tile_data + OR sourceTiles.tile_data ISNULL + OR diffTiles.tile_data ISNULL)" + ) } fn get_select_from(dst_type: MbtType, src_type: MbtType) -> &'static str { if dst_type == Flat { - "SELECT * FROM sourceDb.tiles WHERE TRUE" + "SELECT zoom_level, tile_column, tile_row, tile_data FROM sourceDb.tiles WHERE TRUE" } else { match src_type { - Flat => "SELECT zoom_level, tile_column, tile_row, tile_data, hex(md5(tile_data)) as hash FROM sourceDb.tiles WHERE TRUE", - FlatWithHash => "SELECT zoom_level, tile_column, tile_row, tile_data, tile_hash AS hash FROM sourceDb.tiles_with_hash WHERE TRUE", - Normalized => "SELECT zoom_level, tile_column, tile_row, tile_data, map.tile_id AS hash FROM sourceDb.map JOIN sourceDb.images ON sourceDb.map.tile_id = sourceDb.images.tile_id WHERE TRUE" + Flat => "SELECT zoom_level, tile_column, tile_row, tile_data, hex(md5(tile_data)) as hash + FROM sourceDb.tiles + WHERE TRUE", + FlatWithHash => "SELECT zoom_level, tile_column, tile_row, tile_data, tile_hash AS hash + FROM sourceDb.tiles_with_hash + WHERE TRUE", + Normalized => "SELECT zoom_level, tile_column, tile_row, tile_data, map.tile_id AS hash + FROM sourceDb.map JOIN sourceDb.images + ON sourceDb.map.tile_id = sourceDb.images.tile_id + WHERE TRUE" } } } diff --git a/martin-mbtiles/src/errors.rs b/martin-mbtiles/src/errors.rs index 17501a5fc..f8b8b14ab 100644 --- a/martin-mbtiles/src/errors.rs +++ b/martin-mbtiles/src/errors.rs @@ -44,7 +44,7 @@ pub enum MbtError { #[error("No tiles found")] NoTilesFound, - #[error("The destination file {0} is non-empty")] + #[error("The destination file {0} is not empty. Some operations like creating a diff file require the destination file to be non-existent or empty.")] NonEmptyTargetFile(PathBuf), #[error("The file {0} does not have the required uniqueness constraint")] diff --git a/martin-mbtiles/src/queries.rs b/martin-mbtiles/src/queries.rs index 8fc539ad3..365038814 100644 --- a/martin-mbtiles/src/queries.rs +++ b/martin-mbtiles/src/queries.rs @@ -3,6 +3,17 @@ use sqlx::{query, Executor as _, SqliteExecutor}; use crate::errors::MbtResult; +/// Returns true if the database is empty (no tables/indexes/...) +pub async fn is_empty_database(conn: &mut T) -> MbtResult +where + for<'e> &'e mut T: SqliteExecutor<'e>, +{ + Ok(query!("SELECT 1 as has_rows FROM sqlite_schema LIMIT 1") + .fetch_optional(&mut *conn) + .await? + .is_none()) +} + pub async fn is_normalized_tables_type(conn: &mut T) -> MbtResult where for<'e> &'e mut T: SqliteExecutor<'e>, diff --git a/martin-mbtiles/tests/mbtiles.rs b/martin-mbtiles/tests/mbtiles.rs index def670d45..554c5d283 100644 --- a/martin-mbtiles/tests/mbtiles.rs +++ b/martin-mbtiles/tests/mbtiles.rs @@ -105,7 +105,7 @@ macro_rules! copy_to { ($function:tt, $src:expr, $dst:tt, $dst_type:expr, $skip_agg:expr) => {{ let func = stringify!($function); let name = stringify!($dst); - let file = format!("file:{func}_{name}?mode=memory&cache=shared"); + let file = format!("file:{func}--{name}?mode=memory&cache=shared"); let (dst, cn_dst) = open(&file).await?; let mut opt = copier(&$src, &dst); opt.skip_agg_tiles_hash = $skip_agg; @@ -120,10 +120,10 @@ macro_rules! copy_to { async fn copy_and_convert() -> MbtResult<()> { let mem = Mbtiles::new(":memory:")?; - let (orig, _cn_orig) = new_source!(test_copy, orig, INSERT_METADATA_V1, INSERT_TILES_V1); - let (flat, _cn_flat, _) = copy_to!(test_copy, orig, flat, Flat); - let (hash, _cn_hash, _) = copy_to!(test_copy, orig, hash, FlatWithHash); - let (norm, _cn_norm, _) = copy_to!(test_copy, orig, norm, Normalized); + let (orig, _cn_orig) = new_source!(cp_conv, orig, INSERT_METADATA_V1, INSERT_TILES_V1); + let (flat, _cn_flat, _) = copy_to!(cp_conv, orig, flat, Flat); + let (hash, _cn_hash, _) = copy_to!(cp_conv, orig, hash, FlatWithHash); + let (norm, _cn_norm, _) = copy_to!(cp_conv, orig, norm, Normalized); for (frm, src) in &[("flat", &flat), ("hash", &hash), ("norm", &norm)] { // Same content, but also will include agg_tiles_hash metadata value @@ -160,43 +160,55 @@ async fn copy_and_convert() -> MbtResult<()> { #[actix_rt::test] async fn diff_and_apply() -> MbtResult<()> { let (orig_v1, _cn_orig_v1) = - new_source!(test_diff, orig_v1, INSERT_METADATA_V1, INSERT_TILES_V1); - let (flat_v1, _cn_flat_v1, _) = copy_hash!(test_diff, orig_v1, flat_v1, Flat); - let (hash_v1, _cn_hash_v1, _) = copy_hash!(test_diff, orig_v1, hash_v1, FlatWithHash); - let (norm_v1, _cn_norm_v1, _) = copy_hash!(test_diff, orig_v1, norm_v1, Normalized); + new_source!(dif_aply, orig_v1, INSERT_METADATA_V1, INSERT_TILES_V1); + let (flat_v1, _cn_flat_v1, _) = copy_hash!(dif_aply, orig_v1, flat_v1, Flat); + let (hash_v1, _cn_hash_v1, _) = copy_hash!(dif_aply, orig_v1, hash_v1, FlatWithHash); + let (norm_v1, _cn_norm_v1, _) = copy_hash!(dif_aply, orig_v1, norm_v1, Normalized); let (orig_v2, _cn_orig_v2) = - new_source!(test_diff, orig_v2, INSERT_METADATA_V2, INSERT_TILES_V2); - let (flat_v2, _cn_flat_v2, dmp_flat_v2) = copy_hash!(test_diff, orig_v2, flat_v2, Flat); - let (hash_v2, _cn_hash_v2, dmp_hash_v2) = copy_hash!(test_diff, orig_v2, hash_v2, FlatWithHash); - let (norm_v2, _cn_norm_v2, dmp_norm_v2) = copy_hash!(test_diff, orig_v2, norm_v2, Normalized); + new_source!(dif_aply, orig_v2, INSERT_METADATA_V2, INSERT_TILES_V2); + let (flat_v2, _cn_flat_v2, dmp_flat_v2) = copy_hash!(dif_aply, orig_v2, flat_v2, Flat); + let (hash_v2, _cn_hash_v2, dmp_hash_v2) = copy_hash!(dif_aply, orig_v2, hash_v2, FlatWithHash); + let (norm_v2, _cn_norm_v2, dmp_norm_v2) = copy_hash!(dif_aply, orig_v2, norm_v2, Normalized); - for (frm, v1, v2, dump_v2) in &[ + let types = &[ ("flat", &flat_v1, &flat_v2, dmp_flat_v2), ("hash", &hash_v1, &hash_v2, dmp_hash_v2), ("norm", &norm_v1, &norm_v2, dmp_norm_v2), - ] { - let (dff, _cn_dff) = open!(test_diff, format!("{frm}-dff")); - let (v2a, mut cn_v2a) = open!(test_diff, format!("{frm}-v2a")); + ]; + + for (frm_type, v1, _, _) in types { + for (to_type, _, v2, dump_v2) in types { + let pair = format!("{frm_type}-{to_type}"); + let (dff, _cn_dff) = open!(dif_aply, format!("{pair}-dff")); + let (v2a, mut cn_v2a) = open!(dif_aply, format!("{pair}-v2a")); + + // Diff v1 with v2, and copy to diff anything that's different (i.e. mathematically: v2-v1) + let mut diff_with = copier(v1, &dff); + diff_with.diff_with_file = Some(path(v2)); + assert_snapshot!("delta", pair, dump(&mut diff_with.run().await?).await?); - // Diff v1 with v2, and copy to diff anything that's different (i.e. mathematically: v2-v1) - let mut diff_with = copier(v1, &dff); - diff_with.diff_with_file = Some(path(v2)); - assert_snapshot!(frm, "diff_v2-v1", dump(&mut diff_with.run().await?).await?); + // Copy v1 -> v2a, and apply dff to v2a + copier(v1, &v2a).run().await?; + apply_diff(path(&v2a), path(&dff)).await?; - // Copy v1 -> v2a, and apply dff to v2a - copier(v1, &v2a).run().await?; - apply_diff(path(&v2a), path(&dff)).await?; + let dump_v2a = dump(&mut cn_v2a).await?; + assert_snapshot!("applied", pair, &dump_v2a); - let dump_v2a = dump(&mut cn_v2a).await?; - assert_snapshot!(frm, "applied-diff", &dump_v2a); + let expected_dump = if frm_type != to_type { + eprintln!("TODO: implement convert copying {frm_type} -> {to_type}"); + continue; + } else if frm_type == &"norm" { + eprintln!("FIXME: norm->norm diff is not working yet"); + continue; + } else { + dump_v2 + }; - // FIXME!!! - if frm != &"norm" { pretty_assertions::assert_eq!( &dump_v2a, - dump_v2, - "v2a should be identical to v2 (type = {frm})" + expected_dump, + "v2a should be identical to v2 (type {frm_type} -> {to_type})" ); } } @@ -261,7 +273,7 @@ async fn dump(conn: &mut SqliteConnection) -> MbtResult> { .map(|v| format!(r#""{v}""#)), "BLOB" => row .get::>, _>(idx) - .map(|v| format!(r#""{}""#, from_utf8(&v).unwrap())), + .map(|v| format!("blob({})", from_utf8(&v).unwrap())), _ => panic!("Unknown column type: {typ}"), }) .unwrap_or("NULL".to_string()) diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-cp-skip-agg.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-cp-skip-agg.snap index 38b7767bd..7939eb641 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-cp-skip-agg.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-cp-skip-agg.snap @@ -26,9 +26,9 @@ CREATE TABLE tiles ( tile_data blob, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same" )', - '( 1, 0, 1, "edit-v1" )', - '( 1, 1, 1, "remove" )', + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v1) )', + '( 1, 1, 1, blob(remove) )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-cp.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-cp.snap index 897d9bd64..023676abb 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-cp.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-cp.snap @@ -27,9 +27,9 @@ CREATE TABLE tiles ( tile_data blob, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same" )', - '( 1, 0, 1, "edit-v1" )', - '( 1, 1, 1, "remove" )', + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v1) )', + '( 1, 1, 1, blob(remove) )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-to-flat.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-to-flat.snap index 897d9bd64..023676abb 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-to-flat.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-to-flat.snap @@ -27,9 +27,9 @@ CREATE TABLE tiles ( tile_data blob, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same" )', - '( 1, 0, 1, "edit-v1" )', - '( 1, 1, 1, "remove" )', + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v1) )', + '( 1, 1, 1, blob(remove) )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-to-hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-to-hash.snap index cfaeac66e..27034bbc7 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-to-hash.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-to-hash.snap @@ -28,9 +28,9 @@ CREATE TABLE tiles_with_hash ( tile_hash text, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same", "51037A4A37730F52C8732586D3AAA316" )', - '( 1, 0, 1, "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( 1, 1, 1, "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', + '( 1, 0, 0, blob(same), "51037A4A37730F52C8732586D3AAA316" )', + '( 1, 0, 1, blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( 1, 1, 1, blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-to-norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-to-norm.snap index 7d3ed414e..6a1c96174 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-to-norm.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat-to-norm.snap @@ -10,9 +10,9 @@ CREATE TABLE images ( tile_data blob, tile_id text NOT NULL PRIMARY KEY)''' values = [ - '( "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', - '( "same", "51037A4A37730F52C8732586D3AAA316" )', + '( blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', + '( blob(same), "51037A4A37730F52C8732586D3AAA316" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat.snap index 38b7767bd..7939eb641 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@flat.snap @@ -26,9 +26,9 @@ CREATE TABLE tiles ( tile_data blob, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same" )', - '( 1, 0, 1, "edit-v1" )', - '( 1, 1, 1, "remove" )', + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v1) )', + '( 1, 1, 1, blob(remove) )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-cp-skip-agg.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-cp-skip-agg.snap index 92ddb098d..c4eb59a16 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-cp-skip-agg.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-cp-skip-agg.snap @@ -27,9 +27,9 @@ CREATE TABLE tiles_with_hash ( tile_hash text, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same", "51037A4A37730F52C8732586D3AAA316" )', - '( 1, 0, 1, "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( 1, 1, 1, "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', + '( 1, 0, 0, blob(same), "51037A4A37730F52C8732586D3AAA316" )', + '( 1, 0, 1, blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( 1, 1, 1, blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-cp.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-cp.snap index cfaeac66e..27034bbc7 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-cp.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-cp.snap @@ -28,9 +28,9 @@ CREATE TABLE tiles_with_hash ( tile_hash text, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same", "51037A4A37730F52C8732586D3AAA316" )', - '( 1, 0, 1, "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( 1, 1, 1, "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', + '( 1, 0, 0, blob(same), "51037A4A37730F52C8732586D3AAA316" )', + '( 1, 0, 1, blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( 1, 1, 1, blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-to-flat.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-to-flat.snap index 897d9bd64..023676abb 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-to-flat.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-to-flat.snap @@ -27,9 +27,9 @@ CREATE TABLE tiles ( tile_data blob, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same" )', - '( 1, 0, 1, "edit-v1" )', - '( 1, 1, 1, "remove" )', + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v1) )', + '( 1, 1, 1, blob(remove) )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-to-hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-to-hash.snap index cfaeac66e..27034bbc7 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-to-hash.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-to-hash.snap @@ -28,9 +28,9 @@ CREATE TABLE tiles_with_hash ( tile_hash text, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same", "51037A4A37730F52C8732586D3AAA316" )', - '( 1, 0, 1, "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( 1, 1, 1, "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', + '( 1, 0, 0, blob(same), "51037A4A37730F52C8732586D3AAA316" )', + '( 1, 0, 1, blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( 1, 1, 1, blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-to-norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-to-norm.snap index 7d3ed414e..6a1c96174 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-to-norm.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash-to-norm.snap @@ -10,9 +10,9 @@ CREATE TABLE images ( tile_data blob, tile_id text NOT NULL PRIMARY KEY)''' values = [ - '( "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', - '( "same", "51037A4A37730F52C8732586D3AAA316" )', + '( blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', + '( blob(same), "51037A4A37730F52C8732586D3AAA316" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash.snap index 92ddb098d..c4eb59a16 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@hash.snap @@ -27,9 +27,9 @@ CREATE TABLE tiles_with_hash ( tile_hash text, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same", "51037A4A37730F52C8732586D3AAA316" )', - '( 1, 0, 1, "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( 1, 1, 1, "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', + '( 1, 0, 0, blob(same), "51037A4A37730F52C8732586D3AAA316" )', + '( 1, 0, 1, blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( 1, 1, 1, blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-cp-skip-agg.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-cp-skip-agg.snap index 3437bfb67..f8f39f0aa 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-cp-skip-agg.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-cp-skip-agg.snap @@ -10,9 +10,9 @@ CREATE TABLE images ( tile_data blob, tile_id text NOT NULL PRIMARY KEY)''' values = [ - '( "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', - '( "same", "51037A4A37730F52C8732586D3AAA316" )', + '( blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', + '( blob(same), "51037A4A37730F52C8732586D3AAA316" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-cp.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-cp.snap index 7d3ed414e..6a1c96174 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-cp.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-cp.snap @@ -10,9 +10,9 @@ CREATE TABLE images ( tile_data blob, tile_id text NOT NULL PRIMARY KEY)''' values = [ - '( "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', - '( "same", "51037A4A37730F52C8732586D3AAA316" )', + '( blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', + '( blob(same), "51037A4A37730F52C8732586D3AAA316" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-to-flat.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-to-flat.snap index 897d9bd64..023676abb 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-to-flat.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-to-flat.snap @@ -27,9 +27,9 @@ CREATE TABLE tiles ( tile_data blob, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same" )', - '( 1, 0, 1, "edit-v1" )', - '( 1, 1, 1, "remove" )', + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v1) )', + '( 1, 1, 1, blob(remove) )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-to-hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-to-hash.snap index cfaeac66e..27034bbc7 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-to-hash.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-to-hash.snap @@ -28,9 +28,9 @@ CREATE TABLE tiles_with_hash ( tile_hash text, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same", "51037A4A37730F52C8732586D3AAA316" )', - '( 1, 0, 1, "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( 1, 1, 1, "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', + '( 1, 0, 0, blob(same), "51037A4A37730F52C8732586D3AAA316" )', + '( 1, 0, 1, blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( 1, 1, 1, blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-to-norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-to-norm.snap index 7d3ed414e..6a1c96174 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-to-norm.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm-to-norm.snap @@ -10,9 +10,9 @@ CREATE TABLE images ( tile_data blob, tile_id text NOT NULL PRIMARY KEY)''' values = [ - '( "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', - '( "same", "51037A4A37730F52C8732586D3AAA316" )', + '( blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', + '( blob(same), "51037A4A37730F52C8732586D3AAA316" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm.snap index 3437bfb67..f8f39f0aa 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@norm.snap @@ -10,9 +10,9 @@ CREATE TABLE images ( tile_data blob, tile_id text NOT NULL PRIMARY KEY)''' values = [ - '( "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', - '( "same", "51037A4A37730F52C8732586D3AAA316" )', + '( blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', + '( blob(same), "51037A4A37730F52C8732586D3AAA316" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@orig.snap b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@orig.snap index 38b7767bd..7939eb641 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@orig.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__copy_and_convert@orig.snap @@ -26,9 +26,9 @@ CREATE TABLE tiles ( tile_data blob, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same" )', - '( 1, 0, 1, "edit-v1" )', - '( 1, 1, 1, "remove" )', + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v1) )', + '( 1, 1, 1, blob(remove) )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat-applied-diff.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-flat-flat.snap similarity index 88% rename from martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat-applied-diff.snap rename to martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-flat-flat.snap index 08a28423a..08113d6f1 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat-applied-diff.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-flat-flat.snap @@ -27,9 +27,9 @@ CREATE TABLE tiles ( tile_data blob, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same" )', - '( 1, 0, 1, "edit-v2" )', - '( 1, 1, 0, "new" )', + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v2) )', + '( 1, 1, 0, blob(new) )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-flat-hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-flat-hash.snap new file mode 100644 index 000000000..08113d6f1 --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-flat-hash.snap @@ -0,0 +1,41 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: result +--- +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "4CB1879C4A84910F25B9272B6E5B6E7C" )', + '( "edit", "value - v2" )', + '( "new", "value - new" )', + '( "same", "value - same" )', +] + +[[]] +type = 'table' +tbl_name = 'tiles' +sql = ''' +CREATE TABLE tiles ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_data blob, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v2) )', + '( 1, 1, 0, blob(new) )', +] + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'index' +tbl_name = 'tiles' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-flat-norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-flat-norm.snap new file mode 100644 index 000000000..08113d6f1 --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-flat-norm.snap @@ -0,0 +1,41 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: result +--- +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "4CB1879C4A84910F25B9272B6E5B6E7C" )', + '( "edit", "value - v2" )', + '( "new", "value - new" )', + '( "same", "value - same" )', +] + +[[]] +type = 'table' +tbl_name = 'tiles' +sql = ''' +CREATE TABLE tiles ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_data blob, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v2) )', + '( 1, 1, 0, blob(new) )', +] + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'index' +tbl_name = 'tiles' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash-applied-diff.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-hash-flat.snap similarity index 83% rename from martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash-applied-diff.snap rename to martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-hash-flat.snap index dc624f498..990cd1c51 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash-applied-diff.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-hash-flat.snap @@ -28,9 +28,9 @@ CREATE TABLE tiles_with_hash ( tile_hash text, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same", "51037A4A37730F52C8732586D3AAA316" )', - '( 1, 0, 1, "edit-v2", "FF76830FF90D79BB335884F256031731" )', - '( 1, 1, 0, "new", "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( 1, 0, 0, blob(same), "51037A4A37730F52C8732586D3AAA316" )', + '( 1, 0, 1, blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( 1, 1, 0, blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-hash-hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-hash-hash.snap new file mode 100644 index 000000000..990cd1c51 --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-hash-hash.snap @@ -0,0 +1,49 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: result +--- +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "4CB1879C4A84910F25B9272B6E5B6E7C" )', + '( "edit", "value - v2" )', + '( "new", "value - new" )', + '( "same", "value - same" )', +] + +[[]] +type = 'table' +tbl_name = 'tiles_with_hash' +sql = ''' +CREATE TABLE tiles_with_hash ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_data blob, + tile_hash text, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 1, 0, 0, blob(same), "51037A4A37730F52C8732586D3AAA316" )', + '( 1, 0, 1, blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( 1, 1, 0, blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', +] + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'index' +tbl_name = 'tiles_with_hash' + +[[]] +type = 'view' +tbl_name = 'tiles' +sql = ''' +CREATE VIEW tiles AS + SELECT zoom_level, tile_column, tile_row, tile_data FROM tiles_with_hash''' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-hash-norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-hash-norm.snap new file mode 100644 index 000000000..990cd1c51 --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-hash-norm.snap @@ -0,0 +1,49 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: result +--- +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "4CB1879C4A84910F25B9272B6E5B6E7C" )', + '( "edit", "value - v2" )', + '( "new", "value - new" )', + '( "same", "value - same" )', +] + +[[]] +type = 'table' +tbl_name = 'tiles_with_hash' +sql = ''' +CREATE TABLE tiles_with_hash ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_data blob, + tile_hash text, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 1, 0, 0, blob(same), "51037A4A37730F52C8732586D3AAA316" )', + '( 1, 0, 1, blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( 1, 1, 0, blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', +] + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'index' +tbl_name = 'tiles_with_hash' + +[[]] +type = 'view' +tbl_name = 'tiles' +sql = ''' +CREATE VIEW tiles AS + SELECT zoom_level, tile_column, tile_row, tile_data FROM tiles_with_hash''' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm-applied-diff.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-norm-flat.snap similarity index 86% rename from martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm-applied-diff.snap rename to martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-norm-flat.snap index 4c0d3c222..08ea378da 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm-applied-diff.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-norm-flat.snap @@ -10,11 +10,11 @@ CREATE TABLE images ( tile_data blob, tile_id text NOT NULL PRIMARY KEY)''' values = [ - '( "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( "edit-v2", "FF76830FF90D79BB335884F256031731" )', - '( "new", "22AF645D1859CB5CA6DA0C484F1F37EA" )', - '( "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', - '( "same", "51037A4A37730F52C8732586D3AAA316" )', + '( blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', + '( blob(same), "51037A4A37730F52C8732586D3AAA316" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-norm-hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-norm-hash.snap new file mode 100644 index 000000000..08ea378da --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-norm-hash.snap @@ -0,0 +1,86 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: result +--- +[[]] +type = 'table' +tbl_name = 'images' +sql = ''' +CREATE TABLE images ( + tile_data blob, + tile_id text NOT NULL PRIMARY KEY)''' +values = [ + '( blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', + '( blob(same), "51037A4A37730F52C8732586D3AAA316" )', +] + +[[]] +type = 'table' +tbl_name = 'map' +sql = ''' +CREATE TABLE map ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_id text, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 1, 0, 0, "51037A4A37730F52C8732586D3AAA316" )', + '( 1, 0, 1, "FF76830FF90D79BB335884F256031731" )', + '( 1, 1, 0, "22AF645D1859CB5CA6DA0C484F1F37EA" )', +] + +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "4CB1879C4A84910F25B9272B6E5B6E7C" )', + '( "edit", "value - v2" )', + '( "new", "value - new" )', + '( "same", "value - same" )', +] + +[[]] +type = 'index' +tbl_name = 'images' + +[[]] +type = 'index' +tbl_name = 'map' + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'view' +tbl_name = 'tiles' +sql = ''' +CREATE VIEW tiles AS + SELECT map.zoom_level AS zoom_level, + map.tile_column AS tile_column, + map.tile_row AS tile_row, + images.tile_data AS tile_data + FROM map + JOIN images ON images.tile_id = map.tile_id''' + +[[]] +type = 'view' +tbl_name = 'tiles_with_hash' +sql = ''' +CREATE VIEW tiles_with_hash AS + SELECT + map.zoom_level AS zoom_level, + map.tile_column AS tile_column, + map.tile_row AS tile_row, + images.tile_data AS tile_data, + images.tile_id AS tile_hash + FROM map + JOIN images ON images.tile_id = map.tile_id''' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-norm-norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-norm-norm.snap new file mode 100644 index 000000000..08ea378da --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@applied-norm-norm.snap @@ -0,0 +1,86 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: result +--- +[[]] +type = 'table' +tbl_name = 'images' +sql = ''' +CREATE TABLE images ( + tile_data blob, + tile_id text NOT NULL PRIMARY KEY)''' +values = [ + '( blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', + '( blob(same), "51037A4A37730F52C8732586D3AAA316" )', +] + +[[]] +type = 'table' +tbl_name = 'map' +sql = ''' +CREATE TABLE map ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_id text, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 1, 0, 0, "51037A4A37730F52C8732586D3AAA316" )', + '( 1, 0, 1, "FF76830FF90D79BB335884F256031731" )', + '( 1, 1, 0, "22AF645D1859CB5CA6DA0C484F1F37EA" )', +] + +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "4CB1879C4A84910F25B9272B6E5B6E7C" )', + '( "edit", "value - v2" )', + '( "new", "value - new" )', + '( "same", "value - same" )', +] + +[[]] +type = 'index' +tbl_name = 'images' + +[[]] +type = 'index' +tbl_name = 'map' + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'view' +tbl_name = 'tiles' +sql = ''' +CREATE VIEW tiles AS + SELECT map.zoom_level AS zoom_level, + map.tile_column AS tile_column, + map.tile_row AS tile_row, + images.tile_data AS tile_data + FROM map + JOIN images ON images.tile_id = map.tile_id''' + +[[]] +type = 'view' +tbl_name = 'tiles_with_hash' +sql = ''' +CREATE VIEW tiles_with_hash AS + SELECT + map.zoom_level AS zoom_level, + map.tile_column AS tile_column, + map.tile_row AS tile_row, + images.tile_data AS tile_data, + images.tile_id AS tile_hash + FROM map + JOIN images ON images.tile_id = map.tile_id''' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat-diff_v2-v1.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-flat-flat.snap similarity index 92% rename from martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat-diff_v2-v1.snap rename to martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-flat-flat.snap index 905c82dac..02e25a660 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat-diff_v2-v1.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-flat-flat.snap @@ -28,8 +28,8 @@ CREATE TABLE tiles ( tile_data blob, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 1, "edit-v2" )', - '( 1, 1, 0, "new" )', + '( 1, 0, 1, blob(edit-v2) )', + '( 1, 1, 0, blob(new) )', '( 1, 1, 1, NULL )', ] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-flat-hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-flat-hash.snap new file mode 100644 index 000000000..02e25a660 --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-flat-hash.snap @@ -0,0 +1,42 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: result +--- +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "B69186152AEB4709BB5E51F26122506D" )', + '( "agg_tiles_hash_after_apply", "4CB1879C4A84910F25B9272B6E5B6E7C" )', + '( "edit", "value - v2" )', + '( "new", "value - new" )', + '( "remove", NULL )', +] + +[[]] +type = 'table' +tbl_name = 'tiles' +sql = ''' +CREATE TABLE tiles ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_data blob, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 1, 0, 1, blob(edit-v2) )', + '( 1, 1, 0, blob(new) )', + '( 1, 1, 1, NULL )', +] + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'index' +tbl_name = 'tiles' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-flat-norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-flat-norm.snap new file mode 100644 index 000000000..02e25a660 --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-flat-norm.snap @@ -0,0 +1,42 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: result +--- +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "B69186152AEB4709BB5E51F26122506D" )', + '( "agg_tiles_hash_after_apply", "4CB1879C4A84910F25B9272B6E5B6E7C" )', + '( "edit", "value - v2" )', + '( "new", "value - new" )', + '( "remove", NULL )', +] + +[[]] +type = 'table' +tbl_name = 'tiles' +sql = ''' +CREATE TABLE tiles ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_data blob, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 1, 0, 1, blob(edit-v2) )', + '( 1, 1, 0, blob(new) )', + '( 1, 1, 1, NULL )', +] + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'index' +tbl_name = 'tiles' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-hash-flat.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-hash-flat.snap new file mode 100644 index 000000000..32f6399b1 --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-hash-flat.snap @@ -0,0 +1,50 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: result +--- +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "B69186152AEB4709BB5E51F26122506D" )', + '( "agg_tiles_hash_after_apply", "4CB1879C4A84910F25B9272B6E5B6E7C" )', + '( "edit", "value - v2" )', + '( "new", "value - new" )', + '( "remove", NULL )', +] + +[[]] +type = 'table' +tbl_name = 'tiles_with_hash' +sql = ''' +CREATE TABLE tiles_with_hash ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_data blob, + tile_hash text, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 1, 0, 1, blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( 1, 1, 0, blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( 1, 1, 1, NULL, "" )', +] + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'index' +tbl_name = 'tiles_with_hash' + +[[]] +type = 'view' +tbl_name = 'tiles' +sql = ''' +CREATE VIEW tiles AS + SELECT zoom_level, tile_column, tile_row, tile_data FROM tiles_with_hash''' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash-diff_v2-v1.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-hash-hash.snap similarity index 89% rename from martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash-diff_v2-v1.snap rename to martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-hash-hash.snap index 7ce4fbd4b..5e823f50a 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash-diff_v2-v1.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-hash-hash.snap @@ -29,8 +29,8 @@ CREATE TABLE tiles_with_hash ( tile_hash text, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 1, "edit-v2", "FF76830FF90D79BB335884F256031731" )', - '( 1, 1, 0, "new", "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( 1, 0, 1, blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( 1, 1, 0, blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', '( 1, 1, 1, NULL, NULL )', ] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-hash-norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-hash-norm.snap new file mode 100644 index 000000000..5e823f50a --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-hash-norm.snap @@ -0,0 +1,50 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: result +--- +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "B69186152AEB4709BB5E51F26122506D" )', + '( "agg_tiles_hash_after_apply", "4CB1879C4A84910F25B9272B6E5B6E7C" )', + '( "edit", "value - v2" )', + '( "new", "value - new" )', + '( "remove", NULL )', +] + +[[]] +type = 'table' +tbl_name = 'tiles_with_hash' +sql = ''' +CREATE TABLE tiles_with_hash ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_data blob, + tile_hash text, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 1, 0, 1, blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( 1, 1, 0, blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( 1, 1, 1, NULL, NULL )', +] + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'index' +tbl_name = 'tiles_with_hash' + +[[]] +type = 'view' +tbl_name = 'tiles' +sql = ''' +CREATE VIEW tiles AS + SELECT zoom_level, tile_column, tile_row, tile_data FROM tiles_with_hash''' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-norm-flat.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-norm-flat.snap new file mode 100644 index 000000000..31f1fecee --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-norm-flat.snap @@ -0,0 +1,85 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: result +--- +[[]] +type = 'table' +tbl_name = 'images' +sql = ''' +CREATE TABLE images ( + tile_data blob, + tile_id text NOT NULL PRIMARY KEY)''' +values = [ + '( NULL, "" )', + '( blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', +] + +[[]] +type = 'table' +tbl_name = 'map' +sql = ''' +CREATE TABLE map ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_id text, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 1, 0, 1, "FF76830FF90D79BB335884F256031731" )', + '( 1, 1, 0, "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( 1, 1, 1, "" )', +] + +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "B69186152AEB4709BB5E51F26122506D" )', + '( "agg_tiles_hash_after_apply", "4CB1879C4A84910F25B9272B6E5B6E7C" )', + '( "edit", "value - v2" )', + '( "new", "value - new" )', + '( "remove", NULL )', +] + +[[]] +type = 'index' +tbl_name = 'images' + +[[]] +type = 'index' +tbl_name = 'map' + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'view' +tbl_name = 'tiles' +sql = ''' +CREATE VIEW tiles AS + SELECT map.zoom_level AS zoom_level, + map.tile_column AS tile_column, + map.tile_row AS tile_row, + images.tile_data AS tile_data + FROM map + JOIN images ON images.tile_id = map.tile_id''' + +[[]] +type = 'view' +tbl_name = 'tiles_with_hash' +sql = ''' +CREATE VIEW tiles_with_hash AS + SELECT + map.zoom_level AS zoom_level, + map.tile_column AS tile_column, + map.tile_row AS tile_row, + images.tile_data AS tile_data, + images.tile_id AS tile_hash + FROM map + JOIN images ON images.tile_id = map.tile_id''' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm-diff_v2-v1.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-norm-hash.snap similarity index 94% rename from martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm-diff_v2-v1.snap rename to martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-norm-hash.snap index c2b60362e..876d367ea 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm-diff_v2-v1.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-norm-hash.snap @@ -10,8 +10,8 @@ CREATE TABLE images ( tile_data blob, tile_id text NOT NULL PRIMARY KEY)''' values = [ - '( "edit-v2", "FF76830FF90D79BB335884F256031731" )', - '( "new", "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-norm-norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-norm-norm.snap new file mode 100644 index 000000000..876d367ea --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@delta-norm-norm.snap @@ -0,0 +1,84 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: result +--- +[[]] +type = 'table' +tbl_name = 'images' +sql = ''' +CREATE TABLE images ( + tile_data blob, + tile_id text NOT NULL PRIMARY KEY)''' +values = [ + '( blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', +] + +[[]] +type = 'table' +tbl_name = 'map' +sql = ''' +CREATE TABLE map ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_id text, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 1, 0, 1, "FF76830FF90D79BB335884F256031731" )', + '( 1, 1, 0, "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( 1, 1, 1, NULL )', +] + +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "5E37A28AFE35EA0BFF6703CB3ECE8B2F" )', + '( "agg_tiles_hash_after_apply", "4CB1879C4A84910F25B9272B6E5B6E7C" )', + '( "edit", "value - v2" )', + '( "new", "value - new" )', + '( "remove", NULL )', +] + +[[]] +type = 'index' +tbl_name = 'images' + +[[]] +type = 'index' +tbl_name = 'map' + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'view' +tbl_name = 'tiles' +sql = ''' +CREATE VIEW tiles AS + SELECT map.zoom_level AS zoom_level, + map.tile_column AS tile_column, + map.tile_row AS tile_row, + images.tile_data AS tile_data + FROM map + JOIN images ON images.tile_id = map.tile_id''' + +[[]] +type = 'view' +tbl_name = 'tiles_with_hash' +sql = ''' +CREATE VIEW tiles_with_hash AS + SELECT + map.zoom_level AS zoom_level, + map.tile_column AS tile_column, + map.tile_row AS tile_row, + images.tile_data AS tile_data, + images.tile_id AS tile_hash + FROM map + JOIN images ON images.tile_id = map.tile_id''' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat_v1.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat_v1.snap index 897d9bd64..023676abb 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat_v1.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat_v1.snap @@ -27,9 +27,9 @@ CREATE TABLE tiles ( tile_data blob, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same" )', - '( 1, 0, 1, "edit-v1" )', - '( 1, 1, 1, "remove" )', + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v1) )', + '( 1, 1, 1, blob(remove) )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat_v2.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat_v2.snap index 08a28423a..08113d6f1 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat_v2.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@flat_v2.snap @@ -27,9 +27,9 @@ CREATE TABLE tiles ( tile_data blob, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same" )', - '( 1, 0, 1, "edit-v2" )', - '( 1, 1, 0, "new" )', + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v2) )', + '( 1, 1, 0, blob(new) )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash_v1.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash_v1.snap index cfaeac66e..27034bbc7 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash_v1.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash_v1.snap @@ -28,9 +28,9 @@ CREATE TABLE tiles_with_hash ( tile_hash text, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same", "51037A4A37730F52C8732586D3AAA316" )', - '( 1, 0, 1, "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( 1, 1, 1, "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', + '( 1, 0, 0, blob(same), "51037A4A37730F52C8732586D3AAA316" )', + '( 1, 0, 1, blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( 1, 1, 1, blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash_v2.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash_v2.snap index dc624f498..990cd1c51 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash_v2.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@hash_v2.snap @@ -28,9 +28,9 @@ CREATE TABLE tiles_with_hash ( tile_hash text, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same", "51037A4A37730F52C8732586D3AAA316" )', - '( 1, 0, 1, "edit-v2", "FF76830FF90D79BB335884F256031731" )', - '( 1, 1, 0, "new", "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( 1, 0, 0, blob(same), "51037A4A37730F52C8732586D3AAA316" )', + '( 1, 0, 1, blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( 1, 1, 0, blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm_v1.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm_v1.snap index 7d3ed414e..6a1c96174 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm_v1.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm_v1.snap @@ -10,9 +10,9 @@ CREATE TABLE images ( tile_data blob, tile_id text NOT NULL PRIMARY KEY)''' values = [ - '( "edit-v1", "EFE0AE5FD114DE99855BC2838BE97E1D" )', - '( "remove", "0F6969D7052DA9261E31DDB6E88C136E" )', - '( "same", "51037A4A37730F52C8732586D3AAA316" )', + '( blob(edit-v1), "EFE0AE5FD114DE99855BC2838BE97E1D" )', + '( blob(remove), "0F6969D7052DA9261E31DDB6E88C136E" )', + '( blob(same), "51037A4A37730F52C8732586D3AAA316" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm_v2.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm_v2.snap index 5a067a3ac..e7714100e 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm_v2.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@norm_v2.snap @@ -10,9 +10,9 @@ CREATE TABLE images ( tile_data blob, tile_id text NOT NULL PRIMARY KEY)''' values = [ - '( "edit-v2", "FF76830FF90D79BB335884F256031731" )', - '( "new", "22AF645D1859CB5CA6DA0C484F1F37EA" )', - '( "same", "51037A4A37730F52C8732586D3AAA316" )', + '( blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( blob(same), "51037A4A37730F52C8732586D3AAA316" )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@orig_v1.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@orig_v1.snap index 38b7767bd..7939eb641 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@orig_v1.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@orig_v1.snap @@ -26,9 +26,9 @@ CREATE TABLE tiles ( tile_data blob, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same" )', - '( 1, 0, 1, "edit-v1" )', - '( 1, 1, 1, "remove" )', + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v1) )', + '( 1, 1, 1, blob(remove) )', ] [[]] diff --git a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@orig_v2.snap b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@orig_v2.snap index 80434e261..959b4beb8 100644 --- a/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@orig_v2.snap +++ b/martin-mbtiles/tests/snapshots/mbtiles__diff_and_apply@orig_v2.snap @@ -26,9 +26,9 @@ CREATE TABLE tiles ( tile_data blob, PRIMARY KEY(zoom_level, tile_column, tile_row))''' values = [ - '( 1, 0, 0, "same" )', - '( 1, 0, 1, "edit-v2" )', - '( 1, 1, 0, "new" )', + '( 1, 0, 0, blob(same) )', + '( 1, 0, 1, blob(edit-v2) )', + '( 1, 1, 0, blob(new) )', ] [[]]