Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions crates/yaak-git/bindings/gen_models.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 30 additions & 8 deletions crates/yaak-models/bindings/gen_models.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Freeze the HTTP method, the originating request's name, and the request
-- body type on each response so history rows don't drift when the request is
-- later edited.
ALTER TABLE http_responses ADD COLUMN method TEXT;
ALTER TABLE http_responses ADD COLUMN request_name TEXT;
ALTER TABLE http_responses ADD COLUMN request_body_type TEXT;

-- Backfill method from the matching `send_url` event when we have one.
UPDATE http_responses
SET method = (
SELECT json_extract(e.event, '$.method')
FROM http_response_events e
WHERE e.response_id = http_responses.id
AND json_extract(e.event, '$.type') = 'send_url'
ORDER BY e.created_at ASC
LIMIT 1
);

-- Fall back to the current request method for older responses without events.
UPDATE http_responses
SET method = (
SELECT method FROM http_requests WHERE id = http_responses.request_id
)
WHERE method IS NULL;

UPDATE http_responses
SET request_name = (
SELECT name FROM http_requests WHERE id = http_responses.request_id
);

UPDATE http_responses
SET request_body_type = (
SELECT body_type FROM http_requests WHERE id = http_responses.request_id
);
12 changes: 12 additions & 0 deletions crates/yaak-models/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,9 @@ pub struct HttpResponse {
pub remote_addr: Option<String>,
pub request_content_length: Option<i32>,
pub request_headers: Vec<HttpResponseHeader>,
pub method: Option<String>,
pub request_name: Option<String>,
pub request_body_type: Option<String>,
pub status: i32,
pub status_reason: Option<String>,
pub state: HttpResponseState,
Expand Down Expand Up @@ -1414,6 +1417,9 @@ impl UpsertModelInfo for HttpResponse {
(Headers, serde_json::to_string(&self.headers)?.into()),
(RemoteAddr, self.remote_addr.into()),
(RequestHeaders, serde_json::to_string(&self.request_headers)?.into()),
(Method, self.method.into()),
(RequestName, self.request_name.into()),
(RequestBodyType, self.request_body_type.into()),
(State, serde_json::to_value(self.state)?.as_str().into()),
(Status, self.status.into()),
(StatusReason, self.status_reason.into()),
Expand All @@ -1437,6 +1443,9 @@ impl UpsertModelInfo for HttpResponse {
HttpResponseIden::RemoteAddr,
HttpResponseIden::RequestContentLength,
HttpResponseIden::RequestHeaders,
HttpResponseIden::Method,
HttpResponseIden::RequestName,
HttpResponseIden::RequestBodyType,
HttpResponseIden::State,
HttpResponseIden::Status,
HttpResponseIden::StatusReason,
Expand Down Expand Up @@ -1477,6 +1486,9 @@ impl UpsertModelInfo for HttpResponse {
r.get::<_, String>("request_headers").unwrap_or_default().as_str(),
)
.unwrap_or_default(),
method: r.get("method").unwrap_or_default(),
request_name: r.get("request_name").unwrap_or_default(),
request_body_type: r.get("request_body_type").unwrap_or_default(),
})
}
}
Expand Down
Loading
Loading