-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/hot schema reload, missing metadata keys (#2283)
* fix metadata keys * update changelog * update increment sql * update typing and tidy up * update on review, tidy up * fix sync and migration tests
- Loading branch information
Showing
5 changed files
with
98 additions
and
14 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
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
65 changes: 65 additions & 0 deletions
65
packages/node-core/src/indexer/storeCache/cacheMetadata.test.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,65 @@ | ||
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
import {CacheMetadataModel, DbOption, MetadataFactory} from '@subql/node-core'; | ||
import {QueryTypes, Sequelize} from '@subql/x-sequelize'; | ||
|
||
const option: DbOption = { | ||
host: process.env.DB_HOST ?? '127.0.0.1', | ||
port: process.env.DB_PORT ? Number(process.env.DB_PORT) : 5432, | ||
username: process.env.DB_USER ?? 'postgres', | ||
password: process.env.DB_PASS ?? 'postgres', | ||
database: process.env.DB_DATABASE ?? 'postgres', | ||
timezone: 'utc', | ||
}; | ||
|
||
describe('cacheMetadata integration', () => { | ||
let sequelize: Sequelize; | ||
let schema: string; | ||
|
||
beforeAll(async () => { | ||
sequelize = new Sequelize( | ||
`postgresql://${option.username}:${option.password}@${option.host}:${option.port}/${option.database}`, | ||
option | ||
); | ||
await sequelize.authenticate(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await sequelize.dropSchema(schema, {logging: false}); | ||
}); | ||
afterAll(async () => { | ||
await sequelize.close(); | ||
}); | ||
|
||
it('Ensure increment keys are created on _metadata table', async () => { | ||
schema = '"metadata-test-1"'; | ||
await sequelize.createSchema(schema, {}); | ||
const metaDataRepo = await MetadataFactory(sequelize, schema, false, '1'); | ||
|
||
await metaDataRepo.sync(); | ||
|
||
const cacheMetadataModel = new CacheMetadataModel(metaDataRepo); | ||
|
||
// create key at 0 | ||
await (cacheMetadataModel as any).incrementJsonbCount('schemaMigrationCount'); | ||
|
||
// increment by 1 | ||
await (cacheMetadataModel as any).incrementJsonbCount('schemaMigrationCount'); | ||
|
||
// increase by 100 | ||
await (cacheMetadataModel as any).incrementJsonbCount('schemaMigrationCount', 100); | ||
|
||
const v = (await sequelize.query( | ||
` | ||
SELECT * FROM ${schema}."_metadata" | ||
WHERE key = 'schemaMigrationCount'; | ||
`, | ||
{ | ||
type: QueryTypes.SELECT, | ||
} | ||
)) as any[]; | ||
expect(v.length).toBe(1); | ||
expect(v[0].value).toBe(101); | ||
}); | ||
}); |
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