From a4e6d91ab501cc0accba11b6626df6664ca82c88 Mon Sep 17 00:00:00 2001 From: Ivan S Glazunov Date: Sun, 29 Sep 2024 17:03:45 +0300 Subject: [PATCH] 0.0.582 --- migrations/1727618396605-preload.ts | 43 +++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 migrations/1727618396605-preload.ts diff --git a/migrations/1727618396605-preload.ts b/migrations/1727618396605-preload.ts new file mode 100644 index 00000000..ca280126 --- /dev/null +++ b/migrations/1727618396605-preload.ts @@ -0,0 +1,43 @@ +import { generateApolloClient } from '@deep-foundation/hasura/client.js'; +import Debug from 'debug'; +import { DeepClient } from '../imports/client.js'; +import { installPackage } from './1678940577209-deepcase.js'; +import { containWithin, packageExists, sharePermissions } from './1664940577200-tsx.js'; + +const debug = Debug('deeplinks:migrations:preload'); +const log = debug.extend('log'); +const error = debug.extend('error'); + +const rootClient = generateApolloClient({ + path: `${process.env.MIGRATIONS_HASURA_PATH}/v1/graphql`, + ssl: !!+(process.env.MIGRATIONS_HASURA_SSL || 0), + secret: process.env.MIGRATIONS_HASURA_SECRET, +}); + +const root = new DeepClient({ + apolloClient: rootClient, +}); + +export const up = async () => { + log('up'); + const packageName = '@deep-foundation/preload'; + if (!await packageExists(packageName)) { + const adminId = await root.id('deep', 'admin'); + const admin = await root.login({ linkId: adminId }); + const deep = new DeepClient({ deep: root, ...admin }); + + await installPackage(deep, '@deep-foundation/preload'); + const packageId = await root.id('@deep-foundation/preload'); + await sharePermissions(adminId, packageId); + await containWithin(adminId, packageId); + + const Pckg = await deep.id('@deep-foundation/core', 'Package'); + const Preload = await deep.id('@deep-foundation/preload', 'Preload'); + const { data: packages } = await deep.select({ type_id: Pckg }); + await deep.insert(packages.map(p => ({ type_id: Preload, from_id: p.id, to_id: p.id }))); + } +}; + +export const down = async () => { + log('down'); +}; \ No newline at end of file diff --git a/package.json b/package.json index 1dd51767..85df3951 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@deep-foundation/deeplinks", - "version": "0.0.581", + "version": "0.0.582", "license": "Unlicense", "type": "module", "main": "import.js",