-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
indexer-agent,indexer-common,indexer-cli: Indexing rules by subgraph id
- Update indexing-rule model: deployment --> identifier & identifierType - CLI interface unchanged but now supports providing subgraph ids where deployment ids were the only supported ids previously. - Rules by subgraph id are processed into deployment based rules, so the reconciliation logic doesn't need to change.
- Loading branch information
Showing
30 changed files
with
734 additions
and
2,281 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
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
73 changes: 73 additions & 0 deletions
73
packages/indexer-agent/src/migrations/05-indexing-rules-add-subgraph-id.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,73 @@ | ||
import { Logger } from '@graphprotocol/common-ts' | ||
import { DataTypes, QueryInterface } from 'sequelize' | ||
|
||
interface MigrationContext { | ||
queryInterface: QueryInterface | ||
logger: Logger | ||
} | ||
|
||
interface Context { | ||
context: MigrationContext | ||
} | ||
|
||
export async function up({ context }: Context): Promise<void> { | ||
const { queryInterface, logger } = context | ||
|
||
logger.info( | ||
`Rename indexing rule identifier column and add identifier type column`, | ||
) | ||
|
||
logger.info(`Checking if indexing rules table exists`) | ||
const tables = await queryInterface.showAllTables() | ||
if (!tables.includes('IndexingRules')) { | ||
logger.info(`Indexing rules table does not exist, migration not necessary`) | ||
return | ||
} | ||
|
||
logger.info(`Checking if indexing rules table needs to be migrated`) | ||
const table = await queryInterface.describeTable('IndexingRules') | ||
const subgraphIdentifierTypeColumn = table.identifierType | ||
const subgraphIdentifierColumn = table.identifier | ||
if (subgraphIdentifierTypeColumn && subgraphIdentifierColumn) { | ||
logger.info( | ||
`Identifier and identifierType columns already exist, migration not necessary`, | ||
) | ||
return | ||
} | ||
|
||
logger.info(`Adding identifierType column to IndexingRules table`) | ||
await queryInterface.addColumn('IndexingRules', 'identifierType', { | ||
type: DataTypes.ENUM('deployment', 'subgraph', 'group'), | ||
primaryKey: true, | ||
defaultValue: 'group', | ||
}) | ||
|
||
await queryInterface.renameColumn('IndexingRules', 'deployment', 'identifier') | ||
} | ||
|
||
export async function down({ context }: Context): Promise<void> { | ||
const { queryInterface, logger } = context | ||
|
||
logger.info( | ||
`Revert renaming indexing rule identifier column and adding identifierType column`, | ||
) | ||
|
||
return await queryInterface.sequelize.transaction({}, async transaction => { | ||
const tables = await queryInterface.showAllTables() | ||
|
||
if (tables.includes('IndexingRules')) { | ||
await context.queryInterface.removeColumn( | ||
'IndexingRules', | ||
'identifierType', | ||
{ transaction }, | ||
) | ||
|
||
await queryInterface.renameColumn( | ||
'IndexingRules', | ||
'identifier', | ||
'deployment', | ||
{ transaction }, | ||
) | ||
} | ||
}) | ||
} |
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
Oops, something went wrong.