Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelB committed Nov 26, 2020
1 parent e1f5e37 commit 63ed71b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion targets/hasura/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions targets/hasura/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
version: 2
endpoint: http://localhost:8080
enable_telemetry: false
metadata_directory: metadata
actions:
kind: synchronous
Expand Down
1 change: 1 addition & 0 deletions targets/hasura/migrations/1606401836569_version/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."document_version";
11 changes: 11 additions & 0 deletions targets/hasura/migrations/1606401836569_version/up.sql
Original file line number Diff line number Diff line change
@@ -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';
34 changes: 33 additions & 1 deletion targets/ingester/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -119,6 +130,7 @@ async function getPackage(pkgName, pkgVersion = "latest") {
console.debug(`download package ${pkgName}@${latest}`);
await download(pkgName, url);
}
return latest;
}

/**
Expand Down Expand Up @@ -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");
Expand All @@ -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;
}
Expand Down

0 comments on commit 63ed71b

Please sign in to comment.