From a2b1d6997be1ed4e8853bf208e63da140631e42c Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 18 Aug 2023 00:19:15 +0200 Subject: [PATCH] update hub script --- .../20230817221718_upgrade_hub_sync_2.down.sql | 1 + .../20230817221718_upgrade_hub_sync_2.up.sql | 15 +++++++++++++++ cli/hub.ts | 13 +++++++------ 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 backend/migrations/20230817221718_upgrade_hub_sync_2.down.sql create mode 100644 backend/migrations/20230817221718_upgrade_hub_sync_2.up.sql diff --git a/backend/migrations/20230817221718_upgrade_hub_sync_2.down.sql b/backend/migrations/20230817221718_upgrade_hub_sync_2.down.sql new file mode 100644 index 0000000000..d2f607c5b8 --- /dev/null +++ b/backend/migrations/20230817221718_upgrade_hub_sync_2.down.sql @@ -0,0 +1 @@ +-- Add down migration script here diff --git a/backend/migrations/20230817221718_upgrade_hub_sync_2.up.sql b/backend/migrations/20230817221718_upgrade_hub_sync_2.up.sql new file mode 100644 index 0000000000..f1773d184d --- /dev/null +++ b/backend/migrations/20230817221718_upgrade_hub_sync_2.up.sql @@ -0,0 +1,15 @@ +-- Add up migration script here +UPDATE script SET content = 'import wmill from "https://deno.land/x/wmill@v1.151.0/main.ts"; +export async function main() { + await run( + "workspace", "add", "__automation", "admins", Deno.env.get("BASE_INTERNAL_URL") + "/", "--token", Deno.env.get("WM_TOKEN")); + + await run("hub", "pull"); +} + +async function run(...cmd: string[]) { + console.log("Running \"" + cmd.join('' '') + "\""); + await wmill.parse(cmd); +}', summary = 'Synchronize Hub Resource types with instance', +description = 'Basic administrative script to sync latest resource types from hub to share to every workspace. Recommended to run at least once. On a schedule by default.' +WHERE hash = -28028598712388162 AND workspace_id = 'admins'; \ No newline at end of file diff --git a/cli/hub.ts b/cli/hub.ts index b7a0904d90..f21bba09b4 100644 --- a/cli/hub.ts +++ b/cli/hub.ts @@ -62,6 +62,12 @@ async function pull(opts: GlobalOptions) { }); for (const x of list) { + try { + x.schema = JSON.parse(x.schema); + } catch (e) { + log.info("failed to parse schema for " + x.name); + continue; + } if ( resourceTypes.find( (y) => @@ -74,12 +80,7 @@ async function pull(opts: GlobalOptions) { continue; } log.info("syncing " + x.name); - try { - x.schema = JSON.parse(x.schema); - } catch (e) { - log.info("failed to parse schema for " + x.name); - continue; - } + await pushResourceType( workspace.workspaceId, x.name + ".resource-type.json",