-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set entity columns to be 'timestamp with time zone' to avoid TZ-relat…
…ed test failures (#4720)
- Loading branch information
1 parent
11b9b31
commit 2fa96c9
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
database/migrations/000107_entity_properties_timestamp_tz.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- Copyright 2024 Stacklok, Inc | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
BEGIN; | ||
|
||
SET timezone = 'UTC'; | ||
ALTER TABLE properties | ||
ALTER COLUMN updated_at TYPE TIMESTAMP, | ||
ALTER updated_at SET DEFAULT NOW(); -- Default needs to be set explicitly after type change | ||
|
||
ALTER TABLE entity_instances | ||
ALTER created_at TYPE TIMESTAMP, | ||
ALTER created_at SET DEFAULT NOW(); | ||
|
||
-- There are more TIMESTAMP columns, but these are affecting unit tests in some timezones. | ||
|
||
COMMIT; |
32 changes: 32 additions & 0 deletions
32
database/migrations/000107_entity_properties_timestamp_tz.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-- Copyright 2024 Stacklok, Inc | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
BEGIN; | ||
|
||
-- Postgres only needs to rewrite metadata (and not the column data) when altering | ||
-- a column from timezoneless when timezone='UTC' is set in the session. | ||
-- Ref: https://www.postgresql.org/docs/release/12.0/ | ||
|
||
SET timezone = 'UTC'; | ||
ALTER TABLE properties | ||
ALTER COLUMN updated_at TYPE TIMESTAMPTZ, | ||
ALTER updated_at SET DEFAULT NOW()::timestamptz; -- Default needs to be set explicitly after type change | ||
|
||
ALTER TABLE entity_instances | ||
ALTER created_at TYPE TIMESTAMPTZ, | ||
ALTER created_at SET DEFAULT NOW()::timestamptz; | ||
|
||
-- There are more TIMESTAMP columns, but these are affecting unit tests in some timezones. | ||
|
||
COMMIT; |