node-sql-migrations
node-sql-migrations copied to clipboard
Programmatical migrate() won't work
When you use require('sql-migrations').migrate(configuration) instead of run() it does not attach adapter. So it breaks with an error: ..../node_modules/sql-migrations/commands/run-migrations-command.js:4 return adapter.appliedMigrations() ^ TypeError: Cannot read property 'appliedMigrations' of undefined
migrate() command requires adapter instance as a 2nd argument as well as rollback()
same issue here
try this:
const { postgresql: config } = require('config')
const path = require('path')
const dbConfig = {
host: config.host, // Database host
port: config.port, // Database port
db: config.database, // Database name
user: config.username, // Database username
password: config.password, // Database password
}
const migrationConfig = {
migrationsDir: path.resolve(__dirname, 'schema_migrations'),
...dbConfig,
adapter: 'pg', // Database adapter: pg, mysql
minMigrationTime: new Date('2018-01-01').getTime(),
}
require('sql-migrations').run(migrationConfig)
npx node ./migrate create xxx npx node ./migrate migrate npx node ./migrate rollback