Remove select-builder-pgsql dependency from export-schema.js
parent
809ddfad04
commit
b98797ed49
|
@ -1,24 +1,28 @@
|
||||||
// Экспорт схемы PostgreSQL БД в HTML, GraphViz, SQL
|
// Экспорт схемы PostgreSQL БД в HTML, GraphViz, SQL
|
||||||
// Упоротые случаи не покрывает, только вменяемые
|
// Упоротые случаи не покрывает, только вменяемые
|
||||||
// (c) Vitaliy Filippov 2019+
|
// (c) Vitaliy Filippov 2019+
|
||||||
// Версия: 2020-04-29
|
// Версия: 2020-09-07
|
||||||
|
|
||||||
|
// Установить модуль pg: npm install pg
|
||||||
|
|
||||||
|
// Создать config.json формата:
|
||||||
|
// { db: { host, database, user, password, port }, skip_tables?: RegExp, skip_triggers?: RegExp, skip_functions?: RegExp }
|
||||||
|
|
||||||
|
// HTML:
|
||||||
|
// nodejs export-schema.js config.json html > schema.html
|
||||||
// В docx потом можно перегнать так (open/libreoffice):
|
// В docx потом можно перегнать так (open/libreoffice):
|
||||||
// soffice --headless --infilter=writerglobal8_HTML --convert-to docx:"MS Word 2007 XML" --outdir . schema.html
|
// soffice --headless --infilter=writerglobal8_HTML --convert-to docx:"MS Word 2007 XML" --outdir . schema.html
|
||||||
|
|
||||||
// Graphviz:
|
// Graphviz:
|
||||||
// nodejs export-schema.js server-config.json dot > schema.dot
|
// nodejs export-schema.js config.json dot > schema.dot
|
||||||
// Потом перегнать в SVG:
|
// Потом перегнать в SVG:
|
||||||
// dot -Tsvg schema.dot
|
// dot -Tsvg schema.dot
|
||||||
|
|
||||||
// SQL (воссоздать начальные определения таблиц, индексов, триггеров, функций и агрегатов без pg_dump-ного мусора):
|
// SQL (воссоздать начальные определения таблиц, индексов, триггеров, функций и агрегатов без pg_dump-ного мусора):
|
||||||
// nodejs export-schema.js server-config.json sql <DIRECTORY>
|
// nodejs export-schema.js config.json sql <DIRECTORY>
|
||||||
|
|
||||||
// server-config.json:
|
|
||||||
// { db: { host, database, user, password, port }, skip_tables?: RegExp, skip_triggers?: RegExp, skip_functions?: RegExp }
|
|
||||||
|
|
||||||
const fsp = require('fs').promises || require('../lib/fsp.js');
|
const fsp = require('fs').promises || require('../lib/fsp.js');
|
||||||
const SQL = require('../lib/select-builder-pgsql.js');
|
const pg = require('pg');
|
||||||
|
|
||||||
const columninfo = (ver) => `select distinct on (c.relname, a.attnum, a.attname, a.attnotnull, t.typname)
|
const columninfo = (ver) => `select distinct on (c.relname, a.attnum, a.attname, a.attnotnull, t.typname)
|
||||||
c.relname as table,
|
c.relname as table,
|
||||||
|
@ -107,15 +111,16 @@ where n.nspname = 'public'`;
|
||||||
|
|
||||||
async function run()
|
async function run()
|
||||||
{
|
{
|
||||||
const config = JSON.parse(await fsp.readFile(process.argv[2] || '../server-config.json', { encoding: 'utf-8' }));
|
const config = JSON.parse(await fsp.readFile(process.argv[2] || '../config.json', { encoding: 'utf-8' }));
|
||||||
const format = process.argv[3] || 'html';
|
const format = process.argv[3] || 'html';
|
||||||
const dbh = new SQL.Connection(config.db);
|
const dbh = new pg.Client(config.db);
|
||||||
const pg_ver = await dbh.select('show server_version_num', SQL.MS_VALUE);
|
await dbh.connect();
|
||||||
const columns = await dbh.select(columninfo(pg_ver), SQL.MS_HASH);
|
const pg_ver = (await dbh.query('show server_version_num')).rows[0]['server_version_num'];
|
||||||
let indexes = await dbh.select(indexinfo, SQL.MS_HASH);
|
const columns = (await dbh.query(columninfo(pg_ver))).rows;
|
||||||
const triggers = await dbh.select(triggerinfo, SQL.MS_HASH);
|
let indexes = (await dbh.query(indexinfo)).rows;
|
||||||
const funcs = await dbh.select(funcinfo(pg_ver), SQL.MS_HASH);
|
const triggers = (await dbh.query(triggerinfo)).rows;
|
||||||
const aggs = await dbh.select(agginfo, SQL.MS_HASH);
|
const funcs = (await dbh.query(funcinfo(pg_ver))).rows;
|
||||||
|
const aggs = (await dbh.query(agginfo)).rows;
|
||||||
const tables = {};
|
const tables = {};
|
||||||
let skip = config.skip_tables && new RegExp(config.skip_tables, 'i');
|
let skip = config.skip_tables && new RegExp(config.skip_tables, 'i');
|
||||||
for (const col of columns)
|
for (const col of columns)
|
||||||
|
|
|
@ -7,11 +7,9 @@
|
||||||
"name": "mw-select-builder",
|
"name": "mw-select-builder",
|
||||||
"description": "MediaWiki-like select builder",
|
"description": "MediaWiki-like select builder",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pg": "^7.9.0",
|
"pg": "^7.18.2",
|
||||||
"pg-escape": "^0.2.0"
|
"pg-escape": "^0.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {},
|
||||||
},
|
"scripts": {}
|
||||||
"scripts": {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue