diff --git a/api/src/database/run-seed.ts b/api/src/database/run-seed.ts index 2910538bef..6cb799f53a 100644 --- a/api/src/database/run-seed.ts +++ b/api/src/database/run-seed.ts @@ -2,8 +2,8 @@ import Knex, { ColumnBuilder } from 'knex'; import fse from 'fs-extra'; import path from 'path'; import yaml from 'js-yaml'; -import { types } from '../types'; -import { isObject, merge } from 'lodash'; +import { types, Item } from '../types'; +import { isObject, merge, reduce } from 'lodash'; type SeedData = { tables?: { @@ -106,8 +106,30 @@ export default async function runSeed(knex: Knex, seed: string) { return merge({}, defaults, row); }); - await transaction(table).insert(dataWithDefaults); + const chunks = chunkArray(dataWithDefaults, 25); + + for (const chunk of chunks) { + await transaction(table).insert(chunk); + } } } }); } + +function chunkArray(array: Item[], chunkSize: number) { + return reduce( + array, + (result: Item[][], value) => { + let lastChunk: Item[] = result[result.length - 1]; + + if (lastChunk.length < chunkSize) { + lastChunk.push(value); + } else { + result.push([value]); + } + + return result; + }, + [[]] + ); +} diff --git a/packages/create-directus-project/lib/index.js b/packages/create-directus-project/lib/index.js index e5636f6ba5..bfed9a4aec 100644 --- a/packages/create-directus-project/lib/index.js +++ b/packages/create-directus-project/lib/index.js @@ -62,6 +62,8 @@ async function create(directory) { await execa('npx', ['directus', 'init'], { cwd: rootPath, - stdin: 'ignore', + stdio: 'inherit' }); + + process.exit(1); }