在现有的postgres数据库中使用sails.js [英] Using sails.js with an existing postgres database

查看:176
本文介绍了在现有的postgres数据库中使用sails.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将 Sails 用于我们正在开发的应用程序。

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

我正在使用使用水线orm的sails-postgresql适配器。

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

我有一个要连接的现有数据库。

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

如果我使用生成模型来生成模型

在我的模型中,我有

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

如果我浏览到本地主机,则orm会删除中的所有列

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.

谢谢!

推荐答案

<我是Sails-Postgresql的作者。 Sails有一个称为Waterline的ORM,用于管理数据。默认设置假定您要自动迁移数据库以匹配模型属性。因为Postgresql是一个SQL数据库,所以Sails-Postgresql适配器具有一个名为syncable的设置,默认为true。在像redis这样的NoSQL数据库中,这将是错误的。

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.

如果您想自己管理数据库列,则很容易将其关闭。您可以在模型中添加 migrate:safe ,并且在启动Sails时它不会尝试更新数据库架构。

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与Rails中的迁移不一样。它使用自动迁移尝试将其从开发过程中删除,然后将更新的生产模式留给您。

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.

这篇关于在现有的postgres数据库中使用sails.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆