Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions src/adapter/src/catalog/transact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,9 @@ impl Catalog {
typ,
sql,
} => {
let column_name = name.to_string();
let column_type = typ.to_string();
let nullable = typ.nullable;
let mut new_entry = state.get_entry(&id).clone();
let version = new_entry.item.add_column(name, typ, sql)?;
// All versions of a table share the same shard, so it shouldn't matter what
Expand All @@ -998,6 +1001,25 @@ impl Catalog {
};
table.collections.insert(version, new_global_id);

if Self::should_audit_log_item(new_entry.item()) {
let details = EventDetails::AlterAddColumnV1(mz_audit_log::AlterAddColumnV1 {
id: id.to_string(),
column: column_name,
column_type,
nullable,
});
CatalogState::add_to_audit_log(
&state.system_configuration,
oracle_write_ts,
session,
tx,
audit_events,
EventType::Alter,
catalog_type_to_audit_object_type(new_entry.item().typ()),
details,
)?;
}

tx.update_item(id, new_entry.into())?;
storage_collections_to_register.insert(new_global_id, shard_id);
}
Expand Down
21 changes: 21 additions & 0 deletions src/audit-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ pub enum EventDetails {
UpdateItemV1(UpdateItemV1),
RenameSchemaV1(RenameSchemaV1),
AlterRetainHistoryV1(AlterRetainHistoryV1),
AlterAddColumnV1(AlterAddColumnV1),
ToNewIdV1(ToNewIdV1),
FromPreviousIdV1(FromPreviousIdV1),
SetV1(SetV1),
Expand Down Expand Up @@ -1080,6 +1081,25 @@ pub struct AlterRetainHistoryV1 {
pub new_history: Option<String>,
}

#[derive(
Clone,
Debug,
Serialize,
Deserialize,
PartialOrd,
PartialEq,
Eq,
Ord,
Hash,
Arbitrary
)]
pub struct AlterAddColumnV1 {
pub id: String,
pub column: String,
pub column_type: String,
pub nullable: bool,
}

#[derive(
Clone,
Debug,
Expand Down Expand Up @@ -1192,6 +1212,7 @@ impl EventDetails {
EventDetails::AlterRetainHistoryV1(v) => {
serde_json::to_value(v).expect("must serialize")
}
EventDetails::AlterAddColumnV1(v) => serde_json::to_value(v).expect("must serialize"),
EventDetails::ToNewIdV1(v) => serde_json::to_value(v).expect("must serialize"),
EventDetails::FromPreviousIdV1(v) => serde_json::to_value(v).expect("must serialize"),
EventDetails::SetV1(v) => serde_json::to_value(v).expect("must serialize"),
Expand Down
2 changes: 1 addition & 1 deletion src/catalog-protos/objects_hashes.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"name": "objects.rs",
"md5": "dfd89e1c62b7f1663d6429846a76159f"
"md5": "0088761ac51bdbf5ef8be4a031d8e58a"
},
{
"name": "objects_v74.rs",
Expand Down
30 changes: 27 additions & 3 deletions src/catalog-protos/src/audit_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
//! because of Rust's orphan rules.

use mz_audit_log::{
AlterApplyReplacementV1, AlterDefaultPrivilegeV1, AlterRetainHistoryV1, AlterSetClusterV1,
AlterSourceSinkV1, CreateClusterReplicaV1, CreateClusterReplicaV2, CreateClusterReplicaV3,
CreateClusterReplicaV4, CreateIndexV1, CreateMaterializedViewV1,
AlterAddColumnV1, AlterApplyReplacementV1, AlterDefaultPrivilegeV1, AlterRetainHistoryV1,
AlterSetClusterV1, AlterSourceSinkV1, CreateClusterReplicaV1, CreateClusterReplicaV2,
CreateClusterReplicaV3, CreateClusterReplicaV4, CreateIndexV1, CreateMaterializedViewV1,
CreateOrDropClusterReplicaReasonV1, CreateRoleV1, CreateSourceSinkV1, CreateSourceSinkV2,
CreateSourceSinkV3, CreateSourceSinkV4, DropClusterReplicaV1, DropClusterReplicaV2,
DropClusterReplicaV3, EventDetails, EventType, EventV1, FromPreviousIdV1, FullNameV1,
Expand Down Expand Up @@ -1188,6 +1188,28 @@ impl RustType<crate::objects::audit_log_event_v1::AlterRetainHistoryV1> for Alte
}
}

impl RustType<crate::objects::audit_log_event_v1::AlterAddColumnV1> for AlterAddColumnV1 {
fn into_proto(&self) -> crate::objects::audit_log_event_v1::AlterAddColumnV1 {
crate::objects::audit_log_event_v1::AlterAddColumnV1 {
id: self.id.to_string(),
column: self.column.clone(),
column_type: self.column_type.clone(),
nullable: self.nullable,
}
}

fn from_proto(
proto: crate::objects::audit_log_event_v1::AlterAddColumnV1,
) -> Result<Self, TryFromProtoError> {
Ok(AlterAddColumnV1 {
id: proto.id,
column: proto.column,
column_type: proto.column_type,
nullable: proto.nullable,
})
}
}

impl RustType<crate::objects::audit_log_event_v1::ToNewIdV1> for ToNewIdV1 {
fn into_proto(&self) -> crate::objects::audit_log_event_v1::ToNewIdV1 {
crate::objects::audit_log_event_v1::ToNewIdV1 {
Expand Down Expand Up @@ -1342,6 +1364,7 @@ impl RustType<crate::objects::audit_log_event_v1::Details> for EventDetails {
EventDetails::AlterRetainHistoryV1(details) => {
AlterRetainHistoryV1(details.into_proto())
}
EventDetails::AlterAddColumnV1(details) => AlterAddColumnV1(details.into_proto()),
EventDetails::ToNewIdV1(details) => ToNewIdV1(details.into_proto()),
EventDetails::FromPreviousIdV1(details) => FromPreviousIdV1(details.into_proto()),
EventDetails::SetV1(details) => SetV1(details.into_proto()),
Expand Down Expand Up @@ -1428,6 +1451,7 @@ impl RustType<crate::objects::audit_log_event_v1::Details> for EventDetails {
ResetAllV1(Empty {}) => Ok(EventDetails::ResetAllV1),
RotateKeysV1(details) => Ok(EventDetails::RotateKeysV1(details.into_rust()?)),
CreateRoleV1(details) => Ok(EventDetails::CreateRoleV1(details.into_rust()?)),
AlterAddColumnV1(details) => Ok(EventDetails::AlterAddColumnV1(details.into_rust()?)),
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/catalog-protos/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2298,6 +2298,24 @@ pub mod audit_log_event_v1 {
pub new_history: Option<String>,
}

#[derive(
Clone,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Serialize,
Deserialize,
Arbitrary
)]
pub struct AlterAddColumnV1 {
pub id: String,
pub column: String,
pub column_type: String,
pub nullable: bool,
}

#[derive(
Clone,
Debug,
Expand Down Expand Up @@ -2490,6 +2508,7 @@ pub mod audit_log_event_v1 {
CreateMaterializedViewV1(CreateMaterializedViewV1),
AlterApplyReplacementV1(AlterApplyReplacementV1),
CreateRoleV1(CreateRoleV1),
AlterAddColumnV1(AlterAddColumnV1),
}
}

Expand Down
Loading