Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cd66e05
fix(storage): store U+0000 in strings on PostgreSQL and MongoDB
LeeroyHannigan Oct 29, 2026
09f112f
fix(storage-postgres): derive restored key columns and index rows fro…
LeeroyHannigan Oct 29, 2026
4dff16d
fix(migrate): name the catalog store sessions so the exclusive-access…
LeeroyHannigan Oct 29, 2026
9323f76
refactor(app): move the migrate application_name helper into its own …
LeeroyHannigan Oct 29, 2026
3e86e5c
fix(app): replace an application_name already in the migrate connecti…
LeeroyHannigan Oct 29, 2026
36b4aa6
test(storage-postgres): make the catalog version unreadable after the…
LeeroyHannigan Oct 29, 2026
c9b675a
fix(storage-postgres): rebuild composite keys and queue partitions in…
LeeroyHannigan Nov 1, 2026
0bd7324
fix(storage-postgres): rewrite legacy keys longest first in migration…
LeeroyHannigan Nov 1, 2026
2048b5d
Merge branch 'main' into fix/nul-in-strings
LeeroyHannigan Nov 3, 2026
a620d85
fix(storage-postgres): re-encode legacy strings in catalog migration 6
LeeroyHannigan Nov 3, 2026
636d624
test(storage): count migration 6 in the SQLite and MongoDB migration …
LeeroyHannigan Nov 3, 2026
d83f4ba
docs(contributing): renumber the worked migration example to 7
LeeroyHannigan Nov 3, 2026
c3a229f
test(cli): run migration 6 through migrate --yes beside its own sessions
LeeroyHannigan Nov 3, 2026
48ca715
Merge origin/main into fix/nul-in-strings
LeeroyHannigan Nov 20, 2026
7a10917
fix(storage-postgres): leave gsi_pending.index_context to migration 11
LeeroyHannigan Nov 20, 2026
a7b0277
fix(storage-postgres): re-encode stream_pending records in migration 13
LeeroyHannigan Nov 20, 2026
96a6376
test(storage-postgres): check the escape on the restore and legacy re…
LeeroyHannigan Nov 20, 2026
a922142
test(storage-postgres): read the index rows of catalog_nul_index_writ…
LeeroyHannigan Nov 20, 2026
a4ec2aa
fix(storage-mongodb): decode in-catalog backup items as the data path…
LeeroyHannigan Nov 20, 2026
8e7bb75
test(storage-postgres): test the context decode and stream_pending ch…
LeeroyHannigan Nov 20, 2026
9e1cfc7
refactor(storage-postgres): remove the second copy of the stored JSON…
LeeroyHannigan Nov 20, 2026
8ef0cfb
docs: list migration 11 as not convergent and stream_pending as escaped
LeeroyHannigan Nov 20, 2026
f24c51b
test(storage-postgres): give the stream_pending row of the guard test…
LeeroyHannigan Nov 20, 2026
8dc8091
test(storage-postgres): give the guard test the data database's strea…
LeeroyHannigan Nov 20, 2026
a3b5dcf
docs(storage): say that the in-catalog item decode follows the data path
LeeroyHannigan Nov 20, 2026
41d76ef
Merge origin/main into fix/nul-in-strings
LeeroyHannigan Nov 24, 2026
c62aa6e
fix(storage-postgres): keep key text as main stores it and refuse U+0…
LeeroyHannigan Nov 24, 2026
3be8ff5
fix(storage-mongodb): decode the field names of marked documents only
LeeroyHannigan Nov 24, 2026
c8d852f
fix(storage): leave the TTL attribute name as written
LeeroyHannigan Nov 24, 2026
48ee608
test(cli): wait for other sessions to close before the migration 13 runs
LeeroyHannigan Nov 24, 2026
d5c27dc
docs: record how PostgreSQL and MongoDB store U+0000 (ADR-0031)
LeeroyHannigan Nov 24, 2026
37fc130
test(storage-postgres): build the two long keys from letters and digits
LeeroyHannigan Nov 24, 2026
a68e23f
Merge origin/main into fix/nul-in-strings
LeeroyHannigan Nov 24, 2026
deff98f
Merge origin/main into fix/nul-in-strings
LeeroyHannigan Nov 24, 2026
17979e3
Merge origin/main into fix/nul-in-strings
LeeroyHannigan Nov 25, 2026
6ec490a
Merge origin/main into fix/nul-in-strings
LeeroyHannigan Dec 3, 2026
d559e2a
fix(storage-postgres): read a filtered vector search in stored form
LeeroyHannigan Dec 3, 2026
9be43dd
Merge origin/main into fix/nul-in-strings
LeeroyHannigan Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,29 +402,30 @@ SQLite, PostgreSQL, Cassandra and MongoDB migrate through this framework.

### Example: a nullable column on `tables`

Migration 13, `table_note` (13 being the next free id at the time of writing;
migrations 6, 7, 8, 9, 10, 11 and 12 are `backup_catalog_index`,
Migration 14, `table_note` (14 being the next free id at the time of writing;
migrations 6, 7, 8, 9, 10, 11, 12 and 13 are `backup_catalog_index`,
`stream_pending`, `restore_progress`, `warm_throughput`, `account_metrics`,
`attribute_name_escape` and `unique_access_key_ids`), adds a nullable
`note TEXT` column to the catalog's `tables` table on SQLite and PostgreSQL.
`attribute_name_escape`, `unique_access_key_ids` and `escape_control_chars`),
adds a nullable `note TEXT` column to the catalog's `tables` table on SQLite
and PostgreSQL.

In `crates/storage/src/migrations/registry.rs`, at the end of the
`migration_ids!` list:

```rust
/// Adds a nullable `note` column to the `tables` catalog table.
TableNote = 13, "table_note",
TableNote = 14, "table_note",
"add a nullable note column to the tables catalog";
```

PostgreSQL has `ADD COLUMN IF NOT EXISTS`, so its body is a file,
`crates/storage-postgres/migrations/0013_table_note.sql`:
`crates/storage-postgres/migrations/0014_table_note.sql`:

```sql
-- Copyright 2026 ExtendDB contributors
-- SPDX-License-Identifier: Apache-2.0
--
-- Migration 13, table_note, PostgreSQL catalog database: a nullable note
-- Migration 14, table_note, PostgreSQL catalog database: a nullable note
-- column on tables. IF NOT EXISTS makes a second run change nothing.

ALTER TABLE tables ADD COLUMN IF NOT EXISTS note TEXT;
Expand All @@ -439,7 +440,7 @@ In `crates/storage-postgres/src/migrations/mod.rs`, the arm in `migration()`:
bodies: vec![file_body!(
StoreKind::Catalog,
"migrations",
"0013_table_note.sql"
"0014_table_note.sql"
)],
},
```
Expand All @@ -458,19 +459,20 @@ and the id in the transactional arm of `runs_in()`:
| MigrationId::AccountMetrics
| MigrationId::AttributeNameEscape
| MigrationId::UniqueAccessKeyIds
| MigrationId::EscapeControlChars
| MigrationId::TableNote => RunsIn::Transaction,
```

SQLite has no `ADD COLUMN IF NOT EXISTS`, and a file with a plain
`ADD COLUMN` fails when it runs a second time, so the SQLite body is code
that checks for the column first.
`crates/storage-sqlite/src/migrations/m0013_table_note.rs`:
`crates/storage-sqlite/src/migrations/m0014_table_note.rs`:

```rust
// Copyright 2026 ExtendDB contributors
// SPDX-License-Identifier: Apache-2.0

//! Migration 13, `table_note`, SQLite: a nullable `note` column on `tables`.
//! Migration 14, `table_note`, SQLite: a nullable `note` column on `tables`.
//!
//! SQLite has no `ADD COLUMN IF NOT EXISTS`, so the body reads the table's
//! columns first and adds the column only when it is missing. A second run
Expand All @@ -482,10 +484,10 @@ use extenddb_storage::migrations::{CodeBody, Done, MigrationError};
use super::SqliteStores;

/// This file, whose SHA-256 the checksum test pins.
pub(crate) const SOURCE: &str = include_str!("m0013_table_note.rs");
pub(crate) const SOURCE: &str = include_str!("m0014_table_note.rs");

/// Recorded as this migration's checksum. Changes only with a new migration.
const FINGERPRINT: &str = "0013_table_note/sqlite/1";
const FINGERPRINT: &str = "0014_table_note/sqlite/1";

pub(crate) struct TableNote;

Expand Down Expand Up @@ -524,7 +526,7 @@ beside the others:
```rust
#[rustfmt::skip]
#[allow(clippy::all, deprecated)]
mod m0013_table_note;
mod m0014_table_note;
```

and the arm in `migration()`:
Expand All @@ -535,8 +537,8 @@ and the arm in `migration()`:
convergent: true,
bodies: vec![StoreBody::code(
StoreKind::Catalog,
&m0013_table_note::TableNote,
m0013_table_note::SOURCE,
&m0014_table_note::TableNote,
m0014_table_note::SOURCE,
)],
},
```
Expand All @@ -548,8 +550,8 @@ rows of `tables`:

```rust
#[tokio::test]
async fn migration_13_adds_the_note_column_to_tables() {
let db = temp_db("m13");
async fn migration_14_adds_the_note_column_to_tables() {
let db = temp_db("m14");
load_dump(&db, DEV_0_1_14).await;
run(&db).await.expect("migrate");
let mut text = dump(
Expand All @@ -559,12 +561,12 @@ async fn migration_13_adds_the_note_column_to_tables() {
)
.await;
text.push_str(&dump(&db, "SELECT table_name, note FROM tables ORDER BY table_name").await);
golden("0013_table_note", &text);
golden("0014_table_note", &text);
}
```

`EXTENDDB_BLESS_EXPECTED=1 cargo test -p extenddb-storage-sqlite --lib migration_13`
writes `crates/storage-sqlite/tests/fixtures/golden/0013_table_note.txt`, one
`EXTENDDB_BLESS_EXPECTED=1 cargo test -p extenddb-storage-sqlite --lib migration_14`
writes `crates/storage-sqlite/tests/fixtures/golden/0014_table_note.txt`, one
tab-separated line per row under each query:

```
Expand All @@ -579,15 +581,15 @@ The PostgreSQL body is a file, so it has no golden test.
The example declares `Kind::Breaking`. A nullable column can be additive by
the rule in step 4, but declaring it additive needs the old-binary job, which
this example does not add. As a breaking migration it makes a 1.x binary
without migration 13 refuse a catalog that has it, and a rollback restores the
without migration 14 refuse a catalog that has it, and a rollback restores the
backup.

The same PR changes the code that reads and writes `tables.note` in each
backend's catalog store, and commits the `docs/schema/sqlite.txt` and
`docs/schema/postgres.txt` that the integration jobs regenerate. It changes
no per-table DDL, because `tables` is a catalog table, and adds no `RELEASED`
entry. `extenddb migrate --list` then shows migration 13, and on a catalog at
migration 12 `extenddb migrate` lists migration 13 as pending and exits 3.
entry. `extenddb migrate --list` then shows migration 14, and on a catalog at
migration 13 `extenddb migrate` lists migration 14 as pending and exits 3.

### Running the migration tests

Expand Down
4 changes: 4 additions & 0 deletions crates/storage-cassandra/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ pub fn migration(id: MigrationId) -> Migration<CassandraStores> {
"access_key_id is the primary key of access_keys, and an import writes with IF NOT \
EXISTS, so an ID can be stored once",
),
MigrationId::EscapeControlChars => Migration::NotApplicable(
"Cassandra stores U+0000 in strings as written, so its stored form of strings does \
not change",
),
}
}

Expand Down
35 changes: 12 additions & 23 deletions crates/storage-mongodb/src/backup_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! appears in a collection name.
//!
//! `extenddb backup migrate-legacy` reads a backup through `items`, a cursor
//! over that collection with a frozen copy of the decode, and ends with
//! over that collection, decoded as the data path decodes it, and ends with
//! `replace_with_index_row`: one session transaction that takes the lock
//! below, inserts the catalog index document and writes DELETING marked
//! `migrated_to_store`, then the delete's drop and DELETED. DeleteBackup
Expand Down Expand Up @@ -101,7 +101,7 @@ use serde::Serialize;
use serde::de::DeserializeOwned;

use extenddb_core::types::{
AttributeDefinition, BackupDescription, BackupDetails, BackupSummary, GsiInput, Item,
AttributeDefinition, BackupDescription, BackupDetails, BackupSummary, GsiInput,
KeySchemaElement, LsiInput, Projection, ProvisionedThroughput, SourceTableDetails,
StreamSpecification, TableDescription, TimeToLiveDescription, TimeToLiveStatus,
};
Expand All @@ -123,7 +123,7 @@ use crate::backup_catalog::{
RESTORE_JOB_GENERATION, RESTORE_JOB_HEARTBEAT, RESTORE_JOB_STATUS, backup_in_use,
generation_field, unowned_insert,
};
use crate::data::data_collection_name;
use crate::data::{data_collection_name, document_to_item};
use crate::data_engine::{
CommitOutcome, TRANSIENT_RETRY_ATTEMPTS, TxErr, backoff_sleep, is_duplicate_key,
};
Expand Down Expand Up @@ -1984,11 +1984,14 @@ impl LegacyBackupReader for MongoEngine {

/// The AVAILABLE backup document (its source as `restore_source` reads
/// it), then a cursor over its `_backup_<backup_id>` collection in
/// batches of [`paging::DEFAULT_FETCH_BATCH`] documents, each decoded as
/// the data path decoded `item_data` when the backup was taken
/// ([`legacy_item_from_document`]). The collection is immutable while the
/// backup is AVAILABLE, so no snapshot is held; a DeleteBackup's drop
/// ends the cursor with an error.
/// batches of [`paging::DEFAULT_FETCH_BATCH`] documents. The collection
/// is a copy of the table's documents in their stored form, with the
/// field names and the `names_escaped` mark as the release that took it
/// stored them, so each is decoded as the data path decodes a stored
/// document ([`document_to_item`]). A backup taken before the escape
/// holds no mark, and its names read back as written. The collection
/// is immutable while the backup is AVAILABLE, so no snapshot is held; a
/// DeleteBackup's drop ends the cursor with an error.
fn items(
&self,
account_id: &str,
Expand Down Expand Up @@ -2028,7 +2031,7 @@ impl LegacyBackupReader for MongoEngine {
let mut cursor = cursor?;
match cursor.try_next().await {
Ok(Some(doc)) => {
let item = legacy_item_from_document(&doc);
let item = document_to_item(&doc);
let next = item.is_ok().then_some(cursor);
Some((item, next))
}
Expand Down Expand Up @@ -2077,20 +2080,6 @@ impl LegacyBackupReader for MongoEngine {
/// the frozen DeleteBackup must not finish the deletion and answer DELETED.
const MIGRATED_TO_STORE: &str = "migrated_to_store";

/// A frozen copy of the data path's decode of a stored document
/// (`crate::data::document_to_item`) as it was when the in-catalog `$out`
/// copies were taken, so the data path can change without changing what a
/// legacy backup reads as.
fn legacy_item_from_document(doc: &Document) -> Result<Item, StorageError> {
let item_data = doc
.get("item_data")
.ok_or_else(|| StorageError::Internal("Document missing item_data field".to_string()))?;
let json_value: serde_json::Value = bson::from_bson(item_data.clone())
.map_err(|e| StorageError::Internal(format!("BSON to JSON conversion error: {e}")))?;
serde_json::from_value(json_value)
.map_err(|e| StorageError::Internal(format!("JSON to Item conversion error: {e}")))
}

/// A backup document as a [`LegacyBackupKey`]; a document without its
/// `_id`, `account_id` or `backup_status`, or with a status no release
/// writes, is an error.
Expand Down
3 changes: 3 additions & 0 deletions crates/storage-mongodb/src/backup_live_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ use crate::data::{data_collection_name, document_to_item, item_to_document};
use crate::migrations::{MongoTarget, run_backup_catalog_index};
use crate::restore_engine::INSERT_MANY_DOCUMENTS;

#[path = "backup_live_tests_control_chars.rs"]
mod control_chars;

const ACCOUNT: &str = "123456789012";
const OTHER_ACCOUNT: &str = "210987654321";
const REGION: &str = "us-east-1";
Expand Down
77 changes: 77 additions & 0 deletions crates/storage-mongodb/src/backup_live_tests_control_chars.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2026 ExtendDB contributors
// SPDX-License-Identifier: Apache-2.0

//! Live MongoDB test of an in-catalog backup of an item whose attribute names
//! hold U+0000 and U+0001.
//!
//! The data path stores each field name of `item_data` through the escape of
//! `extenddb_storage::util::escape_json_keys`, and an in-catalog backup is a
//! `$out` copy of the table's collection, so the copy holds the escaped
//! names. `items`, which `extenddb backup migrate-legacy` reads, must return
//! the names as written. The test reads the replica set URI from
//! `EXTENDDB_TEST_MONGODB_URI` and is `#[ignore]`d, like the tests in the
//! parent module.

use extenddb_core::expression::ExpressionMaps;
use extenddb_core::types::{
AttributeValue, BillingMode, CreateTableInput, Item, KeyType, ScalarAttributeType,
};
use extenddb_storage::{DataEngine, JobPermit, LegacyBackupReader, TableEngine};
use futures::{FutureExt, StreamExt};

use super::{ACCOUNT, Fixture, attr, key};

#[tokio::test(flavor = "multi_thread")]
#[ignore = "needs a MongoDB replica set in EXTENDDB_TEST_MONGODB_URI"]
async fn live_legacy_items_return_names_that_hold_u0000_and_u0001_as_written() {
let fixture = Fixture::new().await;
let outcome = std::panic::AssertUnwindSafe(async {
let fx = &fixture;
fx.engine
.create_table(
ACCOUNT,
CreateTableInput {
table_name: "names".to_owned(),
key_schema: vec![key("pk", KeyType::Hash)],
attribute_definitions: vec![attr("pk", ScalarAttributeType::S)],
billing_mode: Some(BillingMode::PayPerRequest),
..Default::default()
},
)
.await
.expect("create the table");
let key_info = fx
.engine
.table_key_info(ACCOUNT, "names")
.await
.expect("key info");
let written: Item = [("pk", "p"), ("c\u{1}", "one"), ("n\u{0}", "two")]
.into_iter()
.map(|(name, value)| (name.to_owned(), AttributeValue::S(value.to_owned())))
.collect();
let maps = ExpressionMaps::default();
fx.engine
.put_item(&key_info, written.clone(), false, None, &maps, None)
.await
.expect("put");
let arn = fx
.engine
.create(ACCOUNT, "names", "b", JobPermit::detached())
.await
.expect("backup")
.backup_arn;
let read: Vec<Item> = fx
.engine
.items(ACCOUNT, &arn)
.await
.expect("items")
.items
.map(|item| item.expect("an item"))
.collect()
.await;
assert_eq!(read, vec![written]);
})
.catch_unwind()
.await;
fixture.finish_after(outcome).await;
}
Loading
Loading