Using sails.js with an existing postgres database

筅森魡賤 提交于 2019-12-05 14:48:38

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/17115141/using-sails-js-with-an-existing-postgres-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!