graphviz to database structure parser
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user