db-migrate / node-db-migrate

Database migration framework for node
Other
2.32k stars 360 forks source link

server_version(); is unsupported in redshift #577

Open cbesangeeth opened 6 years ago

cbesangeeth commented 6 years ago

redshift migration is not working because of unsupported function server_version().

Current behavior

Since redshift is postgres compliance, i'm using db-migrate-pg in my node.js application for redshift.

When i ran migrate script, i'm getting below error from redshift db. Here is my verbose looks like:

sangeeth@sangeeth-kumar ~/Desktop/analytics-api $ ./node_modules/.bin/db-migrate up --config cfg/database.json --verbose
[INFO] Detected and using the projects local version of db-migrate. '/home/sangeeth/Desktop/analytics-api/node_modules/db-migrate/index.js'
[INFO] Using dev settings: { driver: 'pg',
  database: 'analytics',
  user: 'master',
  password: '******',
  host: '*****',
  port: '****' }
[INFO] require: db-migrate-pg
[INFO] connecting
[INFO] connected
[SQL] show server_version_num
[SQL] show server_version
[ERROR] error: must be superuser to examine "server_version"
    at Connection.parseE (/home/sangeeth/Desktop/analytics-api/node_modules/pg/lib/connection.js:553:11)
    at Connection.parseMessage (/home/sangeeth/Desktop/analytics-api/node_modules/pg/lib/connection.js:378:19)
    at Socket.<anonymous> (/home/sangeeth/Desktop/analytics-api/node_modules/pg/lib/connection.js:119:22)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:607:20) 

So we can see the error is thrown from redshift.

I had asked this in SO. Link to stackoverflow question

Got to know that show server_version(); is unsupported postgres function in redshift and they suggested to patch the library to work with select version(); instead.

analytics=# select version();
                                                         version                                                          
--------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.2915
(1 row)

Expected behavior

Can you help me out, how to migrate my sql scripts in redshift? Or How to patch server_version to use select version?

Environment


db-migrate version: 0.11.1
db-migrate-pg: 0.4.0
redshift: 1.0.2915
PostgreSQL 8.0.2

Additional information:
- Node version: 8.11.1
- Platform:  Linux



---
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/61112348-server_version-is-unsupported-in-redshift?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github).
            
cbesangeeth commented 6 years ago

I'm using db-migrate-redshift - repo link now.

But it is hangs up on select version() as version when i do migrate. Here is my verbose:

$ db-migrate up --config cfg/database.json --verbose
[INFO] Detected and using the projects local version of db-migrate. '/home/sangeeth/Desktop/myGitRepos/analytics-api/node_modules/db-migrate/index.js'
[INFO] Using dev settings: { driver: 'redshift',
  database: '*****',
  user: '*****',
  password: '******',
  host: '******' }
[INFO] require: db-migrate-redshift
[INFO] connecting
[INFO] connected
[SQL] select version() as version
[ERROR] Error: connect ETIMEDOUT 54.161.156.200:5432
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@wzrdtales , Could you able to help me out?

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.