Skip to content

cli appending "public" schema in front of database name during migrations. #284

@buildjosh

Description

@buildjosh

So I'm using the latest cli and latest sequelize.

Originally I had my migration file look like this:

'use strict';

module.exports = {
  up: function (queryInterface, Sequelize) {
    return queryInterface.addColumn('accounts', 'agentId', {
      type: Sequelize.STRING,
      allowNull: false,
      defaultValue: 'NOT_TRACKED'
    });
  },

  down: function (queryInterface, Sequelize) {
    /*
      Add reverting commands here.
      Return a promise to correctly handle asynchronicity.

      Example:
      return queryInterface.dropTable('users');
    */
  }
};

But the SQL query was ignoring my database name and using "public.accounts":

{ [SequelizeDatabaseError: relation "public.accounts" does not exist]

So I tried changing the database to "crm.public.accounts" in the migration file, but that resulted in the following.

Config file looks like this:

{
  "development": {
    "use_env_variable": "DATABASE_URL",
    "dialect": "postgres"
  },
  "production": {
    "use_env_variable": "DATABASE_URL",
    "dialect": "postgres"
  }
}

DATABASE_URL looks like:

postgres://josh@localhost:5432/crm

When trying to run migrations:

$  ./node_modules/.bin/sequelize db:migrate

I'm getting this:

{ [SequelizeDatabaseError: relation "public.crm.public.accounts" does not exist]
  name: 'SequelizeDatabaseError',
  message: 'relation "public.crm.public.accounts" does not exist',
  parent: 
   { [error: relation "public.crm.public.accounts" does not exist]
     name: 'error',
     length: 117,
     severity: 'ERROR',
     code: '42P01',
     detail: undefined,
     hint: undefined,
     position: undefined,
     internalPosition: undefined,
     internalQuery: undefined,
     where: undefined,
     schema: undefined,
     table: undefined,
     column: undefined,
     dataType: undefined,
     constraint: undefined,
     file: 'namespace.c',
     line: '413',
     routine: 'RangeVarGetRelidExtended',
     sql: 'ALTER TABLE "public"."crm.public.accounts" ADD COLUMN "agentId" VARCHAR(255) NOT NULL DEFAULT \'NOT_TRACKED\';' },
  original: 
   { [error: relation "public.crm.public.accounts" does not exist]
     name: 'error',
     length: 117,
     severity: 'ERROR',
     code: '42P01',
     detail: undefined,
     hint: undefined,
     position: undefined,
     internalPosition: undefined,
     internalQuery: undefined,
     where: undefined,
     schema: undefined,
     table: undefined,
     column: undefined,
     dataType: undefined,
     constraint: undefined,
     file: 'namespace.c',
     line: '413',
     routine: 'RangeVarGetRelidExtended',
     sql: 'ALTER TABLE "public"."crm.public.accounts" ADD COLUMN "agentId" VARCHAR(255) NOT NULL DEFAULT \'NOT_TRACKED\';' },
  sql: 'ALTER TABLE "public"."crm.public.accounts" ADD COLUMN "agentId" VARCHAR(255) NOT NULL DEFAULT \'NOT_TRACKED\';' }

How do I get the cli to respect my database when running migrations?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions