-
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.
agent, common: Add 'syncingNetwork' column to Actions table
- Syncing network is the network/chain that the subgraph deployment extracts data from.
- Loading branch information
Showing
10 changed files
with
159 additions
and
40 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
packages/indexer-agent/src/db/migrations/17-actions-add-syncing-network.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,53 @@ | ||
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.debug(`Checking if actions table exists`) | ||
const tables = await queryInterface.showAllTables() | ||
if (!tables.includes('Actions')) { | ||
logger.info(`Actions table does not exist, migration not necessary`) | ||
return | ||
} | ||
|
||
logger.debug(`Checking if 'Actions' table needs to be migrated`) | ||
const table = await queryInterface.describeTable('Actions') | ||
const syncingNetworkColumn = table.syncingNetwork | ||
if (syncingNetworkColumn) { | ||
logger.info( | ||
`'syncingNetwork' columns already exist, migration not necessary`, | ||
) | ||
return | ||
} | ||
|
||
logger.info(`Add 'syncingNetwork' column to 'Actions' table`) | ||
await queryInterface.addColumn('Actions', 'syncingNetwork', { | ||
type: DataTypes.BOOLEAN, | ||
defaultValue: false, | ||
}) | ||
} | ||
|
||
export async function down({ context }: Context): Promise<void> { | ||
const { queryInterface, logger } = context | ||
|
||
return await queryInterface.sequelize.transaction({}, async transaction => { | ||
const tables = await queryInterface.showAllTables() | ||
|
||
if (tables.includes('Actions')) { | ||
logger.info(`Remove 'syncingNetwork' column`) | ||
await context.queryInterface.removeColumn('Actions', 'syncingNetwork', { | ||
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
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
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
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
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