Skip to content

fix(postgres): sync with alter method fails with dataType enum (#7649) - #12019

Closed
aristov wants to merge 1 commit into
sequelize:v5from
aristov:pgEnum-fix
Closed

aristov wants to merge 1 commit into
sequelize:v5from
aristov:pgEnum-fix

Conversation

@aristov

@aristov aristov commented Mar 21, 2020

Copy link
Copy Markdown
Contributor

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Closes #7649

This change fixes an error that occurs when calling sync({ alter : true }) on a model with the ENUM data type.

The solution is taken from #7649 (comment) by @GrigoryGraborenko.

@codecov

codecov Bot commented Mar 21, 2020

Copy link
Copy Markdown

Codecov Report

Merging #12019 into v5 will increase coverage by 10.76%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##               v5   #12019       +/-   ##
===========================================
+ Coverage   85.50%   96.27%   +10.76%     
===========================================
  Files          89       94        +5     
  Lines        8806     9189      +383     
===========================================
+ Hits         7530     8847     +1317     
+ Misses       1276      342      -934     
Impacted Files Coverage Δ
lib/dialects/postgres/query-generator.js 94.38% <100.00%> (ø)
lib/dialects/sqlite/query.js 98.65% <0.00%> (ø)
lib/dialects/sqlite/connection-manager.js 100.00% <0.00%> (ø)
lib/dialects/sqlite/index.js 100.00% <0.00%> (ø)
lib/dialects/mssql/index.js 100.00% <0.00%> (ø)
lib/dialects/mssql/connection-manager.js 87.01% <0.00%> (ø)
lib/model.js 96.47% <0.00%> (+0.06%) ⬆️
lib/data-types.js 91.34% <0.00%> (+0.34%) ⬆️
lib/dialects/abstract/query.js 91.98% <0.00%> (+1.28%) ⬆️
lib/sql-string.js 90.47% <0.00%> (+1.58%) ⬆️
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 20e99e1...5692194. Read the comment docs.

@sushantdhiman sushantdhiman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current solution will not work with schemas. Please fix that and add an extra integration test for schema case as well

}

let sql = `CREATE TYPE ${enumName} AS ${values};`;
let sql = `DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'enum_${ tableName }_${ attr }') THEN CREATE TYPE ${ enumName } AS ${ values }; END IF; END$$;`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typname = 'enum_${ tableName }_${ attr }' it should check for enumName, like this typname='${enumName}'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sushantdhiman sushantdhiman added the status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action label Apr 4, 2020
@aderiushev

Copy link
Copy Markdown

the fix is so damn straight-forward and desired by the community but you're doing things unacceptably slow @sushantdhiman 👎

@aristov

aristov commented Feb 24, 2021

Copy link
Copy Markdown
Contributor Author

the fix is so damn straight-forward and desired by the community but you're doing things unacceptably slow @sushantdhiman 👎

Unfortunately, I don't have time for this PR right now. Feel free to complete it if you know what to do.

@tehnorm

tehnorm commented Mar 8, 2021

Copy link
Copy Markdown

I can confirm this does fix the issue of postgres enum types updating correctly after more than run of .sync() in our code base.

@github-actions github-actions Bot added the stale label Nov 2, 2021
@github-actions github-actions Bot closed this Nov 8, 2021
@aristov

aristov commented Feb 27, 2023

Copy link
Copy Markdown
Contributor Author

#15718

@github-actions github-actions Bot removed the status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action label Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants