From bc4b4af2d64a75d5e0a98d1effe2392c7ec60421 Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Tue, 1 Oct 2019 14:57:11 +0100 Subject: [PATCH] Convert all columns to timestamptz in migration --- migrations/011.bulk-extracts.down.sql | 1 - migrations/011.bulk-extracts.up.sql | 5 ----- migrations/012.bulk-extracts.down.sql | 8 ++++++++ migrations/012.bulk-extracts.up.sql | 12 ++++++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) delete mode 100644 migrations/011.bulk-extracts.down.sql delete mode 100644 migrations/011.bulk-extracts.up.sql create mode 100644 migrations/012.bulk-extracts.down.sql create mode 100644 migrations/012.bulk-extracts.up.sql diff --git a/migrations/011.bulk-extracts.down.sql b/migrations/011.bulk-extracts.down.sql deleted file mode 100644 index 62f73283..00000000 --- a/migrations/011.bulk-extracts.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS bulk_extracts; \ No newline at end of file diff --git a/migrations/011.bulk-extracts.up.sql b/migrations/011.bulk-extracts.up.sql deleted file mode 100644 index a6bc27ae..00000000 --- a/migrations/011.bulk-extracts.up.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE IF NOT EXISTS bulk_extracts ( - extract_id serial PRIMARY KEY, - extracted_on timestamp NOT NULL, - extract_path text NOT NULL -); \ No newline at end of file diff --git a/migrations/012.bulk-extracts.down.sql b/migrations/012.bulk-extracts.down.sql new file mode 100644 index 00000000..ce7a95db --- /dev/null +++ b/migrations/012.bulk-extracts.down.sql @@ -0,0 +1,8 @@ +DROP TABLE IF EXISTS bulk_extracts; + +-- convert all existing timestamp columns to timestamptz assuming UTC +ALTER TABLE logs ALTER log_timestamp TYPE timestamp; +ALTER TABLE users + ALTER registered TYPE timestamp, + ALTER deleted_on TYPE timestamp; +ALTER TABLE user_password_reset_tokens ALTER expires_on TYPE timestamp; \ No newline at end of file diff --git a/migrations/012.bulk-extracts.up.sql b/migrations/012.bulk-extracts.up.sql new file mode 100644 index 00000000..031ecf3e --- /dev/null +++ b/migrations/012.bulk-extracts.up.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS bulk_extracts ( + extract_id serial PRIMARY KEY, + extracted_on timestamptz NOT NULL, + extract_path text NOT NULL +); + +-- convert all existing timestamp columns to timestamptz assuming UTC +ALTER TABLE logs ALTER log_timestamp TYPE timestamptz USING log_timestamp AT TIME ZONE 'UTC'; +ALTER TABLE users + ALTER registered TYPE timestamptz USING registered AT TIME ZONE 'UTC', + ALTER deleted_on TYPE timestamptz USING deleted_on AT TIME ZONE 'UTC'; +ALTER TABLE user_password_reset_tokens ALTER expires_on TYPE timestamptz USING expires_on AT TIME ZONE 'UTC'; \ No newline at end of file