Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in migration to custom schema (PG) #13365

Open
2 of 7 tasks
Kolbaskin opened this issue Jul 7, 2021 · 6 comments
Open
2 of 7 tasks

Error in migration to custom schema (PG) #13365

Kolbaskin opened this issue Jul 7, 2021 · 6 comments

Comments

@Kolbaskin
Copy link

Kolbaskin commented Jul 7, 2021

Issue Creation Checklist

[х] I have read the contribution guidelines

  1. Create custom schema in postgres database
  2. Add param "schema" into config file
  3. Create two migration files: one with creating a new table and second with adding extra column (both without specifying the schema name )
  4. Run "sequelize-cli db:migrate"

Config:

{
  "development": {
    "username": "user",
    "password": "pass",
    "database": "database",
    "schema": "customschema",
    "host": "localhost",
    "dialect": "postgres",
    "seederStorage": "sequelize",
    "logging": false,
    "seederStorageTableName": "sequelize_data"
  }
}

First migration:

"use strict";
module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable("users", {
      id: {
        allowNull: false,
        defaultValue: Sequelize.UUIDV4,
        primaryKey: true,
        type: Sequelize.UUID
      },
      name: {
        type: Sequelize.STRING(100)
      }
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable("users");
  }
};

Second:

"use strict";

module.exports = {
  up: function(queryInterface, Sequelize) {
    // logic for transforming into the new state
    return queryInterface.addColumn("users", "realm", Sequelize.UUID);
  },

  down: function(queryInterface, Sequelize) {
    // logic for reverting the changes
    return queryInterface.removeColumn("users", "realm");
  }
};

Bug Description

The new table will created in the custom schema, but the new column sequelize will try add in schema "public"

What do you expect to happen?

I wanted see all objects in schema that is specified in the config.

What is actually happening?

The new table is in custom schema, but the new field is in public schema

Environment

  • Sequelize version: 6.6.5
  • Sequelize-cli version: 6.2.0
  • Node.js version: 12

Bug Report Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s):
  • I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@YBrown-OTO
Copy link

YBrown-OTO commented Jan 3, 2022

Please re-open this issue. I encountered the same problem.
An associated problem to this:
ENUM types are generated in public schema and not in the customschema.

@ephys
Copy link
Member

ephys commented Jan 3, 2022

@YBrown-OTO #13045 could be relevant

Is this an issue with sequelize-cli only or does the issue happen when replicated in a SSCCE too?

Other relevant issue: #11742

@ephys ephys reopened this Jan 3, 2022
@ephys ephys removed the stale label Jan 3, 2022
@YBrown-OTO
Copy link

Thanks @ephys,
I encountered the problem via queryInterface.addColum using Umzug.
Could be related to #11634 as well.
RCA could be: #13045
The workaround suggested by @RossVertizan in #11742 worked for me as follows:

  up: async (queryInterface, Sequelize) => {
    const schema = queryInterface.sequelize.options.schema
    await queryInterface.addColumn(
        { tableName: 'my_table', schema }, ...

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Jan 18, 2022
@metehus
Copy link

metehus commented Jan 20, 2022

Can confirm this is happening

@github-actions github-actions bot removed the stale label Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants