Skip to content

Commit 7f5232f

Browse files
committed
feat(ddl): record schema version metadata on ADD/DROP COLUMN
ALTER TABLE ... ADD COLUMN now stamps the new column's `added_at_version` with the bumped schema version before appending it to the live column list, so the read path can distinguish columns that did not exist when older tuples were written. ALTER TABLE ... DROP COLUMN now records a `DroppedColumn` tombstone (definition, original position, version at drop) instead of silently discarding the column definition. This allows the reader to reconstruct the physical layout of any tuple written before the drop without requiring row migration. The CONVERT path initialises `dropped_columns` to an empty vec to keep all `StrictSchema` construction sites consistent.
1 parent 0d85eef commit 7f5232f

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

nodedb/src/control/server/pgwire/ddl/collection/alter/add_column.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ pub async fn alter_table_add_column(
6262
&format!("column '{}' already exists", column.name),
6363
));
6464
}
65+
let new_version = schema.version.saturating_add(1);
66+
let mut column = column;
67+
column.added_at_version = new_version;
6568
schema.columns.push(column);
66-
schema.version = schema.version.saturating_add(1);
69+
schema.version = new_version;
6770

6871
let mut updated = coll;
6972
updated.collection_type = nodedb_types::CollectionType::strict(schema.clone());

nodedb/src/control/server/pgwire/ddl/collection/alter/drop_column.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,16 @@ pub async fn alter_collection_drop_column(
7979
));
8080
}
8181

82-
schema.columns.remove(idx);
83-
schema.version = schema.version.saturating_add(1);
82+
let dropped_def = schema.columns.remove(idx);
83+
let new_version = schema.version.saturating_add(1);
84+
schema
85+
.dropped_columns
86+
.push(nodedb_types::columnar::DroppedColumn {
87+
def: dropped_def,
88+
position: idx,
89+
dropped_at_version: new_version,
90+
});
91+
schema.version = new_version;
8492

8593
let mut updated = coll;
8694
updated.collection_type = nodedb_types::CollectionType::strict(schema.clone());

nodedb/src/control/server/pgwire/ddl/convert.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ pub async fn convert_collection(
9292
let schema = nodedb_types::columnar::StrictSchema {
9393
columns,
9494
version: 1,
95+
dropped_columns: Vec::new(),
9596
};
9697
if target_type == "kv" {
9798
nodedb_types::CollectionType::kv(schema)

0 commit comments

Comments
 (0)