diff --git a/libs/external-db-postgres/src/postgres_index_provider.ts b/libs/external-db-postgres/src/postgres_index_provider.ts index 055360f43..21562413b 100644 --- a/libs/external-db-postgres/src/postgres_index_provider.ts +++ b/libs/external-db-postgres/src/postgres_index_provider.ts @@ -83,10 +83,9 @@ export default class IndexProvider implements IIndexProvider { SELECT query FROM pg_stat_activity WHERE - -- get only the queries that are creating indexes (query ILIKE 'CREATE INDEX%' OR query ILIKE 'CREATE UNIQUE INDEX%') -- get only the queries that are creating indexes on collectionName table - AND (query LIKE '%${collectionName}(%') + AND (query LIKE '%${escapeIdentifier(collectionName)}(%') -- get only the queries that are active AND state = 'active' GROUP BY query; diff --git a/libs/external-db-postgres/src/postgres_utils.spec.ts b/libs/external-db-postgres/src/postgres_utils.spec.ts index 0de60c81e..51ed5b34e 100644 --- a/libs/external-db-postgres/src/postgres_utils.spec.ts +++ b/libs/external-db-postgres/src/postgres_utils.spec.ts @@ -29,6 +29,19 @@ describe('Postgres utils', () => { describe('Index utils functions', () => { test('extract DomainIndex from index query on 1 column', () => { + const indexQuery = 'CREATE INDEX idx_table_col1 ON table(col1)' + const result = extractIndexFromIndexQueryForCollection(indexQuery) + const expected = { + name: 'idx_table_col1', + columns: ['col1'], + isUnique: false, + caseInsensitive: true, + order: 'ASC', + status: DomainIndexStatus.BUILDING + } + expect(result).toEqual(expected) + }) + test('extract DomainIndex from unique index query on 1 column', () => { const indexQuery = 'CREATE UNIQUE INDEX idx_table_col1 ON table(col1)' const result = extractIndexFromIndexQueryForCollection(indexQuery) const expected = { @@ -42,7 +55,7 @@ describe('Postgres utils', () => { expect(result).toEqual(expected) }) - test('extract DomainIndex from index query on 2 column', () => { + test('extract DomainIndex from unique index query on 2 column', () => { const indexQuery = 'CREATE UNIQUE INDEX idx_table_col1_col2 ON table(col1, col2)' const result = extractIndexFromIndexQueryForCollection(indexQuery) const expected = {