Skip to content

Soft-deletes with new MSSQL DATETIMEOFFSET field #7419

Closed

Description

@Wsiegenthaler

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!

Activity

  1. iamjoyce commented on Apr 12, 2017

    @iamjoyce

    What version of sequelize are you using?

  2. Wsiegenthaler commented on Apr 12, 2017

    @Wsiegenthaler
    ContributorAuthor

    This issue is regarding v4 which has transitioned away from DATETIME2 in favor of DATETIMEOFFSET for SQL Server databases (see #7201).

  3. stale commented on Jun 29, 2017

    @stale

    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 🙂

  4. Wsiegenthaler commented on Jun 29, 2017

    @Wsiegenthaler
    ContributorAuthor

    I believe this is still an issue. I've been using this as a workaround until an official solution is found.

  5. stale commented on Aug 28, 2017

    @stale

    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 🙂

  6. tony-gutierrez commented on Mar 26, 2018

    @tony-gutierrez

    Also there is no way to do a data export and import with this field type. It cannot import dates from strings.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions