Error on sequelize full text search raw sql query - postgresql

Attempting to use raw sql in sequelize db, not sure why it is not working.
Here is the controller with the query:
const db = require("../../models");
const Book = db.book;
const User = db.user;
const Sequelize = require('sequelize');
const { sequelize } = require('../../models/index.js');
exports.getAllBooks = async (req, res) => {
console.log('query: ', req.query);
let books;
if (Object.keys(req.query).length === 0) {
books = await Book.findAll();
res.json(books);
} else {
[books, metadata] = await sequelize.query(`
SELECT ('title')
FROM Book
WHERE searchable ## to_tsquery(${req.query});
`);
res.json(books);
}
};
get request to
http://localhost:8080/api/books?searchable=humor
the tsvector column in the db is named "searchable"
the log response:
Server is running on port 8080.
query: { searchable: 'humor' }
Executing (default): SELECT ('title')
FROM Book
WHERE searchable ## to_tsquery([object Object]);
node:internal/process/promises:279
triggerUncaughtException(err, true /* fromPromise */);
^
Error
at Query.run (/Users/darius/IdeaProjects/node-jwt-auth-postgresql/node_modules/sequelize/lib/dialects/postgres/query.js:50:25)
at /Users/darius/IdeaProjects/node-jwt-auth-postgresql/node_modules/sequelize/lib/sequelize.js:314:28
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async exports.getAllBooks (/Users/darius/IdeaProjects/node-jwt-auth-postgresql/app/controllers/book.controller.js:16:29) {
name: 'SequelizeDatabaseError',
parent: error: syntax error at or near "["
at Parser.parseErrorMessage (/Users/darius/IdeaProjects/node-jwt-auth-postgresql/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/Users/darius/IdeaProjects/node-jwt-auth-postgresql/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Users/darius/IdeaProjects/node-jwt-auth-postgresql/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (/Users/darius/IdeaProjects/node-jwt-auth-postgresql/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
length: 90,
severity: 'ERROR',
code: '42601',
detail: undefined,
hint: undefined,
position: '83',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'scan.l',
line: '1180',
routine: 'scanner_yyerror',
sql: "SELECT ('title')\n" +
' FROM Book\n' +
' WHERE searchable ## to_tsquery([object Object]);',
parameters: undefined
},
original: error: syntax error at or near "["
at Parser.parseErrorMessage (/Users/darius/IdeaProjects/node-jwt-auth-postgresql/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/Users/darius/IdeaProjects/node-jwt-auth-postgresql/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Users/darius/IdeaProjects/node-jwt-auth-postgresql/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (/Users/darius/IdeaProjects/node-jwt-auth-postgresql/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
length: 90,
severity: 'ERROR',
code: '42601',
detail: undefined,
hint: undefined,
position: '83',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'scan.l',
line: '1180',
routine: 'scanner_yyerror',
sql: "SELECT ('title')\n" +
' FROM Book\n' +
' WHERE searchable ## to_tsquery([object Object]);',
parameters: undefined
},
sql: "SELECT ('title')\n" +
' FROM Book\n' +
' WHERE searchable ## to_tsquery([object Object]);',
parameters: {}
}
[nodemon] app crashed - waiting for file changes before starting...

First, you passed the whole query object instead of the searchable prop only.
Second, it's better to use bind option to pass such values safely (remember about SQL injection!).
await sequelize.query(`
SELECT ('title')
FROM Book
WHERE searchable ## to_tsquery($searchable);
`, {
type: QueryTypes.SELECT,
bind: {
searchable: req.query.searchable
}
})

Related

Unable to update data using prisma

I am using prisma to update some fields but i am getting error.
I am using unique id to update the data.
Before update i am able to get all the data from table so prisma is working on select
const cartUpdate = await prisma.custom_checkout__c.update({
where: {
id: uniqueId,
},
data: {
status__c: 'Checkout completed',
coupon_code__c: coupon,
checkout_id__c: result.subscription.id,
}
})
Error is below
PrismaClientUnknownRequestError:
Invalid `prisma.custom_checkout__c.update()` invocation:
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E42883), message: "function get_xmlbinary() does not exist", detail: None, hint: Some("No function matches the given name and argument types. You might need to add explicit type casts."), position: Some(Internal { position: 2, query: "(get_xmlbinary() = 'base64')" }), where_: Some("PL/pgSQL function hc_custom_checkout__c_status() line 3 at IF"), schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_func.c"), line: Some(629), routine: Some("ParseFuncOrColumn") }) }) })
at RequestHandler.handleRequestError (/Users/bi

Mongoose create on session fails on validation

I am trying to create a document, on an existing collection, using MongoDB + async..await programming + session/transaction control (in order to be able to rollback to a previous state if anything goes wrong). The relevant code is shown below:
exports.campaign_totalize = async (campaign, start_date, end_date, now) => {
var session = await mongoose.startSession();
session.startTransaction();
try {
// ...
let commission = await commissionModel.create({
datetime: Date.now(),
value: 10,
status: 'issued',
affiliate: affiliate_id,
campaign: campaign_id
}, { session: session });
// ...
}
// ...
} catch (err) {
console.log("Error totalizing commissions:", err);
await session.abortTransaction();
session.endSession();
throw err;
}
}
Executing code above I get ValidationError on ALL fields (even being sure they are all OK). If I remove the session parameter, however, everything works fine! The collections exists for sure.
Below information about my environment:
"dependencies": {
"express": "^4.16.4",
"mongoose": "^5.3.9",
"mongoose-bcrypt": "^1.6.0",
"validator": "^10.9.0"
}
$ node --version
v10.14.0
$ mongod --version
db version (v3.6.3) -> v4.0.4
Thank you very much.
Update:
As Shivam Pandey pointed out in the comments, mongoDB version starts supporting transactions on version 4.0. I just updated it to 4.0.4 and it is returning the same errors, though.
Update 2:
Stack trace:
Trace: error
at Object.exports.campaign_totalize (/home/luiz/magalabs/magafilio/magafilio-server/logic/commission_calc.js:147:17)
at process._tickCallback (internal/process/next_tick.js:68:7)
Error totalizing commissions: { ValidationError: Commission validation failed: campaign: All commissions must be associated to a campaign, affiliate: All commissions must be associated to an affiliate, status: Commission needs a status associated, value: Commission needs a value - use 0 for no valued commissions, datetime: Commission needs date/time info
at ValidationError.inspect (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/error/validation.js:59:24)
at formatValue (internal/util/inspect.js:453:31)
at inspect (internal/util/inspect.js:193:10)
at Object.formatWithOptions (util.js:165:18)
at Console.(anonymous function) (console.js:188:15)
at Console.log (console.js:199:31)
at Object.exports.campaign_totalize (/home/luiz/magalabs/magafilio/magafilio-server/logic/commission_calc.js:148:17)
at process._tickCallback (internal/process/next_tick.js:68:7)
errors:
{ campaign:
{ ValidatorError: All commissions must be associated to a campaign
at new ValidatorError (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/error/validator.js:29:11)
at validate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:844:13)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:897:11
at Array.forEach (<anonymous>)
at ObjectId.SchemaType.doValidate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:853:19)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/document.js:1893:9
at process._tickCallback (internal/process/next_tick.js:61:11)
message: 'All commissions must be associated to a campaign',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'campaign',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true },
affiliate:
{ ValidatorError: All commissions must be associated to an affiliate
at new ValidatorError (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/error/validator.js:29:11)
at validate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:844:13)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:897:11
at Array.forEach (<anonymous>)
at ObjectId.SchemaType.doValidate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:853:19)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/document.js:1893:9
at process._tickCallback (internal/process/next_tick.js:61:11)
message: 'All commissions must be associated to an affiliate',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'affiliate',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true },
status:
{ ValidatorError: Commission needs a status associated
at new ValidatorError (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/error/validator.js:29:11)
at validate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:844:13)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:897:11
at Array.forEach (<anonymous>)
at SchemaString.SchemaType.doValidate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:853:19)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/document.js:1893:9
at process._tickCallback (internal/process/next_tick.js:61:11)
message: 'Commission needs a status associated',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'status',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true },
value:
{ ValidatorError: Commission needs a value - use 0 for no valued commissions
at new ValidatorError (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/error/validator.js:29:11)
at validate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:844:13)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:897:11
at Array.forEach (<anonymous>)
at SchemaNumber.SchemaType.doValidate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:853:19)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/document.js:1893:9
at process._tickCallback (internal/process/next_tick.js:61:11)
message: 'Commission needs a value - use 0 for no valued commissions',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'value',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true },
datetime:
{ ValidatorError: Commission needs date/time info
at new ValidatorError (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/error/validator.js:29:11)
at validate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:844:13)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:897:11
at Array.forEach (<anonymous>)
at SchemaDate.SchemaType.doValidate (/home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/schematype.js:853:19)
at /home/luiz/magalabs/magafilio/magafilio-server/node_modules/mongoose/lib/document.js:1893:9
at process._tickCallback (internal/process/next_tick.js:61:11)
message: 'Commission needs date/time info',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'datetime',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true } },
_message: 'Commission validation failed',
name: 'ValidationError' }
I think there's an issue with how you're using the create, or at least that's my first guess.
To specify options, docs must be an array, not a spread.
https://mongoosejs.com/docs/api.html#model_Model.create
Has to be in this form
Model.create([doc], options)
you have
Model.create(doc, options)
This might be what you want
let [commission] = await commissionModel.create([{datetime: Date.now(),
...}], {session})
let [commission] = await commissionModel.create([doc], options})
When you pass an array into Model.create(), Model.create() will return an array with the documents you created/saved so that's why I used "let [commission]" which will set variable commission to the first item in the array that gets returned.

Sails.js one to many association with postgreSQL: column does not exist

I need some help with associations in sails 0.12.13 with postgresql.
I have an "App" model and a "Membership" model. Relation should be one to many (one app can be associated with many relationships).
This is the App model db table schema (table is called "apps"):
Table "public.apps"
Column | Type | Modifiers
------------+-----------------------------+---------------------------------------------------
id | integer | not null default nextval('apps_id_seq'::regclass)
name | character varying | not null
Indexes:
"apps_pkey" PRIMARY KEY, btree (id)
"apps_name_key" UNIQUE CONSTRAINT, btree (name)
Referenced by:
TABLE "memberships" CONSTRAINT "app_fk" FOREIGN KEY (app_id) REFERENCES apps(id) ON UPDATE RESTRICT ON DELETE CASCADE
And this is memberships:
Table "public.memberships"
Column | Type | Modifiers
------------+-----------------------------+----------------------------------------------------------
id | integer | not null default nextval('memberships_id_seq'::regclass)
app_id | integer | not null
Foreign-key constraints:
"app_fk" FOREIGN KEY (app_id) REFERENCES apps(id) ON UPDATE RESTRICT ON DELETE CASCADE
in my user model, i have this:
module.exports = {
tableName: 'apps',
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
name: { type: 'string', unique: true, required: true, alphanumericdashed: true },
memberships: { collection: 'memberships', model: 'Membership' },
}
}
And this is the Membership model:
module.exports = {
tableName: 'memberships',
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
app: { model: 'app', columnName: 'app_id' },
},
};
When I try to query an app and get its memberships:
App.find({ id: 1 }).populate('memberships').exec((err, app) => {
if (err) throw err;
console.log(app.memberships);
});
I get this error:
Error (E_UNKNOWN) :: Encountered an unexpected error
error: column apps.memberships does not exist
at Connection.parseE (/usr/src/app/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:539:11)
at Connection.parseMessage (/usr/src/app/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:366:17)
at Socket.<anonymous> (/usr/src/app/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:105:22)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at addChunk (_stream_readable.js:252:12)
at readableAddChunk (_stream_readable.js:239:11)
at Socket.Readable.push (_stream_readable.js:197:10)
at TCP.onread (net.js:589:20)
Looks like the association is not "enabled" and waterline is searching for an actual column "membership" in my model. Can anybody explain me what I am doing wrong? thx
According to the documentation, I would guess that you have a bad association.
// App.js
module.exports = {
tableName: 'apps',
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
name: {
type: 'string',
unique: true,
required: true,
alphanumericdashed: true
},
memberships: {
collection: 'membership', // <-- changed to singular (as your model should be)
via: 'app' // <-- use "via" instead of "model"
},
}
}
// Membership.js
module.exports = {
tableName: 'memberships',
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
app: {
model: 'app'
// <-- removed the "columnName" here
},
},
};
Also, convention generally says name your model as a singular instance. For example, its "User.js" and not "Users.js". It's valid to refer to the collection as a plural. I made some changes in your naming, but you'll have to see how that affects your files (since you didn't give those names).

node-postgres does not show result set for stored procedure

I'm trying to use a stored procedure to create a character. The procedure does some validation to make sure that the params are valid before inserting them into the database(let's keep this validation on the database). However when I attempt to use the procedure in my web interface with invalid data, there is no result set, and the error promise does not happen. What do I have to do to make this procedure cause an error on the node side?
-- add a character with the universe performing the universe name lookup
CREATE OR REPLACE FUNCTION add_character(
IN p_chr_name VARCHAR(255),
IN p_unv_name VARCHAR(255),
IN p_chr_bio TEXT
)
RETURNS INT AS $$
DECLARE
unv_id INTEGER := (SELECT unv_id
FROM universes
WHERE LOWER(unv_name) = LOWER(p_unv_name));
new_id INTEGER := NULL;
BEGIN
IF unv_id IS NULL THEN
RAISE EXCEPTION 'unv_id is null for %', p_unv_name;
END IF;
INSERT INTO characters(chr_name, chr_unv_id, chr_bio) VALUES
(p_chr_name, unv_id, p_chr_bio)
RETURNING chr_id INTO new_id;
RETURN new_id;
END $$
LANGUAGE PLPGSQL;
The javascript
app.post('/contrib/chr', (req, res) => {
console.log(req.body);
pool.query('SELECT add_character($1, $2, $3)'
[req.body.chr_name, req.body.unv_name, req.body.chr_bio])
.then((rows) => {
console.log(rows);
res.render('contrib');
}).catch((err) => {
console.error('contrib-chr-err', err);
res.render('contrib');
});
})
The row object returned.
{ command: '', rowCount: NaN, rows: [], fields: null }
working sample:
sql:
t=# create or replace function s110(_b boolean) returns int as
$$
begin
if not _b then
raise info '%','here is notice';
raise warning '%','warning it is';
end if;
if _b then
raise exception '%','final exception it is';
end if;
return 9;
end;
$$ language plpgsql;
CREATE FUNCTION
js
var pg = require('pg');
var client = new pg.Client({"database": "t"});
client.connect(function (err) {
if (err) throw err;
client.query('SELECT * from s110(true)', [], function (err, result) {
if (err) throw err;
console.log(result);
client.end(function (err) {
if (err) throw err;
});
});
});
run
MacBook-Air:n vao$ vi q1.js && node q1.js
/Users/vao/n/q1.js:6
if (err) throw err;
^
error: final exception it is
at Connection.parseE (/Users/vao/node_modules/pg/lib/connection.js:569:11)
at Connection.parseMessage (/Users/vao/node_modules/pg/lib/connection.js:396:17)
at Socket.<anonymous> (/Users/vao/node_modules/pg/lib/connection.js:132:22)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:153:18)
at Socket.Readable.push (_stream_readable.js:111:10)
at TCP.onread (net.js:531:20)
if I change SELECT * from s110(true) to SELECT * from s110(false):
MacBook-Air:n vao$ vi q1.js && node q1.js
{ command: 'SELECT',
rowCount: 1,
oid: NaN,
rows: [ { s110: 9 } ],
fields:
[ { name: 's110',
tableID: 0,
columnID: 0,
dataTypeID: 23,
dataTypeSize: 4,
dataTypeModifier: -1,
format: 'text' } ],
_parsers: [ [Function] ],
RowCtor: [Function],
rowAsArray: false,
_getTypeParser: [Function: bound ] }
UPDATE
Also you can get STDOUT messages with little change. I'm not good in javascript, hopefully I don't advice very silly things, here. If you add this line above .query:
client.connection.on('message', function(a) {console.log(a);});
client.query('SELECT s110(false)', [], function (err, result) {...
You will get all RAISE output to console.log:
{ [notice: here is notice]
name: 'notice',
length: 123,
severity: 'INFO',
code: '00000',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: 'PL/pgSQL function s110(boolean) line 4 at RAISE',
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'pl_exec.c',
line: '3165',
routine: 'exec_stmt_raise' }
{ [notice: warning it is]
name: 'notice',
length: 128,
severity: 'WARNING',
code: '01000',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: 'PL/pgSQL function s110(boolean) line 5 at RAISE',
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'pl_exec.c',
line: '3165',
routine: 'exec_stmt_raise' }
{ name: 'dataRow', length: 11, fieldCount: 1, fields: [ '9' ] }
{ name: 'commandComplete', length: 13, text: 'SELECT 1' }
{ name: 'readyForQuery', length: 5, status: 'I' }

using sequelize-cli db:seed, schema is ignored when accessing Postgres

i am building a web service using express.js and Sequilize with a Postgres DB.
Database holds a table 'country' under schema 'schema1'. Table 'country' has fields 'name', 'isoCode'.
Created a seed file to insert a list of countries inside table 'country'.
Seed file looks like :
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.bulkInsert(
'country',
[
{
"name":"Afghanistan",
"isoCode":"AF"
},
{
"name":"Ă…land Islands",
"isoCode":"AX"
},
{
"name":"Albania",
"isoCode":"AL"
},
{
"name":"Algeria",
"isoCode":"DZ"
},
{
"name":"American Samoa",
"isoCode":"AS"
},
{
"name":"Andorra",
"isoCode":"AD"
}
],
{
schema : 'schema1'
}
);
},
down: function (queryInterface, Sequelize) {
}
};
While running seed i get this error :
node_modules/sequelize-cli/bin/sequelize --url postgres://user:password#localhost:5432/database db:seed
Sequelize [Node: 0.12.6, CLI: 2.0.0, ORM: 3.11.0, pg: ^4.4.2]
Parsed url postgres://user:*****#localhost:5432/database
Starting 'db:seed'...
Finished 'db:seed' after 165 ms
== 20151029161319-Countries: migrating =======
Unhandled rejection SequelizeDatabaseError: relation "country" does not exist
at Query.formatError (node_modules/sequelize/lib/dialects/postgres/query.js:437:14)
at null.<anonymous> (node_modules/sequelize/lib/dialects/postgres/query.js:112:19)
at emit (events.js:107:17)
at Query.handleError (node_modules/pg/lib/query.js:108:8)
at null.<anonymous> (node_modules/pg/lib/client.js:171:26)
at emit (events.js:107:17)
at Socket.<anonymous> (node_modules/pg/lib/connection.js:109:12)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
I think i am stuck on this. I would appreciate any provided help / guidance etc.
Thank you for your time.
I executed SQL query on Postgres :
ALTER ROLE <username> SET search_path TO schema1,public;
as noted here : Permanently Set Postgresql Schema Path
Then, executed seeder again succesfully :
node_modules/sequelize-cli/bin/sequelize --url postgres://user:password#localhost:5432/database db:seed
Sequelize [Node: 0.12.6, CLI: 2.0.0, ORM: 3.11.0, pg: ^4.4.2]
Parsed url postgres://user:*****#localhost:5432/database
Using gulpfile node_modules/sequelize-cli/lib/gulpfile.js
Starting 'db:seed'...
Finished 'db:seed' after 558 ms
== 20151029161319-Countries: migrating =======
== 20151029161319-Countries: migrated (0.294s)
Thanks #a_horse_with_no_name for the information about search_path. I wish the sequelize library could handle this situation, or maybe i misuse it.
update :
Opened a ticket on Github (https://github.com/sequelize/sequelize/issues/4778#issuecomment-152566806) and the solution is quite simple :
instead of setting only the table as the first argument, set
{tableName: 'country', schema : 'schema1'}
You can actually specify the schema and table name via object like is explained in this Github issue:
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.bulkInsert(
{ tableName: 'account', schema: 'crm' },
{
name: 'Michael'
},
{}
);
},
down: function (queryInterface, Sequelize) {
return queryInterface.bulkDelete({ tableName: 'account', schema: 'crm' }, null, {});
}
};