ormius
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -43,3 +43,7 @@ const arg = require('arg') | ||
const migrateData = 'const { Migration } = require(\'ormius\')\n' + | ||
'class NewMigration extends Migration {\n' + | ||
'class NewMigration extends Migration {\n\n' + | ||
' constructor() {\n' + | ||
' super()\n' + | ||
` this.modelName='${newModelName}'\n` + | ||
' }\n\n' + | ||
' changes() {\n' + | ||
@@ -114,4 +118,19 @@ ` this.createTable(${JSON.stringify(options.filter(({ type }) => !RELATION_TYPES.includes(type)))})\n` + | ||
console.log(results) | ||
selectOption.close() | ||
}) | ||
ormius.connection.query('SELECT migration FROM migrations', function (error, results) { | ||
if (error) { | ||
console.log('error', error) | ||
throw error | ||
} | ||
const alreadyRanMigrations = results.map(({ migration }) => migration) | ||
const migrationsToRun = dirs.filter(migration => !alreadyRanMigrations.includes(migration)) | ||
migrationsToRun.map(currentMigration => { | ||
console.log(path.join(sourcePath, `${migrateFolder}/${currentMigration}/index.js`)) | ||
const module = require(`../${sourcePath}/migrations/${currentMigration}/index`) | ||
const migrationModel = new module() | ||
migrationModel.setConnection(ormius.connection) | ||
migrationModel.setMigrationId(currentMigration) | ||
migrationModel.changes() | ||
}) | ||
}) | ||
} |
class Migration { | ||
#connection | ||
modelName | ||
migrationId | ||
@@ -8,4 +10,21 @@ setConnection(connection) { | ||
setMigrationId(migrationId) { | ||
this.migrationId = migrationId | ||
} | ||
createTable(newTable) { | ||
console.log(newTable) | ||
const self = this | ||
this.#connection.query(`CREATE TABLE ${this.modelName} (${newTable.map(({ type, name }) => `${name} ${type}`).join(',')})`, function (error) { | ||
if (error) { | ||
console.log('error', error) | ||
throw error | ||
} | ||
self.#connection.query('INSERT INTO migrations (migration) VALUES (?)', [self.migrationId], function (error) { | ||
if (error) { | ||
console.log('error', error) | ||
throw error | ||
} | ||
}) | ||
}) | ||
} | ||
@@ -12,0 +31,0 @@ } |
{ | ||
"name": "ormius", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "author": "Adele Bendayan", |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
19440
487
3