1

Im trying to deploy my Sails JS application onto a standard Ubuntu 14.04.3 VM.

Right now, Im having trouble with connecting my SailsJS instance with PostgreSQL server instance. Both the SailsJS server and the PostgreSQL server are running in the same VM.

I am getting the following output from my Sails JS log:

MySailsServer-0 Sending 500 ("Server Error") response:
 Error (E_UNKNOWN) :: Encountered an unexpected error
error: relation "recording" does not exist
    at Connection.parseE (/home/vmuser/MySailsServer/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:539:11)
    at Connection.parseMessage (/home/vmuser/MySailsServer/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:366:17)
    at Socket.<anonymous> (/home/vmuser/MySailsServer/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:105:22)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at Socket.Readable.push (_stream_readable.js:110:10)
    at TCP.onread (net.js:523:20)

It seems as though my Recording model is not being created in the database. I checked the Postgre logs for more info. Here's the output of cat /var/log/postgresql/postgresql-9.3-main.log:

2015-10-17 14:46:13 CDT ERROR:  relation "recording" does not exist at character 491
2015-10-17 14:46:13 CDT STATEMENT:  SELECT "recording"."startTime", "recording"."endTime", "recording"."filename", "recording"."id", "recording"."createdAt", "recording"."updatedAt", "recording"."section", "__section"."startTime" AS "section___startTime", "__section"."endTime" AS "section___endTime", "__section"."name" AS "section___name", "__section"."id" AS "section___id", "__section"."createdAt" AS "section___createdAt", "__section"."updatedAt" AS "section___updatedAt", "__section"."course" AS "section___course" FROM "recording" AS "recording"  LEFT OUTER JOIN "section" AS "__section" ON "recording"."section" = "__section"."id"  LIMIT 30 OFFSET 0

Any clue on why none of the models I have declared under api/models/ are being made into tables in PostgreSQL?

Here is the configuration I have under config/connections.js:

  postgresqlServer: {
    adapter: 'sails-postgresql',
    host: 'localhost',
    user: <username>,
    password: <password>,
    database: <db_name>,
    schema: true
  }

Under config/models.js I have put:

module.exports.models = {
  connection: 'postgresqlServer',
  migrate: 'alter'
};

I can't see what Im doing incorrectly. It seems like my SailsJS Models aren't being translated into PostgreSQL tables and Im not sure why. Any help is greatly appreciated!

sourdesi
  • 360
  • 1
  • 4
  • 21
  • Try `sails lift --silly` to see if sails is logging anything interesting while building the models. Also worth noting if you're using the `--prod` flag, sails always runs in safe mode in prod, and will not migrate changes to the database. – coagmano Oct 18 '15 at 02:49
  • @FrederickStark interesting...I assumed that with `--prod` it would at least create the tables if they haven't at least been made but perhaps not. Any way of specifying that I do want it to run with the production configuration but also not just be in safe mode? Its the initial deployment so there's no data to lose yet. – sourdesi Oct 18 '15 at 04:24
  • Not sure. I usually run `sails lift` before `sails lift --prod` as part of my build process – coagmano Oct 18 '15 at 04:27
  • @FrederickStark Thanks! Turns out deploying with the `--prod` doesn't in fact set up the tables. I had to run `sails lift` without the `--prod` option like you mentioned to create the tables. – sourdesi Oct 19 '15 at 01:34
  • Great! Mind if I add this as the answer in case other folks find this Q (really, it's for the internet points)? – coagmano Oct 19 '15 at 01:39

1 Answers1

3

If you're lifting in production mode with sails lift --prod, sails forces waterline into 'safe' mode. In safe mode, no database alterations are done, including the initial setup of tables.

To get the models to build beforehand, you need to run sails lift without the prod flag. Ideally this is part of your build process, if you use a deploy script.

coagmano
  • 5,542
  • 1
  • 28
  • 41