Performance improvement to dev xp (#9294)

The DX is not great when you need to do a lot of database
resets/command.

Should we disable Typescript validation to speed things up? With this
and caching database:reset takes 1min instead of 2 on my machine.


See also: https://github.com/typeorm/typeorm/issues/4136

And #9291 / #9293

---------

Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
Félix Malfait
2025-01-01 17:28:45 +01:00
committed by GitHub
parent 3544a49702
commit 85c04c8931
55 changed files with 255 additions and 149 deletions

View File

@ -30,6 +30,11 @@ rawDataSource
'create extension "uuid-ossp"',
);
// We paused the work on FDW
if (process.env.IS_FDW_ENABLED !== 'true') {
return;
}
await performQuery(
'CREATE EXTENSION IF NOT EXISTS "postgres_fdw"',
'create extension "postgres_fdw"',

View File

@ -8,32 +8,30 @@ async function dropSchemasSequentially() {
try {
await rawDataSource.initialize();
// Fetch all schemas
// Fetch all schemas excluding the ones we want to keep
const schemas = await performQuery(
`
SELECT n.nspname AS "schema_name"
FROM pg_catalog.pg_namespace n
WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'
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...',
);
// 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) {
if (
schema.schema_name === 'metric_helpers' ||
schema.schema_name === 'user_management' ||
schema.schema_name === 'public'
) {
continue;
}
const batchSize = 10;
await performQuery(
`
DROP SCHEMA IF EXISTS "${schema.schema_name}" CASCADE;
`,
`Dropping schema ${schema.schema_name}...`,
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}...`,
),
),
);
}