Gayan Hewa
Gayan Hewa

Reputation: 2397

SailsJS Models and Migrations

I am having a hard time figuring out if SailJS ships with a Migration Manager to use Models to generate the table migrations or if we need to use something like db-migrate with sail-migrate to manage this ?

Upvotes: 4

Views: 503

Answers (2)

arkoak
arkoak

Reputation: 2497

Sails comes with its built in auto-migration feature (part of waterline) that can update tables based on predefined strategy once there is a change in model. However its important to note that this is not like the full migration you can do including any default data using db-migrate. If you need the more advanced features of migrations and want a more controlled db, it would be useful to use sail-migrations in addition to or in place of auto-migration. Using auto-migration or not depends on your decision as to how you want to use the migrations.

You can find relevant configuration for Waterline here

Upvotes: 2

Gayan Hewa
Gayan Hewa

Reputation: 2397

Apparently sailsjs 0.11v works out of the box. My initial setup had two mode npms that handle the migrations and I think one of them conflicted with the backed in module. After a clean install the below models will create the appropriate tables when we do a sails lift.

module.exports = {
 connection: 'db_adapter',
  tableName: 'users',
  attributes: {
    id: {
      type: 'integer',
      unique: true,
      primaryKey: true
    },
    username: {
      type: 'string'
    },
    password: {
      type: 'string'
    },
    email: {
      type: 'email',
      unique: true
    }
  }
};

Upvotes: 0

Related Questions