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

I am absolutely new to Postgres. I have previously set up a sails app using MongoDB as the underlying database. It was quite simple. However, with postgres, I am facing some issues.

I am following this tutorial

Here are the contents of my config/local.js file

//config/local.js

module.exports = {

  port: process.env.PORT || 1337,

  environment: process.env.NODE_ENV || 'development',

  adapters: {

    'default': 'postgres',

    postgres: {
      module   : 'sails-postgresql',
      host     : 'localhost',
      port     : 5432,
      user     : 'root',
      password : '',
      database : 'postgres',

      schema: true //This makes sure that sails matches 
                   //the database schema to your models.
    }

  }

};

When I run sails lift with verbose logs, The process gets stuck at the following stage:

verbose: Grunt :: 
Running "sails-linker:devTplJADE" (sails-linker) task

verbose: Grunt :: 

verbose: Grunt :: Running "watch" task

verbose: Grunt :: Waiting...

Any help ?

EDIT:

It's working now. Had to create a unix user with the same name as postgre user and db.

Now the porblem is, I want to create a table with two columns

CREATE TABLE users ( user_id serial, user_name varchar(50) );

I create this schema in postgre. The when I submit a POST request, it overrides the schema. I don't want that to happen. Any clues?

share|improve this question

1 Answer 1

You should create the schema in the models folder. In there, you create a file for each model with the proper attributes. When you sails lift, Sails will populate your database for you.

Check out http://sailsjs.org/#!documentation/models for some more information.

share|improve this answer
    
Found that setting migrate: 'safe' will keep the existing schema if the table is already defined –  mandeep_m91 May 23 '14 at 11:43
    
That works as well. Though if you do create new models in the future, it's probably better to do them through Sails rather than manually creating them in SQL. –  Chetan Shenoy May 23 '14 at 14:46

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.