Apply a list of schema changes and return a new schema with incremented ID.
(&self, changes: Vec<crate::spec::SchemaChange>)
| 128 | |
| 129 | /// Apply a list of schema changes and return a new schema with incremented ID. |
| 130 | pub fn apply_changes(&self, changes: Vec<crate::spec::SchemaChange>) -> crate::Result<Self> { |
| 131 | let mut new_schema = self.clone(); |
| 132 | new_schema.id += 1; |
| 133 | new_schema.time_millis = chrono::Utc::now().timestamp_millis(); |
| 134 | |
| 135 | for change in changes { |
| 136 | match change { |
| 137 | crate::spec::SchemaChange::SetOption { key, value } => { |
| 138 | new_schema.options.insert(key, value); |
| 139 | } |
| 140 | crate::spec::SchemaChange::RemoveOption { key } => { |
| 141 | new_schema.options.remove(&key); |
| 142 | } |
| 143 | other => { |
| 144 | return Err(crate::Error::Unsupported { |
| 145 | message: format!("Schema change not yet supported: {other:?}"), |
| 146 | }); |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | Ok(new_schema) |
| 152 | } |
| 153 | |
| 154 | pub fn comment(&self) -> Option<&str> { |
| 155 | self.comment.as_deref() |
no test coverage detected