X Tutup
The Wayback Machine - https://web.archive.org/web/20201204153825/https://github.com/sequelize/sequelize/pull/12231
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

fix(mysql): Add parentheses to default value #12231

Open
wants to merge 3 commits into
base: master
from

Conversation

@JuarezLustosa
Copy link
Contributor

@JuarezLustosa JuarezLustosa commented May 5, 2020

Pull Request check-list

  • 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

  • This close issue #12102. However, I did tests on MySQL version 5.7 and 8.

On 5.7 Do not accept default with parentheses.

CREATE TABLE IF NOT EXISTS `foo2` (`uuid` CHAR(16) DEFAULT (0) );

We have this error

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(0) )' at line 1

- On Version 8 accept

This same query creates the table, so it works as well.

I don't know how the project works with old versions. It up to you guys.

@codecov
Copy link

@codecov codecov bot commented May 13, 2020

Codecov Report

Merging #12231 into master will increase coverage by 0.01%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12231      +/-   ##
==========================================
+ Coverage   96.33%   96.35%   +0.01%     
==========================================
  Files          95       95              
  Lines        9118     9127       +9     
==========================================
+ Hits         8784     8794      +10     
+ Misses        334      333       -1     
Impacted Files Coverage Δ
lib/dialects/mysql/query-generator.js 97.16% <66.66%> (-0.45%) ⬇️
lib/associations/helpers.js 100.00% <0.00%> (ø)
lib/dialects/abstract/query.js 91.98% <0.00%> (ø)
lib/associations/belongs-to-many.js 98.02% <0.00%> (ø)
lib/utils.js 98.31% <0.00%> (+0.01%) ⬆️
lib/dialects/sqlite/query-generator.js 96.63% <0.00%> (+0.03%) ⬆️
lib/dialects/postgres/query-generator.js 94.65% <0.00%> (+0.04%) ⬆️
lib/model.js 96.63% <0.00%> (+0.05%) ⬆️
lib/dialects/mssql/query-generator.js 95.69% <0.00%> (+0.08%) ⬆️
... and 1 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 c14972b...06f61b7. Read the comment docs.

@sushantdhiman
Copy link
Contributor

@sushantdhiman sushantdhiman commented May 13, 2020

Add a test in this file https://github.com/sequelize/sequelize/blob/master/test/integration/data-types.test.js

Create a model with defaultValue using function. Create a row and update it

// MySQL 5.7 or above doesn't support POINT EMPTY
if (dialect === 'mysql' && semver.gte(current.options.databaseVersion, '5.7.0')) {
return;
}

it('should return parenteses when default values is a function', function() {

This comment has been minimized.

@sushantdhiman

sushantdhiman May 19, 2020
Contributor

Some changes

  1. This it block is placed inside another it block so it won't execute. Please move it outside of it('should parse an empty GEOMETRY field', () => { block
  2. You should use async/await
}).then(() => {
return Model.findOne({ where: { id: 1 } });
}).then(user => {
expect(user.get('double')).to.eq(Infinity);

This comment has been minimized.

@sushantdhiman

sushantdhiman May 19, 2020
Contributor

Model doesn't have a double attribute

This comment has been minimized.

@JuarezLustosa

JuarezLustosa May 19, 2020
Author Contributor

Hey @sushantdhiman . Thank you for your support.

I've been troubling whit this test. When I put the function on default, it is trying to create on the database, and on the test, the version of MySQL is 5.7, so it can't happen cuz this version does not support this parenthesis. What do you do in those cases?

Thank you again.
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.
X Tutup