/
githubmirror
/
strapi
Обзор
Документация
Войти
/
githubmirror
/
strapi
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
tests/utils/get-db-counts.js
40 строк
1 KB
Ben Irvin
test(cli): document --exclude files semantics in data-transfer tests (#26913)
09 июл 2026, 16:22
Не верифицирован
09 июл 2026, 16:22
c984bc2
Код
Авторство
О чём код?
'use strict'; /** * Outputs JSON with table counts and sample IDs for the export/import roundtrip test. * Run with cwd = test app path (so .tmp/data.db and node_modules/better-sqlite3 are found). */ const path = require('path'); const dbPath = path.join(process.cwd(), '.tmp', 'data.db'); let output; try { // eslint-disable-next-line import/no-extraneous-dependencies -- run in test app context const Database = require('better-sqlite3'); const db = new Database(dbPath, { readonly: true }); const articles = db.prepare('SELECT COUNT(*) as c FROM articles').get(); const categories = db.prepare('SELECT COUNT(*) as c FROM categories').get(); const uploadFiles = db.prepare('SELECT COUNT(*) as c FROM files').get(); const uploadFolders = db.prepare('SELECT COUNT(*) as c FROM upload_folders').get(); const articleIds = db .prepare('SELECT id FROM articles ORDER BY id') .all() .map((r) => r.id); const categoryIds = db .prepare('SELECT id FROM categories ORDER BY id') .all() .map((r) => r.id); db.close(); output = { articles: articles.c, categories: categories.c, uploadFiles: uploadFiles.c, uploadFolders: uploadFolders.c, articleIds, categoryIds, }; } catch (err) { output = { error: err.message }; } console.log(JSON.stringify(output));