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, mem::VInline,
ql::ddl::{ ql::ddl::{
crt::CreateModel, crt::CreateModel,
drop::DropModel,
syn::{FieldSpec, LayerSpec}, syn::{FieldSpec, LayerSpec},
}, },
}, },
@ -105,6 +106,10 @@ impl ModelView {
Ok(()) Ok(())
} }
} }
pub fn is_empty_atomic(&self) -> bool {
// TODO(@ohsayan): change this!
true
}
} }
impl ModelView { impl ModelView {
@ -167,6 +172,21 @@ impl ModelView {
}; };
space._create_model(ItemID::new(model_name.as_str()), model) 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 { mod exec {
use crate::engine::{core::GlobalNS, idx::STIndex}; use crate::engine::{core::GlobalNS, error::DatabaseError, idx::STIndex};
#[test] #[test]
fn exec_simple_alter() { fn simple_alter() {
let gns = GlobalNS::empty(); let gns = GlobalNS::empty();
super::exec_plan( super::exec_plan(
&gns, &gns,
@ -359,4 +359,19 @@ mod exec {
) )
.unwrap(); .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, DdlModelAlterBadTypedef,
/// didn't find the model /// didn't find the model
DdlModelNotFound, DdlModelNotFound,
/// attempted a remove, but the model view is nonempty
DdlModelViewNotEmpty,
} }

Loading…
Cancel
Save