-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: added description and comment columns in all existing tables and apis #284
Conversation
e80798d
to
8f36918
Compare
@@ -0,0 +1,19 @@ | |||
-- This file should undo anything in `up.sql` | |||
-- contexts table |
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.
Are these needed?
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.
No , I will remove it
a37e9b2
to
dfc8172
Compare
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.
Lets make the fields non-nullable, as per the discussion.
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.
Description should be mandatory. I think comment too but we can discuss this
@@ -378,9 +378,21 @@ fn construct_new_payload( | |||
}, | |||
)?; | |||
|
|||
let description = res | |||
.get("description") | |||
.and_then(|val| val.as_str()) |
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.
This returns result right? We should handle that
let description = res | ||
.get("description") | ||
.and_then(|val| val.as_str()) | ||
.map(|s| s.to_string()); |
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.
You can do this inside and_then
pub description: Option<String>, | ||
pub comment: Option<String>, |
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.
This two should be mandatory in this case, the frontend should just send ""
c3b2999
to
0dd0666
Compare
aeb97be
to
a9ecce7
Compare
let existing_context = contexts_table | ||
.filter(context_id.eq(context_id_value)) | ||
.first::<Context>(transaction_conn) | ||
.optional()?; // Query the database for existing context |
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.
why we are making this optional ?
it should return db error
match existing_context { | ||
Some(ctx) => Ok(ctx.description), | ||
None => Err(superposition::AppError::NotFound(format!( | ||
"Description Not Provided in existing context", |
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.
error should be something different because if context is there , description will also be there
so if db gives not found error , then we will return description not provided
if something else error then we can say something went wrong , or could not fetch description
let mut req_mut = req.into_inner(); | ||
|
||
// Use the helper function to ensure the description | ||
if req_mut.description.is_none() { |
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.
not a blocker , also this can be argued
here can we do like this ,
let description = either from request_mut or if it is none then from ensure_description , also assign in req_mut.description
so that here description will be of type and we will not have to use unwrap_or_default
also declare change_reason here only, so that we wont have to cline the whole req_mut
let description = if req.description.is_none() { | ||
ensure_description(ctx_condition_value.clone(), conn)? | ||
} else { | ||
req.description.expect("Description should not be empty") |
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.
just a suggestion
I know this will work , but if we can use match expression or abstract the some part without expect or unwrap
would be great
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.
expect will cause a panic, this error message won't be logged properly as well. We should throw an AppError here
log::error!( | ||
"Failed to execute query while recomputing weight, error: {err}" | ||
); | ||
db_error!(err) | ||
})?; | ||
} | ||
let version_id = add_config_version(&state, tags, transaction_conn)?; | ||
let description = contexts_new_weight.iter().map(|(_, _, description, _)| description.clone()).collect::<Vec<String>>().join(","); |
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.
instead of using change_reason and description of all contexts,
lets add only this
description: weight recomputed
change_reason: weight recomputed
@@ -75,12 +81,24 @@ pub struct FunctionsInfo { | |||
pub code: Option<String>, | |||
} | |||
|
|||
#[derive(Serialize)] |
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 are not using this anymore
15db62c
to
a5b0055
Compare
8a27413
to
ab85eb7
Compare
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.
Main concern: the error message for a context description not being found.
Nitpicks: no expect calls though they are safe since it throws off clippy checks
log::error!("construct new payload: Description is not a valid string"); | ||
return Err(bad_argument!("Description must be a string")); | ||
} | ||
None => None, |
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.
@sauraww construct_new_payload
function is used by reduce, I don't know if we can just get the description like this. I think we'll need to combine all the descriptions being reduced into one or
insert a new description
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.
Are you suggesting that we take it as input in the reduce api itself ?
} else { | ||
req.description | ||
.clone() | ||
.expect("Description should not be empty") |
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.
No expects, throw an error here
@@ -198,6 +198,15 @@ fn create_ctx_from_put_req( | |||
tenant_config: &TenantConfig, | |||
) -> superposition::Result<Context> { | |||
let ctx_condition = req.context.to_owned().into_inner(); | |||
let description = if req.description.is_none() { | |||
let ctx_condition_value = Value::Object(ctx_condition.clone().into()); |
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.
nitpick: would json!(ctx_condition) work?
Err(diesel::result::Error::NotFound) => Err(superposition::AppError::NotFound( | ||
"Description not provided in existing context".to_string(), | ||
)), |
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.
NotFound error message is confusing. A context was not found, but this message indicates only the description is missing. Probably based on the message the error code should be bad request
let description = if req.description.is_none() { | ||
ensure_description(ctx_condition_value.clone(), conn)? | ||
} else { | ||
req.description.expect("Description should not be empty") |
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.
expect will cause a panic, this error message won't be logged properly as well. We should throw an AppError here
} else { | ||
put_req | ||
.description | ||
.expect("Description should not be empty") |
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.
No expect
@@ -1,6 +1,6 @@ | |||
[print_schema] | |||
file = "schema.rs" | |||
patch_file = "schema.patch" | |||
#patch_file = "schema.patch" |
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 need schema.patch right?
ab85eb7
to
8d03179
Compare
unavailable
Problem
Added description and comment columns in all existing tables and apis
Solution
Provide a brief summary of your solution so that reviewers can understand your code
Environment variable changes
What ENVs need to be added or changed
Pre-deployment activity
Things needed to be done before deploying this change (if any)
Post-deployment activity
Things needed to be done after deploying this change (if any)
API changes