db-migrate / node-db-migrate

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

`migrate up` freezes with no error or timeout #667

Closed Shivang44 closed 4 years ago

Shivang44 commented 4 years ago

I'm submitting a...

Current behavior

I'm using the pg driver and have a simple migration:

exports.up = function(db) {
  db.createTable('users', {
    id: { type: 'int', primaryKey: true },
    email: 'string',
    password: 'string'
  });
}; 

When I execute db-migrate up -v it results in:

[INFO] require: db-migrate-pg
[INFO] connecting
[INFO] connected
[SQL] show server_version_num
[SQL] SHOW search_path
[SQL] SET search_path TO "$user","public"
[SQL] SELECT table_name FROM information_schema.tables WHERE table_name = 'migrations' AND table_schema = 'public'
[INFO] migration table created
[INFO] loading migrations from dir /Users/..../migrations
[INFO] loading migrations from database
[SQL] SELECT * FROM "migrations" ORDER BY run_on DESC, name DESC
[INFO] preparing to run up migration: 20200202032637-AddUserTable
[SQL] BEGIN;
[INFO] creating table: users
[SQL] CREATE TABLE  "users" ("id" INTEGER  PRIMARY KEY, "email" VARCHAR  , "password" VARCHAR  )

But then it just hangs there. I can tell its connecting to the DB because when I CTRL+C my postgres docker container says unexpected EOF on client connection with an open transaction

Expected behavior

It should run the migrations or provide some sort of error on why it couldn't.

Minimal reproduction of the problem with instruction

Run the above migration. I'm using the postgres docker container with docker-compose:

version: '2'
services:
  db:
    image: "postgres:11.6"
    environment:
      POSTGRES_USER: "postgres"
      POSTGRES_PASSWORD: "postgres"
    container_name: "mydb"
    ports:
      - "127.0.0.1:5472:5432"

database.json:

{
    "defaultEnv": "local",
    "local": {
        "driver": "pg",
        "user": "postgres",
        "password": "postgres",
        "host": "localhost",
        "database": "mydb",
        "port": "5472"
    },

Environment


db-migrate version: 0.11.6
db-migrate driver with versions: db-migrate-pg-1.0.0

Additional information:
- Node version: XX   v10.14.0
- Platform:   Mac

Others:

jhnferraris commented 4 years ago

You can either use a callback or wrap it with async/await as mentioned in the document

exports.up = function(db, callback) {
  db.createTable('users', {
    id: { type: 'int', primaryKey: true },
    email: 'string',
    password: 'string'
  }, callback);
};

or

exports.up = async function(db) {
  await db.createTable('users', {
    id: { type: 'int', primaryKey: true },
    email: 'string',
    password: 'string'
  });
};
stale[bot] commented 4 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.