# Introduction Following https://github.com/twentyhq/twenty/pull/12068 Related with https://github.com/twentyhq/core-team-issues/issues/975 We're enabling `noImplicitAny` handled few use case manually, added a `ts-expect-error` to the others, we should plan to handle them in the future
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import console from 'console';
|
|
|
|
import { rawDataSource } from 'src/database/typeorm/raw/raw.datasource';
|
|
|
|
import { performQuery } from './utils';
|
|
|
|
async function dropSchemasSequentially() {
|
|
try {
|
|
await rawDataSource.initialize();
|
|
|
|
// Fetch all schemas excluding the ones we want to keep
|
|
const schemas =
|
|
(await performQuery<{ schema_name: string }[]>(
|
|
`
|
|
SELECT n.nspname AS "schema_name"
|
|
FROM pg_catalog.pg_namespace n
|
|
WHERE n.nspname !~ '^pg_'
|
|
AND n.nspname <> 'information_schema'
|
|
AND n.nspname NOT IN ('metric_helpers', 'user_management', 'public')
|
|
`,
|
|
'Fetching schemas...',
|
|
)) ?? [];
|
|
|
|
const batchSize = 10;
|
|
|
|
for (let i = 0; i < schemas.length; i += batchSize) {
|
|
const batch = schemas.slice(i, i + batchSize);
|
|
|
|
await Promise.all(
|
|
batch.map((schema) =>
|
|
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();
|