Skip to content

Commit

Permalink
Add updatedHeight on provider table and fix indexer (#38)
Browse files Browse the repository at this point in the history
* Add updatedHeight on provider table and fix indexer

* Bump indexer version

* Prepare for PR
  • Loading branch information
Redm4x authored Oct 24, 2023
1 parent 52140ef commit f8f3093
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
34 changes: 34 additions & 0 deletions indexer/UPGRADE.md
Original file line number Diff line number Diff line change
@@ -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";
```
4 changes: 2 additions & 2 deletions indexer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion indexer/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion indexer/src/indexers/akashStatsIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
1 change: 1 addition & 0 deletions shared/dbSchemas/akash/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f8f3093

Please sign in to comment.