-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
indexer-agent: fix db migration for value_aggregate from 20 t0 40 digits
- Loading branch information
Showing
2 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/indexer-agent/src/db/migrations/15-modify-scalar-tap-tables.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} |