(
state: &SharedState,
identity: &AuthenticatedIdentity,
parts: &[&str],
)
| 11 | use super::parse::parse_drop_target; |
| 12 | |
| 13 | pub fn drop_sequence( |
| 14 | state: &SharedState, |
| 15 | identity: &AuthenticatedIdentity, |
| 16 | parts: &[&str], |
| 17 | ) -> PgWireResult<Vec<Response>> { |
| 18 | let tenant_id = identity.tenant_id.as_u64(); |
| 19 | |
| 20 | let (name, if_exists) = parse_drop_target(parts, 2); |
| 21 | |
| 22 | if !state.sequence_registry.exists(tenant_id, &name) { |
| 23 | if if_exists { |
| 24 | return Ok(vec![Response::Execution(Tag::new("DROP SEQUENCE"))]); |
| 25 | } |
| 26 | return Err(PgWireError::UserError(Box::new(ErrorInfo::new( |
| 27 | "ERROR".to_owned(), |
| 28 | "42P01".to_owned(), |
| 29 | format!("sequence \"{name}\" does not exist"), |
| 30 | )))); |
| 31 | } |
| 32 | |
| 33 | // Propose the delete through the metadata raft group. Every |
| 34 | // node's applier removes the record from local redb and from |
| 35 | // its in-memory `sequence_registry`. |
| 36 | let entry = crate::control::catalog_entry::CatalogEntry::DeleteSequence { |
| 37 | tenant_id, |
| 38 | name: name.clone(), |
| 39 | }; |
| 40 | let log_index = crate::control::metadata_proposer::propose_catalog_entry(state, &entry) |
| 41 | .map_err(|e| { |
| 42 | PgWireError::UserError(Box::new(ErrorInfo::new( |
| 43 | "ERROR".to_owned(), |
| 44 | "XX000".to_owned(), |
| 45 | e.to_string(), |
| 46 | ))) |
| 47 | })?; |
| 48 | if log_index == 0 { |
| 49 | // Single-node / no-cluster fallback. |
| 50 | if let Some(catalog) = state.credentials.catalog() { |
| 51 | let _ = catalog.delete_sequence(tenant_id, &name); |
| 52 | } |
| 53 | let _ = state.sequence_registry.remove(tenant_id, &name); |
| 54 | } |
| 55 | |
| 56 | state.schema_version.bump(); |
| 57 | |
| 58 | Ok(vec![Response::Execution(Tag::new("DROP SEQUENCE"))]) |
| 59 | } |
no test coverage detected