-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
override column type using macro attribute #67
base: main
Are you sure you want to change the base?
override column type using macro attribute #67
Conversation
@johnny-smitherson thanks for the PR! Let's remove migration changes, as currently they will not run migration for |
|
||
let column_type = char_attrs.column_type.clone().map( | ||
|tname| CqlType::from_str(tname.as_str()).unwrap() | ||
).unwrap_or_else(|| Field::outer_type(&field.ty, ignore)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we can do:
let column_type =
char_attrs
.column_type
.as_ref()
.map_or(Field::outer_type(&field.ty, ignore), |tname| {
let error = format!("Unknown column type: {}", tname);
CqlType::from_str(tname.as_str()).expect(&error)
});
So we can improve error handling. Otherwise, we will not have a clue why migrations failed. Also, we avoid cloning.
@@ -117,7 +127,8 @@ impl<'a> Field<'a> { | |||
Type::Path(type_path) => type_path.clone(), | |||
_ => panic!("Only type path is supported!"), | |||
}, | |||
outer_type: Field::outer_type(&field.ty, ignore), | |||
outer_type: column_type, | |||
column_type_override: char_attrs.column_type.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the 'clone' here if we borrow value for the column_type
[features] | ||
migrate = ["charybdis-migrate"] | ||
|
||
[dev-dependencies] | ||
tokio = "1.42.0" | ||
strum = { version = "0.26.3", features = ["derive"] } | ||
serde = "1.0" | ||
serde_json = "1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also fix no endlines in files!
@@ -33,6 +33,47 @@ pub struct CodeSchema { | |||
pub materialized_views: SchemaObjects, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove migration changes, I will handle 'target' ignore' on a separate branch.
impl<'frame, 'metadata> DeserializeValue<'frame, 'metadata> for AddressTypeCustomField { | ||
fn type_check( | ||
typ: &scylla::frame::response::result::ColumnType, | ||
) -> std::result::Result<(), scylla::deserialize::TypeCheckError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, path prefix for ColumnType
and Result
is not needed it's already in the scope because of use charybdis::scylla::frame::response::result::ColumnType;
and because std::result::Result
is automatically in the scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's update this in other functions as well.
adds attribute
#[charybdis(column_type = "TinyInt")]
that overrides detected cql type when in migrations.So far only works on tables; should add this for UDT too
closes #66 closes #68