diff --git a/packages/indexer-agent/src/db/migrations/12-add-scalar-tap-table.ts b/packages/indexer-agent/src/db/migrations/12-add-scalar-tap-table.ts index 177caff7b..6ef63eaeb 100644 --- a/packages/indexer-agent/src/db/migrations/12-add-scalar-tap-table.ts +++ b/packages/indexer-agent/src/db/migrations/12-add-scalar-tap-table.ts @@ -112,7 +112,7 @@ export async function up({ context }: Context): Promise { allowNull: false, }, value: { - type: DataTypes.DECIMAL(39), + type: DataTypes.DECIMAL(20), allowNull: false, }, }) @@ -140,7 +140,7 @@ export async function up({ context }: Context): Promise { allowNull: false, }, value_aggregate: { - type: DataTypes.DECIMAL(20), + type: DataTypes.DECIMAL(39), allowNull: false, }, final: { diff --git a/packages/indexer-agent/src/db/migrations/15-modify-scalar-tap-tables.ts b/packages/indexer-agent/src/db/migrations/15-modify-scalar-tap-tables.ts new file mode 100644 index 000000000..1e4468fce --- /dev/null +++ b/packages/indexer-agent/src/db/migrations/15-modify-scalar-tap-tables.ts @@ -0,0 +1,64 @@ +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_Ravs, scalar_tap_receipts and scalar_tap_receipts_invalid with correct value types`, + ) + + if (tables.includes('scalar_tap_ravs')) { + await queryInterface.changeColumn('scalar_tap_ravs', 'value_aggregate', { + type: DataTypes.DECIMAL(39), + allowNull: false, + }) + } + if (tables.includes('scalar_tap_receipts')) { + await queryInterface.changeColumn('scalar_tap_receipts', 'nonce', { + type: DataTypes.DECIMAL(20), + allowNull: false, + }) + } + + if (tables.includes('scalar_tap_receipts_invalid')) { + await queryInterface.changeColumn('scalar_tap_receipts_invalid', 'nonce', { + type: DataTypes.DECIMAL(20), + 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') +}