From f8675f6babfbde02bda5eff66df042e808192620 Mon Sep 17 00:00:00 2001 From: Carlos V Date: Fri, 16 Aug 2024 17:45:16 +0000 Subject: [PATCH] feat!: Add new column to invalid_receipts table --- .../16-modify-invalid-receipts-table.ts | 51 +++++++++++++++++++ .../indexer-common/src/query-fees/models.ts | 6 +++ 2 files changed, 57 insertions(+) create mode 100644 packages/indexer-agent/src/db/migrations/16-modify-invalid-receipts-table.ts diff --git a/packages/indexer-agent/src/db/migrations/16-modify-invalid-receipts-table.ts b/packages/indexer-agent/src/db/migrations/16-modify-invalid-receipts-table.ts new file mode 100644 index 000000000..ee0f142e0 --- /dev/null +++ b/packages/indexer-agent/src/db/migrations/16-modify-invalid-receipts-table.ts @@ -0,0 +1,51 @@ +import { Logger } from '@graphprotocol/common-ts' +import { QueryInterface, DataTypes } from 'sequelize' + +interface MigrationContext { + queryInterface: QueryInterface + logger: Logger +} + +interface Context { + context: MigrationContext +} + +export async function up({ context }: Context): Promise { + const { queryInterface, logger } = context + + const tables = await queryInterface.showAllTables() + logger.debug( + `Modifying tables scalar_tap_receipts_invalid to add extra column`, + ) + + if (tables.includes('scalar_tap_receipts_invalid')) { + await queryInterface.addColumn('scalar_tap_receipts_invalid', 'error_log', { + type: DataTypes.TEXT, + allowNull: false, + }) + } +} + +export async function down({ context }: Context): Promise { + const { queryInterface, logger } = context + // Drop the scalar_tap_ravs table + logger.info(`Drop table`) + await queryInterface.dropTable('scalar_tap_ravs') + + logger.info(`Drop function, trigger, indices, and table`) + await queryInterface.sequelize.query( + 'DROP TRIGGER IF EXISTS receipt_update ON scalar_tap_receipts', + ) + await queryInterface.sequelize.query( + 'DROP FUNCTION IF EXISTS scalar_tap_receipt_notify', + ) + await queryInterface.removeIndex( + 'scalar_tap_receipts', + 'scalar_tap_receipts_allocation_id_idx', + ) + await queryInterface.removeIndex( + 'scalar_tap_receipts', + 'scalar_tap_receipts_timestamp_ns_idx', + ) + await queryInterface.dropTable('scalar_tap_receipts') +} diff --git a/packages/indexer-common/src/query-fees/models.ts b/packages/indexer-common/src/query-fees/models.ts index 821875ee5..1a6b57220 100644 --- a/packages/indexer-common/src/query-fees/models.ts +++ b/packages/indexer-common/src/query-fees/models.ts @@ -11,6 +11,7 @@ export interface ScalarTapReceiptsAttributes { timestamp_ns: bigint nonce: bigint value: bigint + error_log?: string } export class ScalarTapReceipts extends Model @@ -39,6 +40,7 @@ export class ScalarTapReceiptsInvalid public nonce!: bigint public value!: bigint public signature!: Uint8Array + public error_log!: string declare createdAt: CreationOptional declare updatedAt: CreationOptional @@ -657,6 +659,10 @@ export function defineQueryFeeModels(sequelize: Sequelize): QueryFeeModels { type: DataTypes.BLOB, allowNull: false, }, + error_log: { + type: DataTypes.TEXT, + allowNull: false, + }, }, { underscored: true,