chore(file-search): retire legacy index storage · simstudioai/sim@a4bfd13 · GitHub
Skip to content

Commit a4bfd13

Browse files
committed
chore(file-search): retire legacy index storage
1 parent eaa9ff0 commit a4bfd13

9 files changed

Lines changed: 27830 additions & 211 deletions

File tree

‎apps/sim/lib/workspace-files/search/README.md‎

Lines changed: 3 additions & 3 deletions

‎apps/sim/lib/workspace-files/search/chunks.integration.ts‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ describe('chunked workspace file search on PostgreSQL', () => {
187187
'0358_workspace_file_content_version_precision.sql',
188188
'0359_workspace_file_search_chunks.sql',
189189
ginWriteMigration,
190+
'0368_retire_legacy_file_search.sql',
190191
]) {
191192
await applyMigration(migration)
192193
}
@@ -208,7 +209,7 @@ describe('chunked workspace file search on PostgreSQL', () => {
208209
})
209210
beforeEach(async () => {
210211
await connection`TRUNCATE workspace, workspace_files, workspace_file_search_revision, workspace_file_search_build,
211-
workspace_file_search_chunk, workspace_file_search_index, workspace_file_search_segment, workspace_file_search_dispatch_queue, workspace_file_search_backfill`
212+
workspace_file_search_chunk, workspace_file_search_dispatch_queue, workspace_file_search_backfill`
212213
await connection`INSERT INTO workspace_file_search_backfill (id, completed_at) VALUES ('workspace-file-search-chunks-v2', now())`
213214
await addFile('file-1')
214215
})
@@ -222,6 +223,45 @@ describe('chunked workspace file search on PostgreSQL', () => {
222223
}
223224
})
224225

226+
it('retires legacy tables atomically, preserves current search, and safely replays', async () => {
227+
await index('heading\nretirement needle\ntail')
228+
await connection`CREATE TABLE workspace_file_search_index (file_id text PRIMARY KEY)`
229+
await connection`CREATE TABLE workspace_file_search_segment (file_id text, content text)`
230+
await connection`INSERT INTO workspace_file_search_index VALUES ('retired-file')`
231+
await connection`INSERT INTO workspace_file_search_segment VALUES ('retired-file', 'retired text')`
232+
await connection`CREATE VIEW legacy_dependency AS SELECT * FROM workspace_file_search_index`
233+
try {
234+
await expect(applyMigration('0368_retire_legacy_file_search.sql')).rejects.toMatchObject({
235+
code: '2BP01',
236+
})
237+
expect(
238+
(await connection`SELECT count(*)::int AS count FROM workspace_file_search_segment`)[0]
239+
.count
240+
).toBe(1)
241+
await connection`DROP VIEW legacy_dependency`
242+
for (let attempt = 0; attempt < 2; attempt++) {
243+
await applyMigration('0368_retire_legacy_file_search.sql')
244+
expect(
245+
(
246+
await connection`SELECT to_regclass('workspace_file_search_index') AS legacy_index,
247+
to_regclass('workspace_file_search_segment') AS legacy_segment`
248+
)[0]
249+
).toEqual({ legacy_index: null, legacy_segment: null })
250+
expect((await search('retirement needle')).results).toMatchObject([
251+
{ fileId: 'file-1', lineNumber: 2 },
252+
])
253+
expect((await search('^retirement.*needle$', 'regex')).results).toMatchObject([
254+
{ fileId: 'file-1', lineNumber: 2 },
255+
])
256+
}
257+
} finally {
258+
await connection`DROP VIEW IF EXISTS legacy_dependency`
259+
await applyMigration('0368_retire_legacy_file_search.sql')
260+
}
261+
await connection`DELETE FROM workspace_files WHERE id = 'file-1'`
262+
expect((await search('needle')).results).toEqual([])
263+
})
264+
225265
it('preserves search through disabling, draining, and replaying GIN pending-list maintenance', async () => {
226266
await connection`ALTER INDEX workspace_file_search_chunk_content_idx SET (fastupdate = on)`
227267
try {
Lines changed: 7 additions & 0 deletions

0 commit comments

Comments
 (0)