diff --git a/src/components/CTypeDetails/CTypeDetails.astro b/src/components/CTypeDetails/CTypeDetails.astro index bb708cce..39b15306 100644 --- a/src/components/CTypeDetails/CTypeDetails.astro +++ b/src/components/CTypeDetails/CTypeDetails.astro @@ -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 : ''}`; ---
diff --git a/src/migrations/20241206171516-integrateBlockNumbers.cjs b/src/migrations/20241206171516-integrateBlockNumbers.cjs new file mode 100644 index 00000000..09adc2ff --- /dev/null +++ b/src/migrations/20241206171516-integrateBlockNumbers.cjs @@ -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`, + ); + }, +}; diff --git a/src/models/ctype.ts b/src/models/ctype.ts index 3c57227a..9140be62 100644 --- a/src/models/ctype.ts +++ b/src/models/ctype.ts @@ -13,7 +13,7 @@ interface CTypeDataInput extends Omit { schema: ICType['$schema']; creator: DidUri; createdAt: Date; - block: string | null; + block: bigint | null; description: string | null; attestationsCreated?: number; } @@ -55,7 +55,7 @@ export const CTypeModelDefinition: ModelAttributes = { allowNull: false, }, block: { - type: DataTypes.STRING, + type: DataTypes.BIGINT, }, description: { type: DataTypes.STRING, diff --git a/src/utilities/indexer/queryCTypes.ts b/src/utilities/indexer/queryCTypes.ts index 3aced463..c67e1dc6 100644 --- a/src/utilities/indexer/queryCTypes.ts +++ b/src/utilities/indexer/queryCTypes.ts @@ -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() { @@ -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, }); diff --git a/src/utilities/mockCTypes.ts b/src/utilities/mockCTypes.ts index ef2c6935..efd8b63e 100644 --- a/src/utilities/mockCTypes.ts +++ b/src/utilities/mockCTypes.ts @@ -10,7 +10,7 @@ export const mockCTypes: Record = { 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: [ { @@ -35,7 +35,7 @@ export const mockCTypes: Record = { 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, }, @@ -55,7 +55,7 @@ export const mockCTypes: Record = { 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, }, @@ -68,7 +68,7 @@ export const mockCTypes: Record = { 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: [ { @@ -121,7 +121,7 @@ export const mockCTypes: Record = { creator: 'did:kilt:4rrkiRTZgsgxjJDFkLsivqqKTqdUTuxKk3FX3mKFAeMxsR5E', attestationsCreated: 4444, createdAt: new Date('2023-05-01T12:03:00'), - block: '456', + block: 456n, isHidden: false, }, };