Skip to content

8336 Adds support for postgres infinity timestamp - #8357

Merged
sushantdhiman merged 36 commits into
sequelize:masterfrom
mkaufmaner:8356-refactor-data-types-api
Sep 26, 2017
Merged

sushantdhiman merged 36 commits into
sequelize:masterfrom
mkaufmaner:8356-refactor-data-types-api

Conversation

@mkaufmaner

@mkaufmaner mkaufmaner commented Sep 22, 2017 •

Copy link
Copy Markdown
Contributor

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 follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Closes #8336

See #8356 (Partial fix still requires further work)
See #8339

@mkaufmaner mkaufmaner added the wip label Sep 22, 2017
@codecov

codecov Bot commented Sep 22, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #8357 into master will increase coverage by 0.05%.
The diff coverage is 100%.

@mention-bot

Copy link
Copy Markdown

@mkaufmaner, thanks for your PR! By analyzing the history of the files in this pull request, we identified @felixfbecker, @sushantdhiman and @janmeier to be potential reviewers.

@mkaufmaner

Copy link
Copy Markdown
Contributor Author

Please review! Increase coverage by 0.05%! Woot!

Please note, this WON'T affect user defined setters. I think a major refactor of data types should go into v5.

@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.

_isChanged approach LGTM. Also model level changed and sanitize store is a good idea as well.

I have a few comments about duplicate logic, please address them.

Its a good first step to cleanup datatypes and will of-course fix that Infinity/-Infinity issue with Postgres

Comment thread lib/data-types.js Outdated
};

DATE.prototype._isChanged = function _isChanged(value, originalValue) {
if (originalValue && !!value && value instanceof Date && originalValue instanceof Date && value.getTime() === originalValue.getTime()) {

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.

Multi line this condition check

Comment thread lib/dialects/postgres/data-types.js Outdated
DATEONLY.prototype._isChanged = function _isChanged(value, originalValue) {
if (
originalValue && !!value &&
(value === originalValue || value instanceof Date && originalValue instanceof Date && value.getTime() === originalValue.getTime())

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.

move this to base type? this logic should be honored by all dialects for DATEONLY

Comment thread lib/dialects/postgres/data-types.js Outdated
DATE.prototype._isChanged = function _isChanged(value, originalValue) {
if (
originalValue && !!value &&
(value === originalValue || value instanceof Date && originalValue instanceof Date && value.getTime() === originalValue.getTime())

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.

This logic is again same Postgres.DATEONLY._isChanged (which I have suggested to move to BaseTypes.DATEONLY)

May be BaseType.DATE should have this logic, BaseType.DATEONLY should call that and dialect would never need to override it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The only reason I extended this into postgres was because it was the only dialect where the originalValue and value could be equal (Infinity === Infinity). All others would be Date.getTime() === Date.getTime().

However, after some thought I think you are right in moving it into the BaseType.

@mkaufmaner

Copy link
Copy Markdown
Contributor Author

@sushantdhiman I will address these in the morning. Thanks for the quick response!

@mkaufmaner

Copy link
Copy Markdown
Contributor Author

This is ready to go. Please finalize reviews :)

@mkaufmaner
mkaufmaner force-pushed the 8356-refactor-data-types-api branch from ffa9788 to 866f448 Compare September 25, 2017 00:53
return 'BOOLEAN';
};

BOOLEAN.prototype._sanitize = function _sanitize(value) {

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.

Why boolean is needed here, its logic looks exactly same as base type

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Where value === 'f' or 't'.

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.

👍

@@ -34,6 +34,38 @@ module.exports = BaseTypes => {
inherits(DATEONLY, BaseTypes.DATEONLY);

DATEONLY.parse = function parse(value) {

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.

DATEONLY shares exact methods with DATE (from same dialect). I would say just call DATE.* methods inside DATEONLY as they both are same date types

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hrm. ok

@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.

LGTM, for solving postgres specific Infinity / -Infinity logic.

But it wont close #8356 , So please remove that issue from description.

@mkaufmaner

Copy link
Copy Markdown
Contributor Author

@sushantdhiman Changed "Close #8356" to "See #8356". Also removed DATEONLY.parse entirely.

@mkaufmaner mkaufmaner changed the title 8356 refactor data types api 8336 Adds support for postgres infinity timestamp Sep 25, 2017
@mkaufmaner

Copy link
Copy Markdown
Contributor Author

@sushantdhiman Im not at my normal development environment at the moment but will fix the dateonly in about 7 hours when I wake up.

@mkaufmaner

mkaufmaner commented Sep 25, 2017 •

Copy link
Copy Markdown
Contributor Author

@sushantdhiman @janmeier I have put back the DATEONLY.parse method;

DATEONLY.parse = function parse(value) {
	if (value === 'infinity') {
		value = Infinity;
	} else if (value === '-infinity') {
		value = -Infinity;
	}

	return value;
};

because the parser types differ from the DATE data type.

DATEONLY:

BaseTypes.DATEONLY.types.postgres = {
	oids: [1082],
	array_oids: [1182]
};

DATE:

BaseTypes.DATE.types.postgres = {
	oids: [1184],
	array_oids: [1185]
};

If I change the DATEONLY oids then it will break existing functionality supporting varchar columns.

@mkaufmaner
mkaufmaner force-pushed the 8356-refactor-data-types-api branch from 1346971 to 071daf5 Compare September 25, 2017 16:58
});

if (current.dialect.name === 'postgres') {
describe('GEOGRAPHY(POLYGON, SRID)', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see any code changes related to this - tests for something else?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@janmeier Yes, I decided to add some tests to cover GEOGRAPHY types while I was at it because I wanted to increase coverage of the postgres dialect. Hope this doesn't prevent anything.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not at all, just wanted to make sure I wasn't missing anything

Comment thread lib/data-types.js

DATEONLY.prototype._sanitize = function _sanitize(value, options) {
if (!options || options && !options.raw) {
return moment(value).format('YYYY-MM-DD');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is missing a !!value check. Now, we are getting "Invalid date" value for NULL, resulting in an error.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Infinity and -Infinity Dates in PostgreSQL

5 participants