gristlabs_grist-core/app/server/generateInitialDocSql.ts

68 lines
2.8 KiB
TypeScript
Raw Normal View History

import { ActiveDoc } from 'app/server/lib/ActiveDoc';
import { create } from 'app/server/lib/create';
import { DocManager } from 'app/server/lib/DocManager';
import { makeExceptionalDocSession } from 'app/server/lib/DocSession';
import { DocStorageManager } from 'app/server/lib/DocStorageManager';
import { createDummyTelemetry } from 'app/server/lib/GristServer';
import { PluginManager } from 'app/server/lib/PluginManager';
import * as childProcess from 'child_process';
import * as fse from 'fs-extra';
import * as util from 'util';
const execFile = util.promisify(childProcess.execFile);
// tslint:disable:no-console
/**
* Output to stdout typescript code containing SQL strings for creating an empty document.
* The code is of the form:
* export const GRIST_DOC_SQL = <sql code to create a completely empty document>;
* export const GRIST_DOC_WITH_TABLE1_SQL = <sql code to create a document with Table1>;
* Only tables managed by the data engine are included. Any _gristsys_ tables are excluded.
*/
export async function main(baseName: string) {
console.log("/*** THIS FILE IS AUTO-GENERATED BY app/server/generateInitialDocSql.ts ***/");
console.log("");
console.log("/* eslint-disable max-len */");
for (const version of ['DOC', 'DOC_WITH_TABLE1'] as const) {
const storageManager = new DocStorageManager(process.cwd());
const pluginManager = new PluginManager();
const fname = storageManager.getPath(baseName);
if (await fse.pathExists(fname)) {
await fse.remove(fname);
}
const docManager = new DocManager(storageManager, pluginManager, null as any, {
create,
getTelemetry() { return createDummyTelemetry(); },
} as any);
const activeDoc = new ActiveDoc(docManager, baseName);
const session = makeExceptionalDocSession('nascent');
await activeDoc.createEmptyDocWithDataEngine(session);
if (version === 'DOC_WITH_TABLE1') {
await activeDoc.addInitialTable(session);
}
// Remove all _gristsys_ tables, since creation of these tables is handled by DocStorage,
// not data engine.
const tables = await activeDoc.docStorage.all("SELECT name FROM sqlite_master WHERE" +
" type = 'table' AND" +
" name LIKE '_gristsys_%'");
for (const table of tables) {
await activeDoc.docStorage.exec(`DROP TABLE ${table.name}`);
}
console.log("");
console.log("export const GRIST_" + version + "_SQL = `");
console.log((await execFile('sqlite3', [baseName + '.grist', '.dump'])).stdout.trim());
console.log("`;");
await activeDoc.shutdown();
await docManager.shutdownAll();
await storageManager.closeStorage();
}
}
if (require.main === module) {
main(process.argv[2]).catch(e => {
(core) get all tests working under python3/gvisor Summary: This verifies that all existing tests are capable of running under python3/gvisor, and fixes the small issues that came up. It does not yet activate python3 tests on all diffs, only diffs that specifically request them. * Adds a suffix in test names and output directories for tests run with PYTHON_VERSION=3, so that results of the same test run with and without the flag can be aggregated cleanly. * Adds support for checkpointing to the gvisor sandbox adapter. * Prepares a checkpoint made after grist python code has loaded in the gvisor sandbox. * Changes how `DOC_URL` is passed to the sandbox, since it can no longer be passed in as an environment variable when using checkpoints. * Uses the checkpoint to speed up tests using the gvisor sandbox, otherwise a lot of tests need more time (especially on mac under docker). * Directs jenkins to run all tests with python2 and python3 when a new file `buildtools/changelogs/python.txt` is touched (this diff counts as touching that file). * Tweaks miscellaneous tests - some needed fixes exposed by slightly different timing - a small number actually give different results in py3 (removal of `u` prefixes). - some needed a little more time The DOC_URL change is not the ultimate solution we want for DOC_URL. Eventually it should be a variable that gets updated, like the date perhaps. This is just a small pragmatic change to preserve existing behavior. Tests are run mindlessly as py3, and for some tests it won't change anything (e.g. if they do not use NSandbox). Tests are not run in parallel, doubling overall test time. Checkpoints could be useful in deployment, though this diff doesn't use them there. The application of checkpoints doesn't check for other configuration like 3-versus-5-pipe that we don't actually use. Python2 tests run using pynbox as always for now. The diff got sufficiently bulky that I didn't tackle running py3 on "regular" diffs in it. My preference, given that most tests don't appear to stress the python side of things, would be to make a selection of the tests that do and a few wild cards, and run those tests on both pythons rather then all of them. For diffs making a significant python change, I'd propose touching buildtools/changelogs/python.txt for full tests. But this is a conversation in progress. A total of 6886 tests ran on this diff. Test Plan: this is a step in preparing tests for py3 transition Reviewers: dsagal Reviewed By: dsagal Subscribers: dsagal Differential Revision: https://phab.getgrist.com/D3066
2021-10-18 17:37:51 +00:00
console.error(e);
});
}