feat(region): Add admin region get + list endpoints (#6322)
**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>
This commit is contained in:
32
packages/utils/src/common/alter-columns-helper.ts
Normal file
32
packages/utils/src/common/alter-columns-helper.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./alter-columns-helper"
|
||||
export * from "./array-difference"
|
||||
export * from "./build-query"
|
||||
export * from "./camel-to-snake-case"
|
||||
@@ -45,3 +46,4 @@ export * from "./to-pascal-case"
|
||||
export * from "./transaction"
|
||||
export * from "./upper-case-first"
|
||||
export * from "./wrap-handler"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user