95d0e58d31
**What** Add `GET /admin/regions` Add `GET /admin/regions/:id` Blocked by #6320 Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
33 lines
795 B
TypeScript
33 lines
795 B
TypeScript
export function generatePostgresAlterColummnIfExistStatement(
|
|
tableName: string,
|
|
columns: string[],
|
|
alterExpression: string
|
|
) {
|
|
let script = `
|
|
DO $$
|
|
DECLARE
|
|
current_column text;
|
|
BEGIN`
|
|
|
|
columns.forEach((column) => {
|
|
script += `
|
|
current_column := '${column}';
|
|
IF EXISTS (
|
|
SELECT 1
|
|
FROM information_schema.columns
|
|
WHERE table_name = '${tableName}'
|
|
AND column_name = current_column
|
|
) THEN
|
|
EXECUTE format('ALTER TABLE %I ALTER COLUMN %I ${alterExpression}', '${tableName}', current_column);
|
|
ELSE
|
|
RAISE NOTICE 'Column % does not exist or alteration condition not met.', current_column;
|
|
END IF;`
|
|
})
|
|
|
|
script += `
|
|
END$$;
|
|
`
|
|
|
|
return script
|
|
}
|