You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Soft-deletes with new MSSQL DATETIMEOFFSET field #7419
Working around another date issue I've been having, I recently updated my DATETIME2 fields to DATETIMEOFFSET as will be the practice with v4 going forward (see #5403, #7201). Changing the column type fixed my other issue but seems to break soft-deletes.
To make things interesting, my server is hosted on the west coast (-7h) and the database in Hawaii (-10h). Sequelize has been configured to expect the database in "Pacific/Honolulu".
Previously, when using DATETIME2, a record deleted at 10:30am PDT will have a deletedAt value of "07:30" in the database. This makes sense, since 7:30 in database time (Hawaii) is 10:30a PDT. When compared against CURRENT_TIMESTAMP this field will omit the record from subsequent selections.
DATETIMEOFFSET now stores the timezone in addition to the timestamp, so a record deleted at 10:30a PDT will now have a deletedAt value of "07:30 -10:00". This is expected, instead of inferring the timezone from the database it's specified in the field itself. The catch is that CURRENT_TIMESTAMP doesn't have an offset, and so is not compared properly with the DATETIMEOFFSET field, resulting in "deleted" records still being selected.
It seems that our deletedAt field now needs to be compared with MSSQL's SYSDATETIMEOFFSET() in order to account for the offset. I've hacked this into the paranoid clause and it all begins to work as expected - regardless of whether the field is DATETIME2 or DATETIMEOFFSET. SYSDATETIMEOFFSET() is MSSQL specific and so can't simply be substituted for CURRENT_TIMESTAMP. My project is only using MSSQL so for now I'll just get by with the hack but please share any thoughts or opinions on the best way forward!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
Activity
iamjoyce commentedon Apr 12, 2017
What version of sequelize are you using?
Wsiegenthaler commentedon Apr 12, 2017
This issue is regarding v4 which has transitioned away from DATETIME2 in favor of DATETIMEOFFSET for SQL Server databases (see #7201).
stale commentedon Jun 29, 2017
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
Wsiegenthaler commentedon Jun 29, 2017
I believe this is still an issue. I've been using this as a workaround until an official solution is found.
stale commentedon Aug 28, 2017
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
tony-gutierrez commentedon Mar 26, 2018
Also there is no way to do a data export and import with this field type. It cannot import dates from strings.