diff --git a/migrations/mysql/2026-08-10-120000_add_org_policy_revision_date/down.sql b/migrations/mysql/2026-08-10-120000_add_org_policy_revision_date/down.sql index e69de29b..27c33623 100644 --- a/migrations/mysql/2026-08-10-120000_add_org_policy_revision_date/down.sql +++ b/migrations/mysql/2026-08-10-120000_add_org_policy_revision_date/down.sql @@ -0,0 +1 @@ +ALTER TABLE org_policies DROP COLUMN revision_date; diff --git a/migrations/mysql/2026-08-10-120000_add_org_policy_revision_date/up.sql b/migrations/mysql/2026-08-10-120000_add_org_policy_revision_date/up.sql index fc5a5f44..97a84117 100644 --- a/migrations/mysql/2026-08-10-120000_add_org_policy_revision_date/up.sql +++ b/migrations/mysql/2026-08-10-120000_add_org_policy_revision_date/up.sql @@ -1,2 +1,7 @@ +-- DATETIME (not TIMESTAMP) to match this repo's convention for revision_date +-- columns elsewhere, and to avoid MySQL's implicit session-timezone +-- conversion and 2038 range limit on TIMESTAMP. ALTER TABLE org_policies -ADD COLUMN revision_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; +ADD COLUMN revision_date DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'; + +UPDATE org_policies SET revision_date = UTC_TIMESTAMP(); diff --git a/migrations/postgresql/2026-08-10-120000_add_org_policy_revision_date/down.sql b/migrations/postgresql/2026-08-10-120000_add_org_policy_revision_date/down.sql index e69de29b..27c33623 100644 --- a/migrations/postgresql/2026-08-10-120000_add_org_policy_revision_date/down.sql +++ b/migrations/postgresql/2026-08-10-120000_add_org_policy_revision_date/down.sql @@ -0,0 +1 @@ +ALTER TABLE org_policies DROP COLUMN revision_date; diff --git a/migrations/postgresql/2026-08-10-120000_add_org_policy_revision_date/up.sql b/migrations/postgresql/2026-08-10-120000_add_org_policy_revision_date/up.sql index ed39a1d9..44229de2 100644 --- a/migrations/postgresql/2026-08-10-120000_add_org_policy_revision_date/up.sql +++ b/migrations/postgresql/2026-08-10-120000_add_org_policy_revision_date/up.sql @@ -1,2 +1,9 @@ +-- Backfill via `now() AT TIME ZONE 'utc'` rather than a DEFAULT of now(): +-- assigning timestamptz now() into a naive TIMESTAMP column casts through +-- the server's TimeZone GUC, so a DEFAULT now() would store local wall-clock +-- instead of UTC on non-UTC servers, unlike every other naive-UTC timestamp +-- column in this schema. ALTER TABLE org_policies -ADD COLUMN revision_date TIMESTAMP NOT NULL DEFAULT now(); +ADD COLUMN revision_date TIMESTAMP NOT NULL DEFAULT '1970-01-01 00:00:00'; + +UPDATE org_policies SET revision_date = (now() AT TIME ZONE 'utc'); diff --git a/migrations/sqlite/2026-08-10-120000_add_org_policy_revision_date/up.sql b/migrations/sqlite/2026-08-10-120000_add_org_policy_revision_date/up.sql index 4ab5d2e5..86595711 100644 --- a/migrations/sqlite/2026-08-10-120000_add_org_policy_revision_date/up.sql +++ b/migrations/sqlite/2026-08-10-120000_add_org_policy_revision_date/up.sql @@ -1,2 +1,6 @@ +-- SQLite forbids non-constant defaults in ALTER TABLE ... ADD COLUMN, so add +-- the column with a constant placeholder and backfill separately. ALTER TABLE org_policies -ADD COLUMN revision_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; +ADD COLUMN revision_date DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'; + +UPDATE org_policies SET revision_date = CURRENT_TIMESTAMP;