question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running db-migrate programtically

See original GitHub issue

I would like to be able to run db-migrate programmatically, such that all migrations run on start-up of my application.

I have tried to use the Programmable API as described, such as:

var DbMigrate = require('db-migrate'); var dbm = DbMigrate.getInstance(true); dbm.run();

However, I get no such luck with this. I simply get the following error:

[ERROR] TypeError: Cannot read property 'split' of undefined

Any guidance would be great, thanks.

Node version: 4.2.4 NPM version: 2.14.12 db-migrate version: 0.10.0-beta.9 db-migrate-mysql version: 1.1.3

<bountysource-plugin> --- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/30198377-running-db-migrate-programtically?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github). </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
christiaanwesterbeekcommented, May 26, 2017

If you run your app using npm run start, you can add a prestart script to package.json to do the migrations before your app starts. In package.json you would have:

{
  "scripts": {
    "prestart": "db-migrate up",
    "start": "node ./index"
  },
  ...
}
1reaction
wzrdtalescommented, Jan 27, 2016

@HopefulLlama Here is another example project: https://github.com/db-migrate/api-examples

Also please note: The API specification is not yet finished and there are things that are going to be improved, such as using promises on this level and so on. But from the very basic this is a very little example of how it works right now and its very likely that this will also work in the future, but will get easier, hope this helps a bit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Programable API - db-migrate - Read the Docs
Programable API. This API is intended for the usage with db-migrate as a module and consists out of several functions.
Read more >
How to programmatically run sequelize migrations
I dug into the code for the sequelize db:migrate command, ... IMHO, the simplest/best approach is to just run the command in a...
Read more >
How to: Handle Schema Migrations Programmatically - Telerik
The OpenAccessContext exposes a method named GetSchemaHandler that returns the schema handling instance. With the schema handler in hand, there are several ...
Read more >
Running migrations programmatically for automated tests
Hi guys,. I'm trying to run database migrations programmatically, inside a setUpClass() method, sharing a preconfigured connection, but the migration execution ...
Read more >
How to Run Sequelize Migration Programmatically
Sequelize is a famous promise-based Node.js ORM for relational databases including PostgreSQL, MySQL, etc. Today we will be discussing how we can run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found