There was no script for updating typescript schema information after a python-based document migration. Moving one in here, along with its test. Tweaked the code slightly to work with grist-core's directory structure. Also fixed a formatting error in mocha calls that was resulting in some root tests not running.pull/403/head
parent
6b5c2f8d4b
commit
e5e44c786a
@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Regenerates typescript files with schema and sql for grist documents.
|
||||||
|
# This needs to run whenever the document schema is changed in the data
|
||||||
|
# engine, maintained in python code. It propagates the schema information
|
||||||
|
# to a typescript file, and updates SQL code for initializing new documents.
|
||||||
|
#
|
||||||
|
# To preview what it will do, call as:
|
||||||
|
# buildtools/update_schema.sh schema.ts sql.ts
|
||||||
|
# This will put schema.ts and sql.ts files in your working directory.
|
||||||
|
# Run without any arguments to modify application files.
|
||||||
|
# buildtools/update_schema.sh
|
||||||
|
# (you can see the differences with git diff if in a git repository).
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
schema_ts=$1
|
||||||
|
sql_ts=$2
|
||||||
|
if [[ -z "$schema_ts" ]]; then
|
||||||
|
# Default to regenerating regular suspects.
|
||||||
|
schema_ts=app/common/schema.ts
|
||||||
|
sql_ts=app/server/lib/initialDocSql.ts
|
||||||
|
fi
|
||||||
|
if [[ -z "$sql_ts" ]]; then
|
||||||
|
echo "Need both a schema and sql target"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Prepare new version of schema file.
|
||||||
|
# Define custom python path locally, do not let it bleed over to node, since it
|
||||||
|
# could interfere with sandbox operation.
|
||||||
|
if [[ -e sandbox_venv3/bin/python ]]; then
|
||||||
|
# Use our virtual env if available.
|
||||||
|
PYTHON=sandbox_venv3/bin/python
|
||||||
|
else
|
||||||
|
# Fall back on system.
|
||||||
|
PYTHON=python
|
||||||
|
fi
|
||||||
|
PYTHONPATH=sandbox/grist:sandbox/thirdparty $PYTHON -B sandbox/gen_js_schema.py > $schema_ts.tmp
|
||||||
|
|
||||||
|
# Prepare new version of sql file.
|
||||||
|
export NODE_PATH=_build:_build/core:_build/ext
|
||||||
|
BUILD=$(test -e _build/core && echo "_build/core" || echo "_build")
|
||||||
|
node $BUILD/app/server/generateInitialDocSql.js $sql_ts.tmpdoc > $sql_ts.tmp
|
||||||
|
|
||||||
|
rm $sql_ts.tmpdoc.grist
|
||||||
|
mv $schema_ts.tmp $schema_ts
|
||||||
|
mv $sql_ts.tmp $sql_ts
|
@ -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 "./build schema" 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());
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in new issue