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

20230707151359_create_ci_finished_builds.rb « migrate « click_house « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 39521af8d9958c2e298f1f8ba97f43b1c15ca252 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

class CreateCiFinishedBuilds < ClickHouse::Migration
  def up
    execute <<~SQL
      -- source table for CI analytics, almost useless on it's own, but it's a basis for creating materialized views
      CREATE TABLE IF NOT EXISTS ci_finished_builds
      (
        id UInt64 DEFAULT 0,
        project_id UInt64 DEFAULT 0,
        pipeline_id UInt64 DEFAULT 0,
        status LowCardinality(String) DEFAULT '',

        --- Fields to calculate timings
        created_at DateTime64(6, 'UTC') DEFAULT now(),
        queued_at DateTime64(6, 'UTC') DEFAULT now(),
        finished_at DateTime64(6, 'UTC') DEFAULT now(),
        started_at DateTime64(6, 'UTC') DEFAULT now(),

        runner_id UInt64 DEFAULT 0,
        runner_manager_system_xid String DEFAULT '',

        --- Runner fields
        runner_run_untagged Boolean DEFAULT FALSE,
        runner_type UInt8 DEFAULT 0,
        runner_manager_version LowCardinality(String) DEFAULT '',
        runner_manager_revision LowCardinality(String) DEFAULT '',
        runner_manager_platform LowCardinality(String) DEFAULT '',
        runner_manager_architecture LowCardinality(String) DEFAULT '',

        --- Materialized columns
        duration Int64 MATERIALIZED age('ms', started_at, finished_at),
        queueing_duration Int64 MATERIALIZED age('ms', queued_at, started_at)
        --- This table is incomplete, we'll add more fields before starting the data migration
      )
      ENGINE = ReplacingMergeTree -- Using ReplacingMergeTree just in case we accidentally insert the same data twice
      ORDER BY (status, runner_type, project_id, finished_at, id)
      PARTITION BY toYear(finished_at)
    SQL
  end

  def down
    execute <<~SQL
      DROP TABLE ci_finished_builds
    SQL
  end
end