sails.jssails-postgresql

Sails - Postgres - Unable to lift


Issue : Unable to lift sails project (Initially written for mysql, Change adapter and settings to postgres)

Error :

info: ·• Auto-migrating...  (drop)
error: A hook (`orm`) failed to load!
error: 
error: error: syntax error at or near "ON"
   at Connection.parseE (*/node_modules/pg/lib/connection.js:569:11)
   at Connection.parseMessage (*/node_modules/pg/lib/connection.js:396:17)
   at Socket.<anonymous> (*/node_modules/pg/lib/connection.js:132:22)
   at Socket.emit (events.js:189:13)
   at Socket.EventEmitter.emit (domain.js:441:20)
   at addChunk (_stream_readable.js:284:12)
   at readableAddChunk (_stream_readable.js:265:11)
   at Socket.Readable.push (_stream_readable.js:220:10)
   at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

error: Could not load Sails app.

Adapter Response :

Error details:

{ error: syntax error at or near "ON"
    at Connection.parseE (*/node_modules/pg/lib/connection.js:569:11)
    at Connection.parseMessage (*/node_modules/pg/lib/connection.js:396:17)
    at Socket.<anonymous> (*/node_modules/pg/lib/connection.js:132:22)
    at Socket.emit (events.js:189:13)
    at Socket.EventEmitter.emit (domain.js:441:20)
    at addChunk (_stream_readable.js:284:12)
    at readableAddChunk (_stream_readable.js:265:11)
    at Socket.Readable.push (_stream_readable.js:220:10)
    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
  name: 'error',
  length: 92,
  severity: 'ERROR',
  code: '42601',
  detail: undefined,
  hint: undefined,
  position: '191',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'scan.l',
  line: '1134',
  routine: 'scanner_yyerror' }

I have tried changing the datastore settings, trying both localhost and remote deployment, username and password, changing roles, database privileges. But nothing seem to fix this.

Am i missing something?

   adapter: 'sails-postgresql',
   url: 'postgresql://postgres:postgres@localhost:5432/postgres',

A model type :


module.exports = {
    tableName: 'roles',
    attributes: {
        name: {
            type: "string",
            required: true,
            columnType: "varchar(255) COLLATE utf8_unicode_ci NOT NULL"
        },
        company_id: {
            type: "number",
            required: true,
            columnType: "int(11) NOT NULL"
        },
        mobile_user: {
            type: "number",
            required: false,
            defaultsTo: 0,
            columnType: "tinyint(1) NOT NULL DEFAULT '0'"
        },
        enforcement: {
            type: "number",
            required: false,
            defaultsTo: 0,
            columnType: "tinyint(1) NOT NULL DEFAULT '0'"
        },
    }
};

I am migrating my db from mysql to postgre. Anyone faced same issue?


Solution

  • After experimenting with more settings and changes. I found that the issue was caused by Models, i.e. By changing all datatypes and conditions mentioned in columnType of a model from MySQL to PostgresSQL, it worked like a charm.

    Example : tinyint(1) -> smallint, removing COLLATE condition etc