From 11623682c278f0cb6122ea95016a855f0e140cb4 Mon Sep 17 00:00:00 2001 From: pyranota <92104930+pyranota@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:05:44 +0000 Subject: [PATCH] Deploy collision warning fix (#4544) * feat: Multiplayer deploy collision warning Show warning with diff viewer if 2+ users try to deploy flow/script/app at the same time In other words, if user A and user B started editing same flow/script/app and user A deployed it, user B will get warning if they try to deploy as well. * Add warning for scripts * Add `deployedBy` to Apps * Format * Fix advanced deployment on scripts * Write comments and cleanup * feat(frontend): unify all triggers UX and simplify flow settings (#4259) * feat(frontend): added list of triggers in the flow graph * feat(frontend): added list of triggers in the flow graph * feat(frontend): clean up * feat(frontend): improve UX * feat(frontend): triggers * feat(frontend): triggers * feat(frontend): done * feat(frontend): fix trigger when position when a preprocessor is presetn * Glm/rework flow settings v2 (#4497) * fat(frontend): simplify flow settings menu * improve scroll * changing mute toggle * Add advanced settings badge * Add nord theme colors * Add bage for advanced options * fix minor issue * fix minor issue * Add triggers menu to flow settings * Add quick trigger access * remove triggers in flow settings * fix minor issue * Move triggers settings to flow right panel * polishing * fix unset store * remove save up to for triggers * fix padding * reset default tag color * remove custom select component * revert path change * revert section modif * Revert unused feature --------- Co-authored-by: Guilhem * Connect top bar cron to schedules settings * Turn copilot into node * fix copilot placement * remove useless import * fix center copilot * fix binding * remove copilot on top of preprocessor * render copilot node on condition * quickfix * remove copilot node * fix minor issues * fix route count update * fix schedule sync * harmonize colors * fix alignment and add edges * recenter node summary * fix schedules sync * Add id title * all * all * all * iteration * all * all * done * fix * more fixes --------- Co-authored-by: Guilhem Co-authored-by: Guilhem Co-authored-by: Ruben Fiszel Co-authored-by: Ruben Fiszel * Update ScriptBuilder.svelte * Remove `onMount` for flows * Use version instead of last_updated_at in flows * Use only versions for apps * Fetch latest data in Diffs in Apps * Optimize with (script/flow/app)GetLatestVersion Create several new endpoints, that returns just latest version without rest of the history * Sync Diffs with deployed * Improve Diff's data * Use `getFlowLatestVersion` * fix failing endpoints for deployed collision warning --------- Co-authored-by: Faton Ramadani Co-authored-by: Guilhem Co-authored-by: Guilhem Co-authored-by: Ruben Fiszel Co-authored-by: Ruben Fiszel --- backend/windmill-api/openapi.yaml | 6 +++++ backend/windmill-api/src/apps.rs | 24 ++++++++++++------- backend/windmill-api/src/flows.rs | 5 ++-- backend/windmill-api/src/scripts.rs | 23 +++++++++++------- .../src/lib/components/FlowBuilder.svelte | 3 ++- .../src/lib/components/ScriptBuilder.svelte | 3 ++- .../apps/editor/AppEditorHeader.svelte | 3 ++- 7 files changed, 46 insertions(+), 21 deletions(-) diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 855cb787fc..b4611bdd3d 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -4106,6 +4106,9 @@ paths: description: Script version/hash content: application/json: + + required: false + schema: $ref: "#/components/schemas/ScriptHistory" @@ -4611,6 +4614,8 @@ paths: description: Flow version content: application/json: + required: false + schema: $ref: "#/components/schemas/FlowVersion" @@ -5182,6 +5187,7 @@ paths: description: App version content: application/json: + required: false schema: $ref: "#/components/schemas/AppHistory" diff --git a/backend/windmill-api/src/apps.rs b/backend/windmill-api/src/apps.rs index 0c72d12b50..cd65136a2a 100644 --- a/backend/windmill-api/src/apps.rs +++ b/backend/windmill-api/src/apps.rs @@ -432,7 +432,9 @@ async fn get_latest_version( authed: ApiAuthed, Extension(user_db): Extension, Path((w_id, path)): Path<(String, StripPath)>, -) -> JsonResult { + +) -> JsonResult> { + let mut tx = user_db.begin(&authed).await?; let row = sqlx::query!( "SELECT a.id as app_id, av.id as version_id, dm.deployment_msg as deployment_msg @@ -441,15 +443,21 @@ async fn get_latest_version( ORDER BY created_at DESC", w_id, path.to_path(), - ).fetch_one(&mut *tx).await?; + ).fetch_optional(&mut *tx).await?; tx.commit().await?; - let result = AppHistory { - app_id: row.app_id, - version: row.version_id, - deployment_msg: row.deployment_msg, - }; - return Ok(Json(result)); + if let Some(row) = row { + let result = AppHistory { + app_id: row.app_id, + version: row.version_id, + deployment_msg: row.deployment_msg, + }; + + return Ok(Json(Some(result))); + } else { + return Ok(Json(None)); + } + } async fn update_app_history( diff --git a/backend/windmill-api/src/flows.rs b/backend/windmill-api/src/flows.rs index 7e4dd7b4a6..3644e04d30 100644 --- a/backend/windmill-api/src/flows.rs +++ b/backend/windmill-api/src/flows.rs @@ -543,7 +543,8 @@ async fn get_latest_version( authed: ApiAuthed, Extension(user_db): Extension, Path((w_id, path)): Path<(String, StripPath)>, -) -> JsonResult { +) -> JsonResult> { + let path = path.to_path(); let mut tx = user_db.begin(&authed).await?; @@ -556,7 +557,7 @@ async fn get_latest_version( path, w_id ) - .fetch_one(&mut *tx) + .fetch_optional(&mut *tx) .await?; tx.commit().await?; diff --git a/backend/windmill-api/src/scripts.rs b/backend/windmill-api/src/scripts.rs index 1560c31b2d..56b991713f 100644 --- a/backend/windmill-api/src/scripts.rs +++ b/backend/windmill-api/src/scripts.rs @@ -953,9 +953,10 @@ async fn get_latest_version( authed: ApiAuthed, Extension(user_db): Extension, Path((w_id, path)): Path<(String, StripPath)>, -) -> JsonResult { +) -> JsonResult> { let mut tx = user_db.begin(&authed).await?; - let row = sqlx::query!( + let row_o = sqlx::query!( + "SELECT s.hash as hash, dm.deployment_msg as deployment_msg FROM script s LEFT JOIN deployment_metadata dm ON s.hash = dm.script_hash WHERE s.workspace_id = $1 AND s.path = $2 @@ -963,15 +964,21 @@ async fn get_latest_version( w_id, path.to_path(), ) - .fetch_one(&mut *tx) + + .fetch_optional(&mut *tx) .await?; tx.commit().await?; - let result = ScriptHistory { - script_hash: ScriptHash(row.hash), - deployment_msg: row.deployment_msg, // - }; - return Ok(Json(result)); + if let Some(row) = row_o { + let result = ScriptHistory { + script_hash: ScriptHash(row.hash), + deployment_msg: row.deployment_msg, // + }; + return Ok(Json(Some(result))); + } else { + return Ok(Json(None)); + } + } async fn update_script_history( diff --git a/frontend/src/lib/components/FlowBuilder.svelte b/frontend/src/lib/components/FlowBuilder.svelte index fd0b9078d4..49d7055219 100644 --- a/frontend/src/lib/components/FlowBuilder.svelte +++ b/frontend/src/lib/components/FlowBuilder.svelte @@ -124,7 +124,8 @@ path: $pathStore }) - onLatest = version === flowVersion.id + onLatest = version === flowVersion?.id + } const dispatch = createEventDispatcher() diff --git a/frontend/src/lib/components/ScriptBuilder.svelte b/frontend/src/lib/components/ScriptBuilder.svelte index 48f24c8809..8be6e5104f 100644 --- a/frontend/src/lib/components/ScriptBuilder.svelte +++ b/frontend/src/lib/components/ScriptBuilder.svelte @@ -256,7 +256,8 @@ let actual_parent_hash = (await ScriptService.getScriptLatestVersion({ workspace: $workspaceStore!, path: script.path, - })).script_hash; + }))?.script_hash; + // Usually when we create new script, we put current hash as a parent_hash // But if we specify parent_hash that is already used, than we get error diff --git a/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte b/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte index 87a86d2f35..e3eb07b372 100644 --- a/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte +++ b/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte @@ -632,7 +632,8 @@ workspace: $workspaceStore!, path: appPath }) - onLatest = version === appVersion.version + onLatest = version === appVersion?.version + } $: saveDrawerOpen && compareVersions()