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

feat: added description and comment columns in all existing tables and apis #284

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

sauraww
Copy link
Collaborator

@sauraww sauraww commented Nov 14, 2024

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

Endpoint Method Request body Response Body
API GET/POST, etc request response

@sauraww sauraww requested a review from a team as a code owner November 14, 2024 11:01
@sauraww sauraww force-pushed the feat/add-description-and-commit branch from e80798d to 8f36918 Compare November 14, 2024 11:02
@@ -0,0 +1,19 @@
-- This file should undo anything in `up.sql`
-- contexts table
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these needed?

Copy link
Collaborator Author

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

@sauraww sauraww force-pushed the feat/add-description-and-commit branch 11 times, most recently from a37e9b2 to dfc8172 Compare November 14, 2024 15:02
Copy link
Collaborator

@mahatoankitkumar mahatoankitkumar left a 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.

Copy link
Collaborator

@Datron Datron left a 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())
Copy link
Collaborator

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

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

Comment on lines 9 to 10
pub description: Option<String>,
pub comment: Option<String>,
Copy link
Collaborator

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 ""

@sauraww sauraww force-pushed the feat/add-description-and-commit branch 14 times, most recently from c3b2999 to 0dd0666 Compare November 21, 2024 12:57
@sauraww sauraww force-pushed the feat/add-description-and-commit branch 3 times, most recently from aeb97be to a9ecce7 Compare December 18, 2024 13:36
@sauraww sauraww changed the base branch from main to saas December 18, 2024 13:37
let existing_context = contexts_table
.filter(context_id.eq(context_id_value))
.first::<Context>(transaction_conn)
.optional()?; // Query the database for existing context
Copy link
Collaborator

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",
Copy link
Collaborator

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() {
Copy link
Collaborator

@pratikmishra356 pratikmishra356 Dec 18, 2024

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")
Copy link
Collaborator

@pratikmishra356 pratikmishra356 Dec 18, 2024

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

Copy link
Collaborator

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(",");
Copy link
Collaborator

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)]
Copy link
Collaborator

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

@sauraww sauraww force-pushed the feat/add-description-and-commit branch 3 times, most recently from 15db62c to a5b0055 Compare December 18, 2024 19:47
@Datron Datron requested a review from pratikmishra356 January 2, 2025 10:11
@sauraww sauraww force-pushed the feat/add-description-and-commit branch 4 times, most recently from 8a27413 to ab85eb7 Compare January 3, 2025 08:10
Copy link
Collaborator

@Datron Datron left a 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,
Copy link
Collaborator

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

Copy link
Collaborator Author

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")
Copy link
Collaborator

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

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?

Comment on lines 379 to 381
Err(diesel::result::Error::NotFound) => Err(superposition::AppError::NotFound(
"Description not provided in existing context".to_string(),
)),
Copy link
Collaborator

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")
Copy link
Collaborator

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")
Copy link
Collaborator

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

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?

@sauraww sauraww force-pushed the feat/add-description-and-commit branch from ab85eb7 to 8d03179 Compare January 3, 2025 10:49
@sauraww sauraww dismissed stale reviews from ayushjain17 and mahatoankitkumar January 3, 2025 11:14

unavailable

@sauraww sauraww merged commit 8311f36 into saas Jan 3, 2025
4 checks passed
@sauraww sauraww deleted the feat/add-description-and-commit branch January 3, 2025 11:15
Datron pushed a commit that referenced this pull request Jan 20, 2025
Datron pushed a commit that referenced this pull request Jan 23, 2025
Datron pushed a commit that referenced this pull request Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants