Skip to content

Commit

Permalink
feat: adapt to Indexer's new block ID (#749)
Browse files Browse the repository at this point in the history
* feat: logic to migrate blocks from string to integers

* fix: handle search column

* feat: paranoic down transformation

* fix: change block type to integer on ctype model

* fix:  handle the null/zero cases explicitly

* fix: mocked cTypes to use numbers for blocks

* feat: make Integers Big on typeScript code

* fix: make properties explainers available elsewhere

* feat: make Integers Big on migration

* fix: down migration

* fix: delete migration to try new approach

* feat: new tiny migration

* fix: handle search dependency on migration

* Squashed commit of the following:

commit e26c54b
Author: Andrés <[email protected]>
Date:   Fri Dec 6 11:30:37 2024 +0100

    feat: simplify sequelize usage (#747)

    Rely on `dotenv` to load the environment variable `DATABASE_URI` to make it available for the sequelize configuration.
    On this way, there is no need to export the variable value manually.

commit fc68a24
Author: Andrés <[email protected]>
Date:   Fri Dec 6 11:25:33 2024 +0100

    chore: upgrade to node v22 (#748)

* fix: use raw SQL to cast into BigInt
  • Loading branch information
kilted-andres authored Dec 11, 2024
1 parent 07afcf6 commit fa7b63f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/CTypeDetails/CTypeDetails.astro
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ linkToW3N.pathname = web3Name ?? creator;
const linkToBlock = new URL(`https://polkadot.js.org/apps/`);
linkToBlock.searchParams.set('rpc', blockchainEndpoint);
linkToBlock.hash = `/explorer/${block ? 'query/' + block : ''}`;
linkToBlock.hash = `/explorer/${block != null ? 'query/' + block : ''}`;
---

<section class={containerStyles.bigContainer}>
Expand Down
57 changes: 57 additions & 0 deletions src/migrations/20241206171516-integrateBlockNumbers.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
// First, drop the 'search' column since it depends on 'block'
await queryInterface.removeColumn('CTypes', 'search');

// Transformation the type of 'block' from string to bigint
await queryInterface.changeColumn('CTypes', 'block', {
type: 'BIGINT using (block::bigint)',
allowNull: true,
});
// recreate the 'search' column
await queryInterface.addColumn(
'CTypes',
'search',
`tsvector generated always as (to_tsvector('english',
coalesce("id"::text, '') || ' ' ||
coalesce("schema"::text, '') || ' ' ||
coalesce("title"::text, '') || ' ' ||
coalesce("properties"::text, '') || ' ' ||
coalesce("type"::text, '') || ' ' ||
coalesce("creator"::text, '') || ' ' ||
coalesce("block"::text, '') || ' ' ||
coalesce("description"::text, ''))
) stored`,
);
},

async down(queryInterface, Sequelize) {
// First, drop the 'search' column since it depends on 'block'
await queryInterface.removeColumn('CTypes', 'search');

// Transformation the type of 'block' from bigint to string
await queryInterface.changeColumn('CTypes', 'block', {
type: Sequelize.STRING,
allowNull: true,
});

// recreate the 'search' column
await queryInterface.addColumn(
'CTypes',
'search',
`tsvector generated always as (to_tsvector('english',
coalesce("id"::text, '') || ' ' ||
coalesce("schema"::text, '') || ' ' ||
coalesce("title"::text, '') || ' ' ||
coalesce("properties"::text, '') || ' ' ||
coalesce("type"::text, '') || ' ' ||
coalesce("creator"::text, '') || ' ' ||
coalesce("block"::text, '') || ' ' ||
coalesce("description"::text, ''))
) stored`,
);
},
};
4 changes: 2 additions & 2 deletions src/models/ctype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface CTypeDataInput extends Omit<ICType, '$id' | '$schema'> {
schema: ICType['$schema'];
creator: DidUri;
createdAt: Date;
block: string | null;
block: bigint | null;
description: string | null;
attestationsCreated?: number;
}
Expand Down Expand Up @@ -55,7 +55,7 @@ export const CTypeModelDefinition: ModelAttributes = {
allowNull: false,
},
block: {
type: DataTypes.STRING,
type: DataTypes.BIGINT,
},
description: {
type: DataTypes.STRING,
Expand Down
11 changes: 7 additions & 4 deletions src/utilities/indexer/queryCTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ interface QueriedCType {
web3NameId: string;
};
registrationBlock: {
id: string; // Block Ordinal Number, without punctuation
/** Block Ordinal Number, without punctuation */
id: string;
hash: HexString;
timeStamp: string; // ISO8601 Date String, like 2022-02-09T13:09:18.217
/** ISO8601 Date String, like 2022-02-09T13:09:18.217 */
timeStamp: string;
};
definition: string; // stringified JSON of cType Schema
/** Stringified JSON of cType Schema */
definition: string;
}

export async function queryCTypes() {
Expand Down Expand Up @@ -83,7 +86,7 @@ export async function queryCTypes() {
schema: $schema,
createdAt: new Date(registrationBlock.timeStamp + 'Z'),
creator,
block: registrationBlock.id,
block: BigInt(registrationBlock.id),
...rest,
attestationsCreated,
});
Expand Down
10 changes: 5 additions & 5 deletions src/utilities/mockCTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const mockCTypes: Record<string, CTypeData> = {
creator: 'did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY',
createdAt: new Date('2023-05-01T12:00:00'),
description: 'This is some example cType data',
block: '123',
block: 123n,
attestationsCreated: 1,
tags: [
{
Expand All @@ -35,7 +35,7 @@ export const mockCTypes: Record<string, CTypeData> = {
creator: 'did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY',
createdAt: new Date('2023-05-01T12:01:00'),
description: 'This is an example of a CType with a nested property',
block: '321',
block: 321n,
attestationsCreated: 22,
isHidden: false,
},
Expand All @@ -55,7 +55,7 @@ export const mockCTypes: Record<string, CTypeData> = {
creator: 'did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY',
createdAt: new Date('2023-05-01T12:02:00'),
description: 'This is an example of a CType with a nested CType',
block: '456',
block: 456n,
attestationsCreated: 333,
isHidden: false,
},
Expand All @@ -68,7 +68,7 @@ export const mockCTypes: Record<string, CTypeData> = {
creator: 'did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY',
createdAt: new Date('2023-05-01T12:00:00'),
description: 'This is some example cType data',
block: '123',
block: 123n,
attestationsCreated: 1,
tags: [
{
Expand Down Expand Up @@ -121,7 +121,7 @@ export const mockCTypes: Record<string, CTypeData> = {
creator: 'did:kilt:4rrkiRTZgsgxjJDFkLsivqqKTqdUTuxKk3FX3mKFAeMxsR5E',
attestationsCreated: 4444,
createdAt: new Date('2023-05-01T12:03:00'),
block: '456',
block: 456n,
isHidden: false,
},
};

0 comments on commit fa7b63f

Please sign in to comment.