Skip to content

Commit

Permalink
indexer-agent: fix db migration for value_aggregate from 20 t0 40 digits
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosvdr committed Aug 19, 2024
1 parent 46656dc commit bf2f4bf
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export async function up({ context }: Context): Promise<void> {
allowNull: false,
},
value: {
type: DataTypes.DECIMAL(39),
type: DataTypes.DECIMAL(20),
allowNull: false,
},
})
Expand Down Expand Up @@ -140,7 +140,7 @@ export async function up({ context }: Context): Promise<void> {
allowNull: false,
},
value_aggregate: {
type: DataTypes.DECIMAL(20),
type: DataTypes.DECIMAL(39),
allowNull: false,
},
final: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<void> {
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<void> {
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')
}

0 comments on commit bf2f4bf

Please sign in to comment.