Commit a0046d80 authored by rpereira2's avatar rpereira2

Change historical_data.date to timestamptz data type

Set the time and timezone of existing data to 12:00 in Time.zone since
the sidekiq-cron gem evaluates crons in the Rails timezones.
parent ad966830
# frozen_string_literal: true
class ChangeHistoricalDataDateType < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
# historical_data only contains 1059 rows in gitlab.com. A new row is added
# once a day, so self-managed GitLab instances will probably have even less data.
# We're using `Time.zone.tzinfo.name` here because the sidekiq-cron gem
# evaluates crons against the timezone configured in Rails.
# The HistoricalDataWorker is set to run at 12 everyday.
execute(
<<SQL
ALTER TABLE historical_data ALTER COLUMN date TYPE timestamptz USING ((date + '12:00'::time) AT TIME ZONE '#{Time.zone.tzinfo.name}');
SQL
)
end
def down
change_column :historical_data, :date, :date
end
end
16b402740c6b1dd21908265085e516f63f8858424724ba97f46658e7bd5f7bf2
\ No newline at end of file
...@@ -12699,7 +12699,7 @@ CREATE TABLE group_wiki_repositories ( ...@@ -12699,7 +12699,7 @@ CREATE TABLE group_wiki_repositories (
CREATE TABLE historical_data ( CREATE TABLE historical_data (
id integer NOT NULL, id integer NOT NULL,
date date NOT NULL, date timestamp with time zone NOT NULL,
active_user_count integer, active_user_count integer,
created_at timestamp without time zone, created_at timestamp without time zone,
updated_at timestamp without time zone updated_at timestamp without time zone
......
...@@ -18,7 +18,7 @@ class HistoricalData < ApplicationRecord ...@@ -18,7 +18,7 @@ class HistoricalData < ApplicationRecord
# HistoricalData.at(Date.new(2014, 1, 1)).active_user_count # HistoricalData.at(Date.new(2014, 1, 1)).active_user_count
def at(date) def at(date)
find_by(date: date) find_by(date: date.all_day)
end end
def max_historical_user_count(license: nil, from: nil, to: nil) def max_historical_user_count(license: nil, from: nil, to: nil)
......
---
title: Change historical_data.date from date to timestamptz data type
merge_request: 45893
author:
type: changed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment