Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add updatedHeight on provider table and fix indexer #38

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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