mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) updates from grist-core
This commit is contained in:
41
test/server/generateInitialDocSql.ts
Normal file
41
test/server/generateInitialDocSql.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { getAppRoot } from 'app/server/lib/places';
|
||||
import { createTmpDir } from 'test/server/docTools';
|
||||
import * as testUtils from 'test/server/testUtils';
|
||||
|
||||
import { assert } from 'chai';
|
||||
import * as childProcess from 'child_process';
|
||||
import * as fse from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
import * as util from 'util';
|
||||
|
||||
const execFile = util.promisify(childProcess.execFile);
|
||||
|
||||
describe('generateInitialDocSql', function() {
|
||||
this.timeout(10000);
|
||||
|
||||
let tmpDir: string;
|
||||
|
||||
testUtils.setTmpLogLevel('fatal');
|
||||
|
||||
before(async function() {
|
||||
tmpDir = await createTmpDir();
|
||||
});
|
||||
|
||||
it('confirms schema and sql files are up to date (run "yarn run generate:schema:ts" on failure)', async function() {
|
||||
let root = getAppRoot();
|
||||
if (await fse.pathExists(path.join(root, 'core'))) {
|
||||
root = path.join(root, 'core');
|
||||
}
|
||||
const newSchemaTs = path.join(tmpDir, 'schema.ts');
|
||||
const newSqlTs = path.join(tmpDir, 'sql.ts');
|
||||
const currentSchemaTs = path.join(root, 'app/common/schema.ts');
|
||||
const currentSqlTs = path.join(root, 'app/server/lib/initialDocSql.ts');
|
||||
await execFile(path.join(getAppRoot(), 'buildtools/update_schema.sh'), [
|
||||
newSchemaTs, newSqlTs,
|
||||
], { env: process.env });
|
||||
assert.equal((await fse.readFile(newSchemaTs)).toString(),
|
||||
(await fse.readFile(currentSchemaTs)).toString());
|
||||
assert.equal((await fse.readFile(newSqlTs)).toString(),
|
||||
(await fse.readFile(currentSqlTs)).toString());
|
||||
});
|
||||
});
|
||||
7
test/setupPaths.js
Normal file
7
test/setupPaths.js
Normal file
@@ -0,0 +1,7 @@
|
||||
// enhance require() to support project paths and typescript.
|
||||
const path = require('path');
|
||||
const appModulePath = require('app-module-path');
|
||||
const root = path.dirname(__dirname);
|
||||
appModulePath.addPath(path.join(root, "_build"));
|
||||
appModulePath.addPath(path.join(root, "_build/core"));
|
||||
appModulePath.addPath(path.join(root, "_build/ext"));
|
||||
4
test/upgradeDocument
Executable file
4
test/upgradeDocument
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('./setupPaths');
|
||||
require('test/upgradeDocumentImpl').main().catch(e => console.error(String(e)));
|
||||
43
test/upgradeDocumentImpl.ts
Normal file
43
test/upgradeDocumentImpl.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Upgrade one or more documents (both the DocStorage and schema migrations).
|
||||
*
|
||||
* Usage:
|
||||
* test/upgradeDocument <docPaths...>
|
||||
*/
|
||||
import {copyFile} from 'app/server/lib/docUtils';
|
||||
import {createDocTools} from 'test/server/docTools';
|
||||
import log from 'app/server/lib/log';
|
||||
import * as fs from "fs";
|
||||
|
||||
export async function main() {
|
||||
const docPaths = process.argv.slice(2);
|
||||
if (docPaths.length === 0) {
|
||||
console.log(`Usage:\n test/upgradeDocument path/to/doc.grist ...\n`);
|
||||
throw new Error("Document argument required");
|
||||
}
|
||||
for (const docPath of docPaths) {
|
||||
if (!docPath.endsWith('.grist')) {
|
||||
throw new Error(`Document path should have .grist extension: ${docPath}`);
|
||||
}
|
||||
if (!fs.existsSync(docPath)) {
|
||||
throw new Error(`Document path doesn't exist: ${docPath}`);
|
||||
}
|
||||
}
|
||||
|
||||
const prevLogLevel = log.transports.file.level;
|
||||
log.transports.file.level = 'warn';
|
||||
const docTools = createDocTools();
|
||||
await docTools.before();
|
||||
try {
|
||||
for (const docPath of docPaths) {
|
||||
console.log(`Upgrading ${docPath}`);
|
||||
const activeDoc = await docTools.loadLocalDoc(docPath);
|
||||
await activeDoc.waitForInitialization();
|
||||
await activeDoc.shutdown();
|
||||
await copyFile(docTools.getStorageManager().getPath(activeDoc.docName), docPath);
|
||||
}
|
||||
} finally {
|
||||
await docTools.after();
|
||||
log.transports.file.level = prevLogLevel;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user