Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does sails.js handle database migrations when working with a schema database?

I'm currently using postgresql for a database.

I come from more of a rails background where we create a migration and then run rake db:migrate to migrate the database.

How can I do something similar in sails.js? Do I need to?

like image 420
monty_lennie Avatar asked Jun 25 '15 17:06

monty_lennie


1 Answers

With an unmodified config/models.js file each time you sails lift it will prompt you for one of 3 possible options, detailed in the docs here:

  1. safe -- No migrations are run
  2. alter -- Sails will attempt to migrate the data as intelligently as possible
  3. drop -- Sails will drop the database and run all of the migrations. Equivalent to rake db: drop db:migrate

It's recommended that you only use safe in production, and run you migrations either by hand, or using one of the following modules (non-exhaustive list):

  • https://github.com/building5/sails-db-migrate
  • https://github.com/BlueHotDog/sails-migrations

In development however you're generally safe to modify your config/models.js file to set the value of the migrate attribute to the alter setting.

like image 87
brittonjb Avatar answered Sep 28 '22 08:09

brittonjb