Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

johnny-smitherson
Copy link

@johnny-smitherson johnny-smitherson commented Dec 27, 2024

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

@johnny-smitherson johnny-smitherson marked this pull request as ready for review December 27, 2024 18:15
@GoranBrkuljan
Copy link
Member

GoranBrkuljan commented Dec 28, 2024

@johnny-smitherson thanks for the PR!

Let's remove migration changes, as currently they will not run migration for test files. In general we need to run migration within src dir or within test dir. However, I wil update logic to just ignore 'target' on a separate branch. Also, can you rebase against the main branch to pick up few latest changes. Thanks!


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));
Copy link
Member

@GoranBrkuljan GoranBrkuljan Dec 28, 2024

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(),
Copy link
Member

@GoranBrkuljan GoranBrkuljan Dec 28, 2024

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"
Copy link
Member

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,
Copy link
Member

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> {
Copy link
Member

@GoranBrkuljan GoranBrkuljan Dec 28, 2024

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.

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants