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

When using enum column types in a model that also uses an explicit schema, it generates the wrong sql... #3171

Closed
NoMoreNicksLeft opened this issue Feb 19, 2015 · 8 comments
Labels
dialect: postgres For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects). type: bug

Comments

@NoMoreNicksLeft
Copy link

Example:

var Platform = sequelize.define('platform', {
            id:              { type: DataTypes.UUID, 
            nature:       { type: DataTypes.ENUM('hardware', 'software') }
), 
// This statement chucks the table into the "common" schema (at least in Postgres).
x = Platform.schema('videoGames', '_');

The sql generated for this model is

"nature" "enum_videoGames.platforms_nature"

When it should probably be

"nature" "videoGames.enum_platforms_nature"

 "nature" "videoGames"."enum_platforms_nature"

(If the dot is inside double quotes, it becomes part of the name, and the enum is created without a schema...)

This is only in Postgres, I haven't tested it with other backends. I'll try to provide a fix for this later, if I can figure it out.

@mickhansen
Copy link
Contributor

Thanks for the report.
You don't need to supply a delimiter for postgres, it will just ignore it: Platform.schema('videoGames', '_'); => Platform.schema('videoGames');

@NoMoreNicksLeft
Copy link
Author

Thanks for the tip... still learning. I'll try to figure out the fix too... I know it's in query-generator.js, but it looks pretty complicated.

@janmeier janmeier added the dialect: postgres For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects). label Jun 28, 2015
@janmeier
Copy link
Member

This problem applies in several places:

  • When checking if an enum already exists we should look in the right schema
  • When creating a new enum it should be created in the right schema
  • When referencing an enum in the table definition it should reference the right schema (maybe it should also be possible for users to specify another schema for the enum?)

@marcingasior
Copy link

I updated to 3.11.0 and still get errors
Unhandled rejection SequelizeDatabaseError: type "..._type" already exists

@janmeier
Copy link
Member

janmeier commented Oct 5, 2015

@marcingasior please show a reproducible test case then

@marcingasior
Copy link

if you use it from node cluster or restart 2 times your app
var Page = sequelize.define("page", {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false
},
type: { type: DataTypes.ENUM('article','news','other') },
data: { type: DataTypes.JSON }
});

models.sequelize.sync().then(function () {

    var server = app.listen(app.get('port'), function() {
        log.info('Swagger API server listening on port ' + app.get('port'));
    });

});

@janmeier
Copy link
Member

@marcingasior Works fine for me, the second time it's run it finds the enum fine. Please create a SSCCE

@marcingasior
Copy link

Hi Jan,

I create a test and run it against local instance (9.3 and 9.4) and it looks it is working fine.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialect: postgres For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects). type: bug
Projects
None yet
Development

No branches or pull requests

4 participants