Skip to content

Commit

Permalink
test for require and prepearing for plv8 3.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Menzorg committed Mar 1, 2023
1 parent ba6a395 commit 93978b1
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 137 deletions.
4 changes: 1 addition & 3 deletions mathjs-bundled/mathjs.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions migrations/1655979260869-sync-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ const triggerFunctionFabric = (handleOperationTypeId, valueTrigger) => /*javascr
}
const require = (package) => {
const code = plv8.find_function("${LINKS_TABLE_NAME}__".concat(package))();
return eval(code)();
const packageFabric = plv8.find_function("${LINKS_TABLE_NAME}__sync__handlers__".concat(package, '__package'));
return packageFabric();
}
for (let i = 0; i < prepared.length; i++) {
(()=>{
Expand Down Expand Up @@ -445,7 +445,7 @@ export const dropSyncInsertTriggerFunction = sql`DROP FUNCTION IF EXISTS ${LINKS

export const createSyncDeleteTriggerFunction = sql`CREATE OR REPLACE FUNCTION ${LINKS_TABLE_NAME}__sync__handlers__delete__trigger__function() RETURNS TRIGGER AS $$ ${triggerFunctionFabric(handleDeleteId, false)} $$ LANGUAGE plv8;`;
export const createSyncDeleteTrigger = sql`CREATE TRIGGER a_${LINKS_TABLE_NAME}__sync__handlers__delete__trigger AFTER DELETE ON "links" FOR EACH ROW EXECUTE PROCEDURE ${LINKS_TABLE_NAME}__sync__handlers__delete__trigger__function();`;
export const dropSyncDeleteTrigger = sql`DROP TRIGGER a_${LINKS_TABLE_NAME}__sync__delete__handler__trigger ON "${LINKS_TABLE_NAME}";`;
export const dropSyncDeleteTrigger = sql`DROP TRIGGER a_${LINKS_TABLE_NAME}__sync__handlers__delete__trigger ON "${LINKS_TABLE_NAME}";`;
export const dropSyncDeleteTriggerFunction = sql`DROP FUNCTION IF EXISTS ${LINKS_TABLE_NAME}__sync__handlers__delete__trigger__function CASCADE;`;

// strings triggers
Expand Down
28 changes: 7 additions & 21 deletions migrations/1677594787268-mathjs.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
import Debug from 'debug';
import { generateApolloClient } from '@deep-foundation/hasura/client';
import { DeepClient } from '../imports/client';;
import { api, TABLE_NAME as LINKS_TABLE_NAME } from '../migrations/1616701513782-links';
import { api, TABLE_NAME as LINKS_TABLE_NAME } from './1616701513782-links';
import { sql } from '@deep-foundation/hasura/sql';
import { _ids } from '../imports/client';
import fs from 'fs';

const mathjs = require('../mathjs-bundled/mathjs.js').json;
const mathjs = require('../mathjs-bundled/mathjs.js').code;

const debug = Debug('deeplinks:migrations:plv8');
const log = debug.extend('log');
const error = debug.extend('error');

const client = generateApolloClient({
path: `${process.env.MIGRATIONS_HASURA_PATH}/v1/graphql`,
ssl: !!+process.env.MIGRATIONS_HASURA_SSL,
secret: process.env.MIGRATIONS_HASURA_SECRET,
});

const deep = new DeepClient({
apolloClient: client,
})


const mathjsFunction = /*javascript*/` return ${mathjs}`;

export const createMathjsFunction = sql`CREATE OR REPLACE FUNCTION ${LINKS_TABLE_NAME}__sync__handlers__mathjs__package(link jsonb, handletypeid bigint) RETURNS jsonb AS $$ ${mathjsFunction} $$ LANGUAGE plv8;`;
export const dropMathjsFunction = sql`DROP FUNCTION IF EXISTS ${LINKS_TABLE_NAME}__sync__handlers__mathjs__package CASCADE;`;

const mathjsFunction = `const sync__handlers__package = ${mathjs}; return sync__handlers__package()`;
export const createMathjsFunction = `CREATE OR REPLACE FUNCTION links__sync__handlers__mathjs__package() RETURNS jsonb AS $code$ ${mathjsFunction} $code$ LANGUAGE plv8;`;
export const dropMathjsFunction = `DROP FUNCTION IF EXISTS links__sync__handlers__mathjs__package CASCADE;`;

export const up = async () => {
log('up');
Expand All @@ -38,4 +24,4 @@ export const down = async () => {
log('down');

await api.sql(dropMathjsFunction);
};
};
7 changes: 3 additions & 4 deletions postgresql/dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM postgres:12

ENV PLV8_VERSION=3.0.0 \
PLV8_SHASUM="de030f5d6b0439710efa05f4c35ffb8ef36ae754fa0e3c46d334352cf1507661"
ENV PLV8_VERSION=3.1.5

RUN buildDependencies="build-essential \
ninja-build \
ca-certificates \
curl \
git-core \
python \
python3 \
gpp \
cpp \
pkg-config \
Expand All @@ -24,7 +24,6 @@ RUN buildDependencies="build-essential \
&& mkdir -p /tmp/build \
&& curl -o /tmp/build/v$PLV8_VERSION.tar.gz -SL "https://github.com/plv8/plv8/archive/v${PLV8_VERSION}.tar.gz" \
&& cd /tmp/build \
&& echo $PLV8_SHASUM v$PLV8_VERSION.tar.gz | sha256sum -c \
&& tar -xzf /tmp/build/v$PLV8_VERSION.tar.gz -C /tmp/build/ \
&& cd /tmp/build/plv8-$PLV8_VERSION \
&& make static \
Expand Down
Empty file removed test.json
Empty file.
1 change: 0 additions & 1 deletion test.txt

This file was deleted.

Loading

0 comments on commit 93978b1

Please sign in to comment.