Add `drop model` exec without advanced params

next
Sayan Nandan 1 year ago
parent fcc187901d
commit 1586b05bbd
No known key found for this signature in database
GPG Key ID: 42EEDF4AE9D96B54

@ -42,6 +42,7 @@ use {
mem::VInline,
ql::ddl::{
crt::CreateModel,
drop::DropModel,
syn::{FieldSpec, LayerSpec},
},
},
@ -105,6 +106,10 @@ impl ModelView {
Ok(())
}
}
pub fn is_empty_atomic(&self) -> bool {
// TODO(@ohsayan): change this!
true
}
}
impl ModelView {
@ -167,6 +172,21 @@ impl ModelView {
};
space._create_model(ItemID::new(model_name.as_str()), model)
}
pub fn exec_drop(gns: &super::GlobalNS, stmt: DropModel) -> DatabaseResult<()> {
let Some((space, model)) = stmt.entity.into_full() else {
return Err(DatabaseError::ExpectedEntity);
};
let spaces = gns.spaces().read();
let Some(space) = spaces.st_get(space.as_bytes()) else {
return Err(DatabaseError::DdlSpaceNotFound);
};
let mut w_space = space.models().write();
match w_space.st_delete_if(model.as_bytes(), |mdl| !mdl.is_empty_atomic()) {
Some(true) => Ok(()),
Some(false) => Err(DatabaseError::DdlModelViewNotEmpty),
None => Err(DatabaseError::DdlModelNotFound),
}
}
}
/*

@ -343,9 +343,9 @@ mod plan {
}
mod exec {
use crate::engine::{core::GlobalNS, idx::STIndex};
use crate::engine::{core::GlobalNS, error::DatabaseError, idx::STIndex};
#[test]
fn exec_simple_alter() {
fn simple_alter() {
let gns = GlobalNS::empty();
super::exec_plan(
&gns,
@ -359,4 +359,19 @@ mod exec {
)
.unwrap();
}
#[test]
fn failing_alter_nullable_switch_need_lock() {
let gns = GlobalNS::empty();
assert_eq!(
super::exec_plan(
&gns,
true,
"create model myspace.mymodel(username: string, null gh_handle: string)",
"alter model myspace.mymodel update gh_handle { nullable: false }",
|_| {},
)
.unwrap_err(),
DatabaseError::NeedLock
);
}
}

@ -117,4 +117,6 @@ pub enum DatabaseError {
DdlModelAlterBadTypedef,
/// didn't find the model
DdlModelNotFound,
/// attempted a remove, but the model view is nonempty
DdlModelViewNotEmpty,
}

Loading…
Cancel
Save