Skip to content

unable to set migration strategy per model #4542

@chestercharles

Description

@chestercharles

Sails version: 1.0.2
Node version: 8.9.4
NPM version: 6.1.0
DB adapter name: sails-disk
DB adapter version: version that ships with sails 1.0.2
Operating system: Windows 8.1 Enterprise


Howdy,

I've started to use Sails v1 for new projects after using v0.12 for many previous projects. In v0.12, I set a migration strategy I wanted to use for my models in config/models.js.

/**
 * Default model settings
 * (sails.config.models)
 */
module.exports.models = {
    migrate: 'drop',
}

For a given model, I could set a different migration strategy in that model file (eg. api/models/Kitten.js) that would override what was in config/models.js.

/**
 * Kitten.js
 *
 * @description :: A model definition.  Represents a database table/collection/etc.
 * @docs        :: https://sailsjs.com/docs/concepts/models-and-orm/models
 */
module.exports = {
    migrate: 'safe',
    attributes: {
       
    }
}

When the server lifted, it would honor this model-specific migration strategy, and leave my kittens data intact.

Is this no longer the default behavior in v1.x? I do not see this on the list of breaking changes when upgrading to v1.

Steps to reproduce (or see this repo):

  1. Generate a new app: sails generate new testapp1
  2. Create a kitten model: sails generate model kitten
  3. Create a puppy model: sails generate model puppy
  4. Set migrate: 'drop' in config/models.js
  5. Start sails with node app.js
  6. Hit http://localhost:1337/kitten/create a couple times to generate some kittens.
  7. Shut down sails
  8. Add migrate: 'safe to api/models/Kitten.js
  9. Start sails with node app.js
  10. Go to http://localhost:1337/kitten... we've lost all the kittens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions