// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
// SPDX-License-Identifier: Apache-2.0
/*
* Generated by @medplum/generator
* Do not edit manually.
*/
import type { PoolClient } from 'pg';
const SIMPLE = 'simple';
const ENGLISH = 'english';
export async function run(client: PoolClient): Promise<void> {
const fields = [
['HumanName', 'name', SIMPLE],
['HumanName', 'given', SIMPLE],
['HumanName', 'family', SIMPLE],
['Address', 'address', SIMPLE],
['Address', 'city', SIMPLE],
['Address', 'country', SIMPLE],
['Address', 'postalCode', SIMPLE],
['Address', 'state', SIMPLE],
['Address', 'use', SIMPLE],
['ValueSetElement', 'display', ENGLISH],
];
for (const [table, column, lang] of fields) {
// Drop existing index if it exists
// These indexes were created in migration v37
// Note: These used "_tsv_idx"
await client.query(`DROP INDEX CONCURRENTLY IF EXISTS "${table}_${column}_tsv_idx"`);
// Drop the precomputed columns if they exist
// These columns were created in migration v37
await client.query(`ALTER TABLE "${table}" DROP COLUMN IF EXISTS "${column}_tsv"`);
// Drop incorrect TSV index
// This was created in migration v51 with a bug in the index name
await client.query(`DROP INDEX CONCURRENTLY IF EXISTS "${table}_idx_tsv"`);
// Now add new TSV index column using the full name including table and column name
await client.query(
`CREATE INDEX CONCURRENTLY IF NOT EXISTS "${table}_${column}_idx_tsv" ON "${table}" USING gin (to_tsvector('${lang}', "${column}"))`
);
}
}