Convert all columns to timestamptz in migration

This commit is contained in:
Maciej Ziarkowski 2019-10-01 14:57:11 +01:00
parent 6614cdfb4b
commit bc4b4af2d6
4 changed files with 20 additions and 6 deletions

View File

@ -1 +0,0 @@
DROP TABLE IF EXISTS bulk_extracts;

View File

@ -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
);

View File

@ -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;

View File

@ -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';