Skip to content

Commit fa7b63f

Browse files
authored
feat: adapt to Indexer's new block ID (#749)
* 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 <105802444+kilted-andres@users.noreply.github.com> 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 <105802444+kilted-andres@users.noreply.github.com> Date: Fri Dec 6 11:25:33 2024 +0100 chore: upgrade to node v22 (#748) * fix: use raw SQL to cast into BigInt
1 parent 07afcf6 commit fa7b63f

File tree

5 files changed

+72
-12
lines changed

5 files changed

+72
-12
lines changed

src/components/CTypeDetails/CTypeDetails.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ linkToW3N.pathname = web3Name ?? creator;
5353
5454
const linkToBlock = new URL(`https://polkadot.js.org/apps/`);
5555
linkToBlock.searchParams.set('rpc', blockchainEndpoint);
56-
linkToBlock.hash = `/explorer/${block ? 'query/' + block : ''}`;
56+
linkToBlock.hash = `/explorer/${block != null ? 'query/' + block : ''}`;
5757
---
5858

5959
<section class={containerStyles.bigContainer}>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
/** @type {import('sequelize-cli').Migration} */
4+
module.exports = {
5+
async up(queryInterface, Sequelize) {
6+
// First, drop the 'search' column since it depends on 'block'
7+
await queryInterface.removeColumn('CTypes', 'search');
8+
9+
// Transformation the type of 'block' from string to bigint
10+
await queryInterface.changeColumn('CTypes', 'block', {
11+
type: 'BIGINT using (block::bigint)',
12+
allowNull: true,
13+
});
14+
// recreate the 'search' column
15+
await queryInterface.addColumn(
16+
'CTypes',
17+
'search',
18+
`tsvector generated always as (to_tsvector('english',
19+
coalesce("id"::text, '') || ' ' ||
20+
coalesce("schema"::text, '') || ' ' ||
21+
coalesce("title"::text, '') || ' ' ||
22+
coalesce("properties"::text, '') || ' ' ||
23+
coalesce("type"::text, '') || ' ' ||
24+
coalesce("creator"::text, '') || ' ' ||
25+
coalesce("block"::text, '') || ' ' ||
26+
coalesce("description"::text, ''))
27+
) stored`,
28+
);
29+
},
30+
31+
async down(queryInterface, Sequelize) {
32+
// First, drop the 'search' column since it depends on 'block'
33+
await queryInterface.removeColumn('CTypes', 'search');
34+
35+
// Transformation the type of 'block' from bigint to string
36+
await queryInterface.changeColumn('CTypes', 'block', {
37+
type: Sequelize.STRING,
38+
allowNull: true,
39+
});
40+
41+
// recreate the 'search' column
42+
await queryInterface.addColumn(
43+
'CTypes',
44+
'search',
45+
`tsvector generated always as (to_tsvector('english',
46+
coalesce("id"::text, '') || ' ' ||
47+
coalesce("schema"::text, '') || ' ' ||
48+
coalesce("title"::text, '') || ' ' ||
49+
coalesce("properties"::text, '') || ' ' ||
50+
coalesce("type"::text, '') || ' ' ||
51+
coalesce("creator"::text, '') || ' ' ||
52+
coalesce("block"::text, '') || ' ' ||
53+
coalesce("description"::text, ''))
54+
) stored`,
55+
);
56+
},
57+
};

src/models/ctype.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface CTypeDataInput extends Omit<ICType, '$id' | '$schema'> {
1313
schema: ICType['$schema'];
1414
creator: DidUri;
1515
createdAt: Date;
16-
block: string | null;
16+
block: bigint | null;
1717
description: string | null;
1818
attestationsCreated?: number;
1919
}
@@ -55,7 +55,7 @@ export const CTypeModelDefinition: ModelAttributes = {
5555
allowNull: false,
5656
},
5757
block: {
58-
type: DataTypes.STRING,
58+
type: DataTypes.BIGINT,
5959
},
6060
description: {
6161
type: DataTypes.STRING,

src/utilities/indexer/queryCTypes.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ interface QueriedCType {
4242
web3NameId: string;
4343
};
4444
registrationBlock: {
45-
id: string; // Block Ordinal Number, without punctuation
45+
/** Block Ordinal Number, without punctuation */
46+
id: string;
4647
hash: HexString;
47-
timeStamp: string; // ISO8601 Date String, like 2022-02-09T13:09:18.217
48+
/** ISO8601 Date String, like 2022-02-09T13:09:18.217 */
49+
timeStamp: string;
4850
};
49-
definition: string; // stringified JSON of cType Schema
51+
/** Stringified JSON of cType Schema */
52+
definition: string;
5053
}
5154

5255
export async function queryCTypes() {
@@ -83,7 +86,7 @@ export async function queryCTypes() {
8386
schema: $schema,
8487
createdAt: new Date(registrationBlock.timeStamp + 'Z'),
8588
creator,
86-
block: registrationBlock.id,
89+
block: BigInt(registrationBlock.id),
8790
...rest,
8891
attestationsCreated,
8992
});

src/utilities/mockCTypes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const mockCTypes: Record<string, CTypeData> = {
1010
creator: 'did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY',
1111
createdAt: new Date('2023-05-01T12:00:00'),
1212
description: 'This is some example cType data',
13-
block: '123',
13+
block: 123n,
1414
attestationsCreated: 1,
1515
tags: [
1616
{
@@ -35,7 +35,7 @@ export const mockCTypes: Record<string, CTypeData> = {
3535
creator: 'did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY',
3636
createdAt: new Date('2023-05-01T12:01:00'),
3737
description: 'This is an example of a CType with a nested property',
38-
block: '321',
38+
block: 321n,
3939
attestationsCreated: 22,
4040
isHidden: false,
4141
},
@@ -55,7 +55,7 @@ export const mockCTypes: Record<string, CTypeData> = {
5555
creator: 'did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY',
5656
createdAt: new Date('2023-05-01T12:02:00'),
5757
description: 'This is an example of a CType with a nested CType',
58-
block: '456',
58+
block: 456n,
5959
attestationsCreated: 333,
6060
isHidden: false,
6161
},
@@ -68,7 +68,7 @@ export const mockCTypes: Record<string, CTypeData> = {
6868
creator: 'did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY',
6969
createdAt: new Date('2023-05-01T12:00:00'),
7070
description: 'This is some example cType data',
71-
block: '123',
71+
block: 123n,
7272
attestationsCreated: 1,
7373
tags: [
7474
{
@@ -121,7 +121,7 @@ export const mockCTypes: Record<string, CTypeData> = {
121121
creator: 'did:kilt:4rrkiRTZgsgxjJDFkLsivqqKTqdUTuxKk3FX3mKFAeMxsR5E',
122122
attestationsCreated: 4444,
123123
createdAt: new Date('2023-05-01T12:03:00'),
124-
block: '456',
124+
block: 456n,
125125
isHidden: false,
126126
},
127127
};

0 commit comments

Comments
 (0)