Skip to content

Commit 83cf336

Browse files
authored
fix(records): remove sync_id from mark_previous_generation_as_deleted index (#5144)
sync_id isn't a filter anymore in the `deleteOutdatedRecords` query. c2e9ba4 his commit replaces the existing index by a new one without the sync_id field <!-- Describe the problem and your solution --> <!-- Issue ticket number and link (if applicable) --> <!-- Testing instructions (skip if just adding/editing providers) -->
1 parent 38f1329 commit 83cf336

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { Knex } from 'knex';
2+
3+
export const config = {
4+
transaction: false
5+
};
6+
7+
export async function up(knex: Knex): Promise<void> {
8+
// adding a more specific index used by the "mark previous generation as deleted" query
9+
// removing sync_id from the index as it's not used in the query filter anymore
10+
// pg prevents adding index to parent table concurrently - must be done on each partition
11+
for (let p = 0; p < 256; p++) {
12+
await knex.raw(
13+
`CREATE INDEX CONCURRENTLY IF NOT EXISTS records_p${p}_mark_previous_generation_as_deleted_v2
14+
ON nango_records.records_p${p}(connection_id, model, sync_job_id)
15+
INCLUDE (id)
16+
WHERE deleted_at IS NULL;`
17+
);
18+
}
19+
20+
// droping existing indexes that are not being used by pg
21+
for (let p = 0; p < 256; p++) {
22+
await knex.raw(`DROP INDEX CONCURRENTLY IF EXISTS records_p${p}_mark_previous_generation_as_deleted;`);
23+
}
24+
}
25+
26+
export async function down(): Promise<void> {}

0 commit comments

Comments
 (0)