Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20231211130023_drop_contribution_analytics_mv.rb « migrate « click_house « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b8b4f7fb5c0fb9a7ea9d5464a661de71c6359e4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

class DropContributionAnalyticsMv < ClickHouse::Migration
  def up
    execute <<~SQL
      DROP VIEW IF EXISTS contribution_analytics_events_mv
    SQL
  end

  def down
    execute <<~SQL
      CREATE MATERIALIZED VIEW IF NOT EXISTS contribution_analytics_events_mv
      TO contribution_analytics_events
      AS
      SELECT
        id,
        argMax(path, events.updated_at) as path,
        argMax(author_id, events.updated_at) as author_id,
        argMax(target_type, events.updated_at) as target_type,
        argMax(action, events.updated_at) as action,
        argMax(date(created_at), events.updated_at) as created_at,
        max(events.updated_at) as updated_at
      FROM events
      WHERE (("events"."action" = 5 AND "events"."target_type" = '')
        OR ("events"."action" IN (1, 3, 7, 12)
          AND "events"."target_type" IN ('MergeRequest', 'Issue')))
      GROUP BY id
    SQL
  end
end