From f8f309335bbd7fcd51fbe67d6b6800d391577a17 Mon Sep 17 00:00:00 2001 From: Maxime Cyr Date: Tue, 24 Oct 2023 11:02:30 -0400 Subject: [PATCH] Add updatedHeight on provider table and fix indexer (#38) * Add updatedHeight on provider table and fix indexer * Bump indexer version * Prepare for PR --- indexer/UPGRADE.md | 34 +++++++++++++++++++++++ indexer/package-lock.json | 4 +-- indexer/package.json | 2 +- indexer/src/indexers/akashStatsIndexer.ts | 2 +- shared/dbSchemas/akash/provider.ts | 1 + 5 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 indexer/UPGRADE.md diff --git a/indexer/UPGRADE.md b/indexer/UPGRADE.md new file mode 100644 index 000000000..be84362e8 --- /dev/null +++ b/indexer/UPGRADE.md @@ -0,0 +1,34 @@ +# Upgrade instructions + +Some indexer updates changes the database schemas and an upgrade script must be run on the database to migrate the data before or after updating the indexer. Here is a list of those migrations. If a version is not listed here it means the indexer can be updated without any manual migration. + +## v1.5.0 + +Version 1.5.0 adds an `updatedHeight` field to Akash's `Provider` table and fixes a bug that was updating the `createdHeight` on provider updates. This script need to be run before updating the indexer to v1.5.0. + +``` +-- Add updatedHeight column to provider table +ALTER TABLE IF EXISTS "provider" ADD COLUMN "updatedHeight" integer; + +-- Set correct values for createdHeight and updatedHeight +WITH "created_msg" AS ( + SELECT m."height",ar."address" + FROM "message" m + INNER JOIN "transaction" t ON t.id=m."txId" + INNER JOIN "addressReference" ar ON ar."transactionId"=t."id" + WHERE t."hasProcessingError" IS FALSE AND m."type" LIKE '/akash.provider.%.MsgCreateProvider' AND ar."type"='Signer' +), +"update_msg" AS ( + SELECT MAX(m."height") AS "height",ar."address" + FROM "message" m + INNER JOIN "transaction" t ON t.id=m."txId" + INNER JOIN "addressReference" ar ON ar."transactionId"=t."id" + WHERE t."hasProcessingError" IS FALSE AND m."type" LIKE '/akash.provider.%.MsgUpdateProvider' AND ar."type"='Signer' + GROUP BY ar."address" +) +UPDATE "provider" p +SET "createdHeight"=cm."height", "updatedHeight"=um."height" +FROM "created_msg" cm +LEFT JOIN "update_msg" um ON um."address"=cm."address" +WHERE cm."address"=p."owner"; +``` diff --git a/indexer/package-lock.json b/indexer/package-lock.json index e73c47873..ba32ccb96 100644 --- a/indexer/package-lock.json +++ b/indexer/package-lock.json @@ -1,12 +1,12 @@ { "name": "cloudmos-indexer", - "version": "1.4.1", + "version": "1.5.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cloudmos-indexer", - "version": "1.4.1", + "version": "1.5.0", "license": "Apache-2.0", "dependencies": { "@akashnetwork/akashjs": "0.4.11", diff --git a/indexer/package.json b/indexer/package.json index eb2ce5228..955c84ff4 100644 --- a/indexer/package.json +++ b/indexer/package.json @@ -1,6 +1,6 @@ { "name": "cloudmos-indexer", - "version": "1.4.1", + "version": "1.5.0", "description": "Indexer for any Cosmos based blockchain", "author": "Cloudmos", "license": "Apache-2.0", diff --git a/indexer/src/indexers/akashStatsIndexer.ts b/indexer/src/indexers/akashStatsIndexer.ts index a5d1bf4aa..0382f7d7a 100644 --- a/indexer/src/indexers/akashStatsIndexer.ts +++ b/indexer/src/indexers/akashStatsIndexer.ts @@ -799,7 +799,7 @@ export class AkashStatsIndexer extends Indexer { await Provider.update( { hostUri: decodedMessage.hostUri, - createdHeight: height, + updatedHeight: height, email: decodedMessage.info?.email, website: decodedMessage.info?.website }, diff --git a/shared/dbSchemas/akash/provider.ts b/shared/dbSchemas/akash/provider.ts index 2d5e1706e..bcbc068ac 100644 --- a/shared/dbSchemas/akash/provider.ts +++ b/shared/dbSchemas/akash/provider.ts @@ -13,6 +13,7 @@ export class Provider extends Model { @Required @PrimaryKey @Column owner: string; @Required @Column hostUri: string; @Required @Column createdHeight: number; + @Column updatedHeight?: number; @Column deletedHeight?: number; @Column email?: string; @Column website?: string;