|
| 1 | +import { Logger } from '@graphprotocol/common-ts' |
| 2 | + |
| 3 | +import { QueryInterface, DataTypes } from 'sequelize' |
| 4 | + |
| 5 | +interface MigrationContext { |
| 6 | + queryInterface: QueryInterface |
| 7 | + logger: Logger |
| 8 | +} |
| 9 | + |
| 10 | +interface Context { |
| 11 | + context: MigrationContext |
| 12 | +} |
| 13 | + |
| 14 | +export async function up({ context }: Context): Promise<void> { |
| 15 | + const { queryInterface, logger } = context |
| 16 | + |
| 17 | + const tables = await queryInterface.showAllTables() |
| 18 | + logger.debug('Checking if pending_rca_proposals table exists', { tables }) |
| 19 | + |
| 20 | + if (tables.includes('pending_rca_proposals')) { |
| 21 | + logger.debug( |
| 22 | + 'pending_rca_proposals already exists, migration not necessary', |
| 23 | + ) |
| 24 | + return |
| 25 | + } |
| 26 | + |
| 27 | + logger.info('Create pending_rca_proposals') |
| 28 | + await queryInterface.createTable('pending_rca_proposals', { |
| 29 | + id: { |
| 30 | + type: DataTypes.UUID, |
| 31 | + primaryKey: true, |
| 32 | + }, |
| 33 | + signed_payload: { |
| 34 | + type: DataTypes.BLOB, |
| 35 | + allowNull: false, |
| 36 | + }, |
| 37 | + version: { |
| 38 | + type: DataTypes.SMALLINT, |
| 39 | + allowNull: false, |
| 40 | + defaultValue: 2, |
| 41 | + }, |
| 42 | + status: { |
| 43 | + type: DataTypes.STRING(20), |
| 44 | + allowNull: false, |
| 45 | + defaultValue: 'pending', |
| 46 | + }, |
| 47 | + created_at: { |
| 48 | + type: DataTypes.DATE, |
| 49 | + allowNull: false, |
| 50 | + }, |
| 51 | + updated_at: { |
| 52 | + type: DataTypes.DATE, |
| 53 | + allowNull: false, |
| 54 | + }, |
| 55 | + }) |
| 56 | + |
| 57 | + await queryInterface.addIndex( |
| 58 | + 'pending_rca_proposals', |
| 59 | + ['status', 'created_at'], |
| 60 | + { |
| 61 | + name: 'idx_pending_rca_status', |
| 62 | + }, |
| 63 | + ) |
| 64 | + await queryInterface.addIndex('pending_rca_proposals', { |
| 65 | + fields: [{ name: 'created_at', order: 'DESC' }], |
| 66 | + name: 'idx_pending_rca_created', |
| 67 | + }) |
| 68 | +} |
| 69 | + |
| 70 | +export async function down({ context }: Context): Promise<void> { |
| 71 | + const { queryInterface, logger } = context |
| 72 | + logger.info('Drop pending_rca_proposals') |
| 73 | + await queryInterface.dropTable('pending_rca_proposals') |
| 74 | +} |
0 commit comments