Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agent: fix db migration for value_aggregate from 20 to 39 digits #973

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
}
Loading