-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue 879: add composite index constraint to block concurrent inserts…
… of the same item to actions table
- Loading branch information
Showing
4 changed files
with
73 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,3 +119,4 @@ yalc.lock | |
# IDE | ||
.idea/ | ||
.envrc | ||
.vscode |
32 changes: 32 additions & 0 deletions
32
packages/indexer-agent/src/db/migrations/12-add-actions-composite-constraint.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,32 @@ | ||
import { Logger } from '@graphprotocol/common-ts' | ||
import { 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('Adding composite unique constraint to Actions table') | ||
// Add the new composite primary key | ||
await queryInterface.addConstraint('Actions', { | ||
fields: ['deploymentID', 'source'], | ||
type: 'unique', | ||
name: 'Actions_ckey_unique_deploymentID_source', | ||
}) | ||
} | ||
|
||
export async function down({ context }: Context): Promise<void> { | ||
const { queryInterface, logger } = context | ||
logger.info('Removing composite uniqie constraint from Actions table') | ||
await queryInterface.removeConstraint( | ||
'Actions', | ||
'Actions_ckey_unique_deploymentID_source', | ||
) | ||
} |
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