-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Datetime column in MSSQL migrations #2304
Comments
I believe that if Microsoft recommends against the use of I don't know much about MSSQL let alone the detailed differences between @elhigu thoughts? |
I don't think it'd be a breaking change in Javascript, really, barring weird edge cases relying on I think both of them support the same string literal formats for input, as well, although this is only really relevant to queries explicitly using custom and/or localized date formats. I could investigate further if needed. e: Actually now that I think about it there may be a few more gotchas wrt manipulating datetimes with SQL functions, but I'll have to investigate if this actually is meaningful in practice in this case. |
I wouldnt like to make this as default, but to add some deprecation notice maybe. If we change the type now, it means that when existing project updates knex and runs new migrations they will have mixed datetime types in their db which sound pretty scary... Im not sure how to handle this. |
@elhigu Well, yes. However, There is one thing What would you propose to move this forward though? Add a deprecation warning to |
I suppose that one correct flow for this would be allow using That option should be implemented also for |
That sounds reasonable. I'll take a look at setting up a PR. |
fixed in #2757 |
In
knex.schema
, creating or altering a column usingtable.dateTime()
ortable.timestamp()
generates a query that uses thedatetime
type. Microsoft discourages the use of this type for new work and recommends usingdatetime2
instead, since it's got considerably better precision, a wider representable range and is ANSI SQL compliant, without using any more storage (both types are 8 bytes wide by default).datetime2
is available since SQL Server 2008, but since I believe other parts of knex generates syntax requiring at least SQL Server 2012, that shouldn't be a problem. The dominant MSSQL Node driver (Tedious) supports both and returns both as a JavascriptDate
by default.Now, this is trivial to work around with
table.specificType
, but I think knex should default to the recommended best practice. I am willing to create a PR for this, but before I do that I figured I'd check if there are any potential problems I've overlooked with such a change. I don't know what the policy is on backwards compatibility in migrations, either.In addition to switching to
datetime2
, MSSQL also has a timezone-aware type,datetimeoffset
, which is likedatetime2
but including a timezone offset (in Postgres terms it's atimestamptz
). Perhaps a better idea would be to implement the same API as Postgres, that istable.dateTime(columnName, withoutTimezone)
, but unlike just switching fromdatetime
todatetime2
which is technically incompatible but unlikely to actually break things in practice, changing to timezone-aware by default has a great deal of potential for interesting bugs.The text was updated successfully, but these errors were encountered: