Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I was looking at using Sails for an app that we are developing.

I'm using the sails-postgresql adapter which uses the waterline orm.

I have an existing database that I want to connect to.

If I create a model using generate something

and then in my model I have

attributes:{
    title:{type:'String'}
}

If I browse to localhost/something the orm deletes all the columns in the something table except title.

Is there a way to stop it from doing this? This app should not delete columns on this database.

Thanks!

share|improve this question

1 Answer 1

up vote 19 down vote accepted

I am the author of Sails-Postgresql. Sails has an ORM called Waterline that it uses for managing data. The default setting assumes that you would want to auto-migrate your database to match your model attributes. Because Postgresql is a SQL database the Sails-Postgresql adapter has a setting called syncable that defaults to true. This would be false in a NoSQL database like redis.

This is easy to turn off if you want to manage your database columns yourself. You can add migrate: safe to your model and it won't try and update your database schema when you start Sails.

module.exports = {
  adapter: 'postgresql',
  migrate: 'safe',
  attributes: {
    title: { type: 'string' }
  }
};

Sails doesn't have anything like migrations in Rails. It uses auto-migrations to attempt to remove this from your development process and then leaves updating your production schema to you.

share|improve this answer
8  
Is there a configuration to make this true for every model? –  Alex Sep 1 '13 at 18:55
3  
Could up update the documentation to reflect all of the various options? I am new to sails, and have been trying to figure out how to actually USE a model within a controller for the better part of the last hour. Thanks –  Andrew Rhyne Oct 9 '13 at 2:32
    
Since there are no migrations like in Rails, what happens when you need to run a migration that requires data transformation? In Rails, the proper way would be to do this in a migration file, but how would do this in Waterline/Sails? –  Strawberry Feb 19 '14 at 9:11
    
@Alex in Sails v0.10.x, you can use the sails.config.model config in config/model.js to set any property for all models (think of it as the definition of your "base model"). –  mikermcneil Mar 4 '14 at 20:09
    
@Strawberry There is an implementation of Rails-like manual migrations for Sails here: github.com/BlueHotDog/sails-migrations –  mikermcneil Mar 4 '14 at 20:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.