graphviz to database structure parser

This commit is contained in:
2020-02-21 11:38:53 +01:00
parent 33c34b18f7
commit 285dbf2b5a
3 changed files with 202 additions and 9 deletions

View File

@ -136,7 +136,7 @@ function create_table_function (table) {
*
* @param {any} knex database connection
* @returns {Promise} result
*/
*/
function create_${table.name} (knex) {
return knex.schema.createTable ('${table.name}', (table) => {
${table.columns
@ -190,23 +190,25 @@ async function create_migration (file_path) {
const tables = await get_tables (file_path);
const functions = tables.map ((tab) => create_table_function (tab));
const file = `${functions.join ('\n\n')}
const file = `'use strict';
/*
${functions.join ('\n\n')}
/**
* run migration
*
* @param {any} knex db connection
*/
${create_up_function (tables)}
/*
/**
* revert migration
*
* @param {any} knex db connection
*/
function down () {}
function down () {
// noop
}
module.exports = { up, down }
module.exports = { up, down };
`;
return file;
}

View File

@ -25,7 +25,7 @@ async function run (folder, args) {
const graph = path.join (folder, args[0]);
const migration = path.join (folder, args[1]);
const db_migration = dot_parser.create_migration (graph);
const db_migration = await dot_parser.create_migration (graph);
await fs.writeFile (migration, db_migration, 'utf-8');
}