diff --git a/packages/cli/commands/start.ts b/packages/cli/commands/start.ts index b6f0a39b3e..c40c0e6392 100644 --- a/packages/cli/commands/start.ts +++ b/packages/cli/commands/start.ts @@ -12,6 +12,7 @@ import { ActiveWorkflowRunner, CredentialsOverwrites, CredentialTypes, + DatabaseType, Db, ExternalHooks, GenericHelpers, @@ -156,6 +157,15 @@ export class Start extends Command { // Wait till the database is ready await startDbInitPromise; + const dbType = await GenericHelpers.getConfigValue('database.type') as DatabaseType; + + if (dbType === 'sqlite') { + const shouldRunVacuum = config.get('database.sqlite.executeVacuumOnStartup') as number; + if (shouldRunVacuum) { + Db.collections.Execution!.query("VACUUM;"); + } + } + if (flags.tunnel === true) { this.log('\nWaiting for tunnel ...'); diff --git a/packages/cli/config/index.ts b/packages/cli/config/index.ts index 5cbacddf85..0793e8c7f1 100644 --- a/packages/cli/config/index.ts +++ b/packages/cli/config/index.ts @@ -124,6 +124,14 @@ const config = convict({ env: 'DB_MYSQLDB_USER', }, }, + sqlite: { + executeVacuumOnStartup: { + doc: 'Runs VACUUM operation on startup to rebuild the database. Reduces filesize and optimizes indexes. WARNING: This is a long running blocking operation. Will increase start-up time.', + format: Boolean, + default: false, + env: 'DB_SQLITE_VACUUM_ON_STARTUP', + }, + }, }, credentials: {