Fix/workspace health type (#4053)

* fix: memory issue with truncate command

* fix: LINK doesn't have any default value

* fix: Cannot convert LINK to column type.

* fix: handle old column type and add a warn to fix them manually
This commit is contained in:
Jérémy M
2024-02-19 17:28:40 +01:00
committed by GitHub
parent 4a95798411
commit e293abe332
5 changed files with 77 additions and 36 deletions

View File

@ -2,31 +2,35 @@ import console from 'console';
import { connectionSource, performQuery } from './utils';
connectionSource
.initialize()
.then(async () => {
await performQuery(
async function dropSchemasSequentially() {
try {
await connectionSource.initialize();
// Fetch all schemas
const schemas = await performQuery(
`
CREATE OR REPLACE FUNCTION drop_all() RETURNS VOID AS $$
DECLARE schema_item RECORD;
BEGIN
FOR schema_item IN
SELECT subrequest."name" as schema_name
FROM (SELECT n.nspname AS "name"
FROM pg_catalog.pg_namespace n
WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema') as subrequest
LOOP
EXECUTE 'DROP SCHEMA ' || schema_item.schema_name || ' CASCADE';
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
SELECT drop_all ();
`,
'Dropping all schemas...',
SELECT n.nspname AS "schema_name"
FROM pg_catalog.pg_namespace n
WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'
`,
'Fetching schemas...',
);
})
.catch((err) => {
console.error('Error during Data Source initialization:', err);
});
// Iterate over each schema and drop it
// This is to avoid dropping all schemas at once, which would cause an out of shared memory error
for (const schema of schemas) {
await performQuery(
`
DROP SCHEMA IF EXISTS "${schema.schema_name}" CASCADE;
`,
`Dropping schema ${schema.schema_name}...`,
);
}
console.log('All schemas dropped successfully.');
} catch (err) {
console.error('Error during schema dropping:', err);
}
}
dropSchemasSequentially();