forge
Explore
Log in

Don't you dare go Hollow

the old formatter trimmed trailing zeros too: a nanosecond ending in zero lost its ninth digit, so a legacy stamp could also sit at twenty-nine characters ('…T18:21:00.34746478Z') — and Z outranks the digits as much as it outranks the dot, so the trimmed shape compares against the pinned one exactly as wrongly as the whole-second shape did; the boot pass now pads both short spellings to the nine-digit shape (trailing zeros carry no information: growing .34746478 to .347464780 moves no instant), and the canonicalize test plants the trimmed spelling beside the whole-second one and asserts the digits it named are the digits it kept

Browse files at this commit

dd98d9a353ac0e9d8abd1e112b27fda6cbd4a4d1Ahmet Kaan GümüşParent: 6f9e149
crates/iz-core/src/store/turso_store.rsmodified+43 -14
@@ -191,13 +191,15 @@ impl TursoStore {
191 }191 }
192 192
193 /// Stamps written before [`stamp`] pinned its format may sit in any TEXT193 /// Stamps written before [`stamp`] pinned its format may sit in any TEXT
194- /// stamp column as whole seconds (`…T08:30:00Z`, twenty characters) — and194+ /// stamp column in either of the old formatter's two short spellings —
195- /// because `Z` outranks `.` in a string compare, such a row hid from195+ /// whole seconds (`…T08:30:00Z`, twenty characters) or a subsecond with
196- /// `claim_sends_owed` for the whole of the first second it was due. Like196+ /// its trailing zeros trimmed (`…T18:21:00.34746478Z`, twenty-nine) —
197- /// the password-sealing pass above, this is a data repair no schema197+ /// and because `Z` outranks `.` and every digit in a string compare,
198- /// migration can express, run once per boot and idempotent by its own198+ /// both hid from `claim_sends_owed` for the whole of the instant they
199- /// WHERE clause: a twenty-character stamp of the whole-second shape is199+ /// name. Like the password-sealing pass above, this is a data repair no
200- /// the only thing it matches, and after one boot none are left to match.200+ /// schema migration can express, run once per boot and idempotent by its
201+ /// own WHERE clauses: they match only the two short shapes, and after
202+ /// one boot neither is left to match.
201 /// The inventory is the live schema's stamp columns, table by table out203 /// The inventory is the live schema's stamp columns, table by table out
202 /// of `migrations/0001` through `0006`: `workspace` (created_at,204 /// of `migrations/0001` through `0006`: `workspace` (created_at,
203 /// smtp_test_at, smtp_check_at), `user` (created_at, last_signed_in_at),205 /// smtp_test_at, smtp_check_at), `user` (created_at, last_signed_in_at),
@@ -240,13 +242,41 @@ impl TursoStore {
240 let conn = self.conn.lock().await;242 let conn = self.conn.lock().await;
241 let mut changed = 0usize;243 let mut changed = 0usize;
242 for (table, column) in STAMP_COLUMNS {244 for (table, column) in STAMP_COLUMNS {
245+ // Two legacy shapes, both from the `time` crate's Rfc3339
246+ // formatter, which spells an instant as short as it can: a zero
247+ // subsecond is left out entirely (twenty characters), and a
248+ // nonzero one has its trailing zeros trimmed — a nanosecond
249+ // ending in zero loses a digit, so the same formatter wrote
250+ // eight digits where the pinned shape writes nine. Both spell
251+ // the instant faithfully, and both still compare wrong as text
252+ // against the pinned shape: `Z` outranks every digit, so a
253+ // shorter fraction sorts after the same instant written in
254+ // full. The repair is padding, never re-derivation — trailing
255+ // zeros carry no information, so growing `.34746478` to
256+ // `.347464780` moves no instant and breaks no reader.
243 let n = conn257 let n = conn
244 .execute(258 .execute(
245 &format!(259 &format!(
246- "UPDATE {table} SET {column} = substr({column}, 1, 19) \260+ "UPDATE {table} \
247- || '.000000000Z' \261+ SET {column} = substr({column}, 1, 19) || '.000000000Z' \
248 WHERE {column} IS NOT NULL AND length({column}) = 20 \262 WHERE {column} IS NOT NULL AND length({column}) = 20 \
249- AND {column} LIKE '____-__-__T__:__:__Z'"263+ AND {column} LIKE '____-__-__T__:__:__Z'",
264+ ),
265+ (),
266+ )
267+ .await
268+ .map_err(backend)?;
269+ changed += n as usize;
270+ let n = conn
271+ .execute(
272+ &format!(
273+ "UPDATE {table} \
274+ SET {column} = substr({column}, 1, 20) \
275+ || substr(replace(substr({column}, 21), 'Z', '') || '000000000', 1, 9) \
276+ || 'Z' \
277+ WHERE {column} IS NOT NULL AND length({column}) BETWEEN 21 AND 29 \
278+ AND {column} LIKE '____-__-__T__:__:__.%' \
279+ AND {column} LIKE '%Z'",
250 ),280 ),
251 (),281 (),
252 )282 )
@@ -257,7 +287,7 @@ impl TursoStore {
257 // Spoken only when something actually moved: a boot log that287 // Spoken only when something actually moved: a boot log that
258 // reports every quiet pass trains the reader to skip it.288 // reports every quiet pass trains the reader to skip it.
259 if changed > 0 {289 if changed > 0 {
260- println!("iz store canonicalized {changed} legacy whole-second stamps");290+ println!("iz store canonicalized {changed} legacy stamps to the pinned shape");
261 }291 }
262 Ok(())292 Ok(())
263 }293 }
@@ -1176,9 +1206,8 @@ const DAY: &[BorrowedFormatItem] = format_description!("[year]-[month]-[day]");
1176 /// Why the width is pinned: see [`stamp`] — the queue compares stamps as1206 /// Why the width is pinned: see [`stamp`] — the queue compares stamps as
1177 /// text, and text only compares like time when every stamp is the same1207 /// text, and text only compares like time when every stamp is the same
1178 /// shape. [`parse_stamp`] reads this and the shorter legacy width alike.1208 /// shape. [`parse_stamp`] reads this and the shorter legacy width alike.
1179-const STAMP: &[BorrowedFormatItem] = format_description!(1209+const STAMP: &[BorrowedFormatItem] =
1180- "[year]-[month]-[day]T[hour]:[minute]:[second].[subsecond digits:9]Z"1210+ format_description!("[year]-[month]-[day]T[hour]:[minute]:[second].[subsecond digits:9]Z");
1181-);
1182 1211
1183 fn day_text(day: Date) -> Result<String> {1212 fn day_text(day: Date) -> Result<String> {
1184 day.format(&DAY)1213 day.format(&DAY)
crates/iz-core/tests/store.rsmodified+80 -27
@@ -7466,7 +7466,11 @@ async fn a_whole_second_stamp_is_written_with_nine_zero_digits() {
7466 /// rewrites every one of them to the canonical shape — so the queue's TEXT7466 /// rewrites every one of them to the canonical shape — so the queue's TEXT
7467 /// comparisons never again meet a `Z` sorting after a `.`. The row planted7467 /// comparisons never again meet a `Z` sorting after a `.`. The row planted
7468 /// here is the production reminder, verbatim: due on a whole second,7468 /// here is the production reminder, verbatim: due on a whole second,
7469-/// written without a fraction.7469+/// written without a fraction. The old formatter's other short spelling —
7470+/// a subsecond with its trailing zero trimmed, one digit short — is
7471+/// planted beside it, because `Z` outranks the digits too and a
7472+/// twenty-nine-character stamp compares no better than a twenty-character
7473+/// one.
7470 #[tokio::test]7474 #[tokio::test]
7471 async fn a_boot_canonicalizes_the_legacy_whole_second_stamps() {7475 async fn a_boot_canonicalizes_the_legacy_whole_second_stamps() {
7472 let dir = std::env::temp_dir().join(format!("iz-test-{}", Ulid::new()));7476 let dir = std::env::temp_dir().join(format!("iz-test-{}", Ulid::new()));
@@ -7483,19 +7487,20 @@ async fn a_boot_canonicalizes_the_legacy_whole_second_stamps() {
7483 let due = clock - Duration::minutes(15);7487 let due = clock - Duration::minutes(15);
7484 drop(store);7488 drop(store);
7485 7489
7486- // The old write path, by hand: the same instants, no fraction, in a7490+ // The old write paths, by hand: the same instants, no fraction, in a
7487- // handful of the columns the boot pass owns. Everything else in the7491+ // handful of the columns the boot pass owns — and one column carrying
7488- // file was written by the canonical stamp already.7492+ // the trimmed-fraction spelling an eight-digit nanosecond used to get.
7489- let columns = [7493+ // Everything else in the file was written by the canonical stamp
7494+ // already. The reminder's own due keeps its instant: only the spelling
7495+ // is legacy, never the time it names.
7496+ let db = turso::Builder::new_local(&path).build().await.unwrap();
7497+ let conn = db.connect().unwrap();
7498+ for (table, column) in [
7490 ("mail_send", "next_attempt_at"),7499 ("mail_send", "next_attempt_at"),
7491 ("mail_send", "claimed_at"),7500 ("mail_send", "claimed_at"),
7492 ("task", "clock_at"),7501 ("task", "clock_at"),
7493 ("task", "created_at"),7502 ("task", "created_at"),
7494- ("task", "updated_at"),7503+ ] {
7495- ];
7496- let db = turso::Builder::new_local(&path).build().await.unwrap();
7497- let conn = db.connect().unwrap();
7498- for (table, column) in columns {
7499 conn.execute(7504 conn.execute(
7500 &format!(7505 &format!(
7501 "UPDATE {table} SET {column} = substr({column}, 1, 19) || 'Z' \7506 "UPDATE {table} SET {column} = substr({column}, 1, 19) || 'Z' \
@@ -7506,6 +7511,14 @@ async fn a_boot_canonicalizes_the_legacy_whole_second_stamps() {
7506 .await7511 .await
7507 .unwrap();7512 .unwrap();
7508 }7513 }
7514+ // A subsecond whose last digit the old formatter would have trimmed
7515+ // away: `.123456780` written as `.12345678`.
7516+ conn.execute(
7517+ "UPDATE task SET updated_at = substr(updated_at, 1, 20) || '12345678Z'",
7518+ (),
7519+ )
7520+ .await
7521+ .unwrap();
7509 drop(conn);7522 drop(conn);
7510 drop(db);7523 drop(db);
7511 7524
@@ -7513,7 +7526,13 @@ async fn a_boot_canonicalizes_the_legacy_whole_second_stamps() {
7513 let reopened = TursoStore::open(&path, &dir.join("storage")).await.unwrap();7526 let reopened = TursoStore::open(&path, &dir.join("storage")).await.unwrap();
7514 let db = turso::Builder::new_local(&path).build().await.unwrap();7527 let db = turso::Builder::new_local(&path).build().await.unwrap();
7515 let conn = db.connect().unwrap();7528 let conn = db.connect().unwrap();
7516- for (table, column) in columns {7529+ for (table, column) in [
7530+ ("mail_send", "next_attempt_at"),
7531+ ("mail_send", "claimed_at"),
7532+ ("task", "clock_at"),
7533+ ("task", "created_at"),
7534+ ("task", "updated_at"),
7535+ ] {
7517 let mut rows = conn7536 let mut rows = conn
7518 .query(7537 .query(
7519 &format!("SELECT {column} FROM {table} WHERE {column} IS NOT NULL"),7538 &format!("SELECT {column} FROM {table} WHERE {column} IS NOT NULL"),
@@ -7524,15 +7543,22 @@ async fn a_boot_canonicalizes_the_legacy_whole_second_stamps() {
7524 let mut seen = 0;7543 let mut seen = 0;
7525 while let Some(row) = rows.next().await.unwrap() {7544 while let Some(row) = rows.next().await.unwrap() {
7526 let raw: String = row.get(0).unwrap();7545 let raw: String = row.get(0).unwrap();
7527- assert_eq!(7546+ assert_eq!(raw.len(), 30, "{table}.{column} came back canonical: {raw}");
7528- raw.len(),
7529- 30,
7530- "{table}.{column} came back canonical: {raw}"
7531- );
7532 seen += 1;7547 seen += 1;
7533 }7548 }
7534 assert!(seen > 0, "{table}.{column} had rows to rewrite");7549 assert!(seen > 0, "{table}.{column} had rows to rewrite");
7535 }7550 }
7551+ // The trimmed fraction came back padded, not re-derived: the digits it
7552+ // named are the digits it kept.
7553+ let mut rows = conn.query("SELECT updated_at FROM task", ()).await.unwrap();
7554+ let raw: String = rows
7555+ .next()
7556+ .await
7557+ .unwrap()
7558+ .expect("one task row")
7559+ .get(0)
7560+ .unwrap();
7561+ assert!(raw.ends_with(".123456780Z"), "padded with a zero: {raw}");
7536 drop(conn);7562 drop(conn);
7537 drop(db);7563 drop(db);
7538 7564
@@ -8442,7 +8468,10 @@ async fn demoting_a_member_to_viewer_takes_their_assignments_with_them() {
8442 for task in [&first, &second] {8468 for task in [&first, &second] {
8443 let chips = store.assignees_for_task(task).await.unwrap();8469 let chips = store.assignees_for_task(task).await.unwrap();
8444 assert_eq!(8470 assert_eq!(
8445- chips.iter().map(|p| p.display_name.as_str()).collect::<Vec<_>>(),8471+ chips
8472+ .iter()
8473+ .map(|p| p.display_name.as_str())
8474+ .collect::<Vec<_>>(),
8446 ["Emre"],8475 ["Emre"],
8447 "the demoted person is still a chip on {task}"8476 "the demoted person is still a chip on {task}"
8448 );8477 );
@@ -8571,7 +8600,8 @@ async fn set_user_disabled_round_trips() {
8571 async fn a_synced_member_is_born_linked_and_never_signed_in() {8600 async fn a_synced_member_is_born_linked_and_never_signed_in() {
8572 let (scratch, workspace, _admin) = workspace_with_admin().await;8601 let (scratch, workspace, _admin) = workspace_with_admin().await;
8573 let sync = scratch8602 let sync = scratch
8574- .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 0, "UTC+03:00")8603+ .store
8604+ .sync_member("sub-mert", "mert@iz.sh", "Mert", false, 0, "UTC+03:00")
8575 .await8605 .await
8576 .unwrap();8606 .unwrap();
8577 assert_eq!(sync, iz_core::store::MemberSync::Inserted);8607 assert_eq!(sync, iz_core::store::MemberSync::Inserted);
@@ -8586,7 +8616,8 @@ async fn a_synced_member_is_born_linked_and_never_signed_in() {
8586 assert!(row.last_signed_in_at.is_none());8616 assert!(row.last_signed_in_at.is_none());
8587 // An im admin the workspace has never met is Admin from the first beat.8617 // An im admin the workspace has never met is Admin from the first beat.
8588 scratch8618 scratch
8589- .store.sync_member("sub-boss", "boss@iz.sh", "Boss", true, 0, "UTC+03:00")8619+ .store
8620+ .sync_member("sub-boss", "boss@iz.sh", "Boss", true, 0, "UTC+03:00")
8590 .await8621 .await
8591 .unwrap();8622 .unwrap();
8592 let boss = scratch8623 let boss = scratch
@@ -8607,7 +8638,15 @@ async fn a_sync_claims_an_unclaimed_row_without_touching_its_sign_in_fact() {
8607 .await8638 .await
8608 .unwrap();8639 .unwrap();
8609 let sync = scratch8640 let sync = scratch
8610- .store.sync_member("sub-mert", "MERT@iz.sh", "Mert Yılmaz", false, 0, "UTC+03:00")8641+ .store
8642+ .sync_member(
8643+ "sub-mert",
8644+ "MERT@iz.sh",
8645+ "Mert Yılmaz",
8646+ false,
8647+ 0,
8648+ "UTC+03:00",
8649+ )
8611 .await8650 .await
8612 .unwrap();8651 .unwrap();
8613 assert_eq!(sync, iz_core::store::MemberSync::Claimed);8652 assert_eq!(sync, iz_core::store::MemberSync::Claimed);
@@ -8628,7 +8667,8 @@ async fn a_sync_follows_provider_drift_but_not_the_sign_in_fact() {
8628 let before = scratch.store.user(&admin_id).await.unwrap().unwrap();8667 let before = scratch.store.user(&admin_id).await.unwrap().unwrap();
8629 let seen = before.last_signed_in_at.clone();8668 let seen = before.last_signed_in_at.clone();
8630 let sync = scratch8669 let sync = scratch
8631- .store.sync_member("sub-ada", "ada@iz.sh", "Ada Lovelace", true, 0, "UTC+03:00")8670+ .store
8671+ .sync_member("sub-ada", "ada@iz.sh", "Ada Lovelace", true, 0, "UTC+03:00")
8632 .await8672 .await
8633 .unwrap();8673 .unwrap();
8634 assert_eq!(sync, iz_core::store::MemberSync::Refreshed);8674 assert_eq!(sync, iz_core::store::MemberSync::Refreshed);
@@ -8637,7 +8677,15 @@ async fn a_sync_follows_provider_drift_but_not_the_sign_in_fact() {
8637 assert_eq!(after.last_signed_in_at, seen);8677 assert_eq!(after.last_signed_in_at, seen);
8638 // Losing the flag in the directory drops an Admin to Member.8678 // Losing the flag in the directory drops an Admin to Member.
8639 scratch8679 scratch
8640- .store.sync_member("sub-ada", "ada@iz.sh", "Ada Lovelace", false, 0, "UTC+03:00")8680+ .store
8681+ .sync_member(
8682+ "sub-ada",
8683+ "ada@iz.sh",
8684+ "Ada Lovelace",
8685+ false,
8686+ 0,
8687+ "UTC+03:00",
8688+ )
8641 .await8689 .await
8642 .unwrap();8690 .unwrap();
8643 let demoted = scratch.store.user(&admin_id).await.unwrap().unwrap();8691 let demoted = scratch.store.user(&admin_id).await.unwrap().unwrap();
@@ -8649,7 +8697,8 @@ async fn an_agreeing_sync_is_untouched_and_silent() {
8649 let (scratch, _, _) = workspace_with_admin().await;8697 let (scratch, _, _) = workspace_with_admin().await;
8650 let mut rx = scratch.store.subscribe();8698 let mut rx = scratch.store.subscribe();
8651 let sync = scratch8699 let sync = scratch
8652- .store.sync_member("sub-ada", "ada@iz.sh", "Ada", true, 0, "UTC")8700+ .store
8701+ .sync_member("sub-ada", "ada@iz.sh", "Ada", true, 0, "UTC")
8653 .await8702 .await
8654 .unwrap();8703 .unwrap();
8655 assert_eq!(sync, iz_core::store::MemberSync::Untouched);8704 assert_eq!(sync, iz_core::store::MemberSync::Untouched);
@@ -8660,7 +8709,8 @@ async fn an_agreeing_sync_is_untouched_and_silent() {
8660 async fn a_sync_without_a_workspace_skips_and_writes_nothing() {8709 async fn a_sync_without_a_workspace_skips_and_writes_nothing() {
8661 let scratch = Scratch::open().await;8710 let scratch = Scratch::open().await;
8662 let sync = scratch8711 let sync = scratch
8663- .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 0, "UTC+03:00")8712+ .store
8713+ .sync_member("sub-mert", "mert@iz.sh", "Mert", false, 0, "UTC+03:00")
8664 .await8714 .await
8665 .unwrap();8715 .unwrap();
8666 assert_eq!(sync, iz_core::store::MemberSync::Skipped);8716 assert_eq!(sync, iz_core::store::MemberSync::Skipped);
@@ -8676,7 +8726,8 @@ async fn a_photo_version_bump_refreshes_and_announces() {
8676 let (scratch, workspace, _admin) = workspace_with_admin().await;8726 let (scratch, workspace, _admin) = workspace_with_admin().await;
8677 let mut rx = scratch.store.subscribe();8727 let mut rx = scratch.store.subscribe();
8678 let sync = scratch8728 let sync = scratch
8679- .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 2, "UTC+03:00")8729+ .store
8730+ .sync_member("sub-mert", "mert@iz.sh", "Mert", false, 2, "UTC+03:00")
8680 .await8731 .await
8681 .unwrap();8732 .unwrap();
8682 assert_eq!(sync, iz_core::store::MemberSync::Inserted);8733 assert_eq!(sync, iz_core::store::MemberSync::Inserted);
@@ -8691,7 +8742,8 @@ async fn a_photo_version_bump_refreshes_and_announces() {
8691 8742
8692 // The same version again: the row agrees, and silence is the answer.8743 // The same version again: the row agrees, and silence is the answer.
8693 let again = scratch8744 let again = scratch
8694- .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 2, "UTC+03:00")8745+ .store
8746+ .sync_member("sub-mert", "mert@iz.sh", "Mert", false, 2, "UTC+03:00")
8695 .await8747 .await
8696 .unwrap();8748 .unwrap();
8697 assert_eq!(again, iz_core::store::MemberSync::Untouched);8749 assert_eq!(again, iz_core::store::MemberSync::Untouched);
@@ -8699,7 +8751,8 @@ async fn a_photo_version_bump_refreshes_and_announces() {
8699 8751
8700 // im counted another upload: the stamp moves and the move is news.8752 // im counted another upload: the stamp moves and the move is news.
8701 let bumped = scratch8753 let bumped = scratch
8702- .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 3, "UTC+03:00")8754+ .store
8755+ .sync_member("sub-mert", "mert@iz.sh", "Mert", false, 3, "UTC+03:00")
8703 .await8756 .await
8704 .unwrap();8757 .unwrap();
8705 assert_eq!(bumped, iz_core::store::MemberSync::Refreshed);8758 assert_eq!(bumped, iz_core::store::MemberSync::Refreshed);