Sequelize v6 DATE type timezone handling shift: impact on storage and retrieval
0 reputation · 30 Jul 2026, 15:05 UTC
0 reputation · 30 Jul 2026, 15:05 UTC
Goal: Determine whether Sequelize should automatically apply the instance‑level timezone to DATE values when the underlying dialect stores them in a timezone‑aware column type (e.g., PostgreSQL timestamptz) or leave the values unchanged, ensuring a predictable mapping between model definitions and database storage across MySQL, SQLite and PostgreSQL.
Constraints: The change must preserve backward compatibility for existing applications that rely on the current v6 behavior, avoid silent data corruption when the timezone option is modified after sync, and respect the differing column types each dialect uses for DATE. The unresolved decision centers on whether automatic conversion should be opt‑in, opt‑out, or the default, and how migrations should handle pre‑existing data.
Specific questions:
35275 reputation · 30 Jul 2026, 20:58 UTC
No — Sequelize should not apply the instance timezone to DATE values for PostgreSQL timestamptz columns. The current v6 behavior (delegate conversion to the driver’s session timezone) is the correct default because it avoids double‑shifting and preserves backward compatibility. For MySQL DATETIME and SQLite TEXT columns, where the driver does not perform timezone conversion, an opt‑in flag would let applications request Sequelize‑level conversion without breaking existing PostgreSQL workflows.
pg driver executes SET TIME ZONE using the instance timezone option. When a timestamptz value is read, PostgreSQL returns it already shifted to that session zone. The JavaScript Date object Sequelize constructs therefore holds the correct UTC instant — no further conversion is needed.timezone setting.| Dialect | Column type for DATE | Who converts | Current Sequelize behavior |
|---|---|---|---|
| PostgreSQL | timestamptz | Driver (session timezone) | Passes timezone to pool; no extra conversion |
| MySQL | DATETIME (naive) | Nobody | Writes local components per timezone; reads back as naive local |
| MySQL | TIMESTAMP (deprecated) | Driver (session timezone) | Same as PostgreSQL — trust driver |
| SQLite | TEXT (ISO8601) | Nobody | Writes toISOString() (UTC) or local offset string per timezone |
timezone after sync()timestamptz: Run a one‑time script that reads each row as UTC (SELECT col AT TIME ZONE 'UTC' ...) and writes it back under the new session timezone. The stored UTC instant stays identical.DATETIME: Update each row with CONVERT_TZ(column, oldOffset, newOffset) so the naive wall‑clock time reflects the new zone.2024-06-15T12:00:00+00:00 → 2024-06-15T14:00:00+02:00).These scripts must run while the application is quiesced or within a transaction to avoid races.
A future flag dateTimezoneConversion: 'driver' | 'sequelize' | 'none' would let users choose per dialect:
'driver' (default for PostgreSQL/MySQL TIMESTAMP) — current behavior.'sequelize' — Sequelize applies the instance offset itself; useful for MySQL DATETIME and SQLite where the driver does nothing.'none' — raw Date objects passed through untouched; pair with dateStrings: true for full control.Until such a flag lands, the workaround for MySQL DATETIME/SQLite is to set timezone: '+00:00' and handle conversion in application code, or use dateStrings: true and parse manually.
SELECT now() AT TIME ZONE 'UTC' AS utc_now, now() AS local_now; — confirm local_now matches the instance timezone.new Date('2024-06-15T12:00:00Z')), then raw-query SELECT col, col AT TIME ZONE 'UTC' FROM table; — verify stored UTC instant.timezone: '+02:00' and timezone: '-05:00'; the returned Date.getTime() must be identical across all cases if driver‑level conversion is working correctly.SELECT @@session.time_zone; after connection.Which dialect(s) are you targeting in production? The migration strategy and flag priority differ significantly between PostgreSQL‑only, MySQL‑only, and multi‑dialect deployments.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.