You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
we've been using Postgrator for a while now, and ran into a bug after a recent upgrade. This is a simplified version of the function we run:
importpgfrom'pg';importPostgratorfrom'postgrator';exportasyncfunctionmigrateDb(): Promise<void>{constclient=newpg.Client({host: '127.0.0.1',port: 5432,database: 'postgres',user: 'postgres',password: 'the password',});try{awaitclient.connect();// connection test – added for demonstration purposesawaitclient.query(`CREATE TABLE persons (personid INT,lastname VARCHAR(255));`);awaitclient.query(`INSERT INTO persons (personid,lastname) VALUES (1,'Doe');`);constresult=awaitclient.query('SELECT lastname FROM persons;');console.debug('connection test query result',result.rows);constpostgrator=newPostgrator({migrationPattern: 'migrations/*',driver: 'pg',database: 'postgres',schemaTable: 'schemaversion',execQuery: query=>client.query(query),});postgrator.on('migration-started',m=>console.debug(`migration-started\t #${m.version}${m.name}`));postgrator.on('migration-finished',m=>console.debug(`migration-finished\t #${m.version}${m.name}`));console.debug('before migration');awaitpostgrator.migrate();console.debug('after migration');awaitclient.end();}catch(error){console.error('migration failed',error);awaitclient.end();throwerror;}}
I run this code on/with
node v12.22.10
pg 8.7.3
postgrator 5.0.1
Postgres 9.6
and get the following output:
connection test query result [ { lastname: 'Doe' } ]
before migration
migration failed error: role "kaiputh" does not exist
at Connection.parseE (/Users/kaiputh/code/project-name/backend/out/dist/node_modules/pg/lib/connection.js:555:11)
at Connection.parseMessage (/Users/kaiputh/code/project-name/backend/out/dist/node_modules/pg/lib/connection.js:380:19)
at Socket.<anonymous> (/Users/kaiputh/code/project-name/backend/out/dist/node_modules/pg/lib/connection.js:120:22)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:272:9)
at Socket.Readable.push (_stream_readable.js:213:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
at TCP.callbackTrampoline (internal/async_hooks.js:126:14) {
length: 99,
severity: 'FATAL',
code: '28000',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'miscinit.c',
line: '510',
routine: 'InitializeSessionUserId',
appliedMigrations: []
}
For some reason, this error only occures during development, and neither in our automated tests nor on the server. It's unclear to me what triggers it.
I modified the code to make it easy to reproduce and debug the issue. As far as I can tell, the connection to the Postgres server works as it should. I can change the role name in the error message by setting the environment variable PGUSER (see pg documentation). It seems like some part or dependency of Postgrator is trying to open a separate database connection with the default values of pg. Is this a bug in Postgrator?
The text was updated successfully, but these errors were encountered:
kputh
changed the title
Migration fails with seemingly wrong connection configuration
Migration fails with node-postgres' default connection configuration
Mar 1, 2022
@kputh Postgrator just calls the execQuery to do everything with latest version. I wondered if something was funky with the this context of things, but I don't understand why it'd work in some environments and not others.
Is there anything in your migrations that reference the role kaiputh?
Hi,
we've been using Postgrator for a while now, and ran into a bug after a recent upgrade. This is a simplified version of the function we run:
I run this code on/with
and get the following output:
For some reason, this error only occures during development, and neither in our automated tests nor on the server. It's unclear to me what triggers it.
I modified the code to make it easy to reproduce and debug the issue. As far as I can tell, the connection to the Postgres server works as it should. I can change the role name in the error message by setting the environment variable
PGUSER
(see pg documentation). It seems like some part or dependency of Postgrator is trying to open a separate database connection with the default values of pg. Is this a bug in Postgrator?The text was updated successfully, but these errors were encountered: