From 63ed71bc84688e23de2c83b5f10f0996650826a3 Mon Sep 17 00:00:00 2001 From: LionelB Date: Thu, 26 Nov 2020 16:09:30 +0100 Subject: [PATCH] update --- targets/hasura/Dockerfile | 2 +- targets/hasura/config.yaml | 1 + .../migrations/1606401836569_version/down.sql | 1 + .../migrations/1606401836569_version/up.sql | 11 ++++++ targets/ingester/src/cli.js | 34 ++++++++++++++++++- 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 targets/hasura/migrations/1606401836569_version/down.sql create mode 100644 targets/hasura/migrations/1606401836569_version/up.sql diff --git a/targets/hasura/Dockerfile b/targets/hasura/Dockerfile index 05a143265..89359b848 100644 --- a/targets/hasura/Dockerfile +++ b/targets/hasura/Dockerfile @@ -1,4 +1,4 @@ -FROM hasura/graphql-engine:v1.3.2.cli-migrations-v2 +FROM hasura/graphql-engine:v1.3.3.cli-migrations-v2 ENV HASURA_GRAPHQL_ENABLE_TELEMETRY false COPY ./migrations /hasura-migrations COPY ./metadata /hasura-metadata diff --git a/targets/hasura/config.yaml b/targets/hasura/config.yaml index 6ddf586e5..c7dd00812 100644 --- a/targets/hasura/config.yaml +++ b/targets/hasura/config.yaml @@ -1,5 +1,6 @@ version: 2 endpoint: http://localhost:8080 +enable_telemetry: false metadata_directory: metadata actions: kind: synchronous diff --git a/targets/hasura/migrations/1606401836569_version/down.sql b/targets/hasura/migrations/1606401836569_version/down.sql new file mode 100644 index 000000000..4d589d08e --- /dev/null +++ b/targets/hasura/migrations/1606401836569_version/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."document_version"; diff --git a/targets/hasura/migrations/1606401836569_version/up.sql b/targets/hasura/migrations/1606401836569_version/up.sql new file mode 100644 index 000000000..4974096f1 --- /dev/null +++ b/targets/hasura/migrations/1606401836569_version/up.sql @@ -0,0 +1,11 @@ +CREATE TABLE "public"."document_version" ( "repository" text NOT NULL, "version" text NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("repository") +); + +COMMENT ON TABLE "public"."document_version" IS E'tracks documents git version by repository'; + +CREATE TRIGGER "set_public_document_version_updated_at" + BEFORE UPDATE ON "public"."document_version" + FOR EACH ROW + EXECUTE PROCEDURE trigger_set_timestamp (); + +COMMENT ON TRIGGER "set_public_document_version_updated_at" ON "public"."document_version" IS 'trigger to set value of column "updated_at" to current timestamp on row update'; diff --git a/targets/ingester/src/cli.js b/targets/ingester/src/cli.js index 0592c93eb..398b78761 100644 --- a/targets/ingester/src/cli.js +++ b/targets/ingester/src/cli.js @@ -42,6 +42,17 @@ mutation insert_documents($documents: [documents_insert_input!]!) { } `; +const insertDocumentsVersionMutation = ` +mutation insert_document_version($object:document_version_insert_input!) { + version: insert_document_version_one(object: $object, on_conflict: { + constraint: document_version_pkey, + update_columns: version + }) { + repository, version + } +} +`; + /** * * @param {string} pkgName @@ -119,6 +130,7 @@ async function getPackage(pkgName, pkgVersion = "latest") { console.debug(`download package ${pkgName}@${latest}`); await download(pkgName, url); } + return latest; } /** @@ -163,10 +175,29 @@ async function initDocAvailabity(source) { } return result.data.documents.affected_rows; } +/** + * + * @param {string} repository + * @param {string} version + */ +async function updateVersion(repository, version) { + const result = await client + .mutation(insertDocumentsVersionMutation, { + object: { repository, version }, + }) + .toPromise(); + if (result.error) { + console.error(result.error); + throw new Error(`error updating document_version ${repository}@${version}`); + } + return result.data.version; +} async function main() { + /** @type {{[key:string]:string}} */ + const pkgVersions = {}; for (const [pkgName] of dataPackages) { - await getPackage(pkgName); + pkgVersions[pkgName] = await getPackage(pkgName); } if (args.dryRun) { console.log("dry-run mode"); @@ -186,6 +217,7 @@ async function main() { const chunks = chunk(documents, 80); const inserts = await batchPromises(chunks, insertDocuments, 15); ids = ids.concat(inserts); + await updateVersion(pkgName, pkgVersions[pkgName]); } return ids; }