From 3db8c2909e09590b47d148a24fb938cb4fb16acc Mon Sep 17 00:00:00 2001
From: Pedro Pombeiro <noreply@pedro.pombei.ro>
Date: Wed, 3 Jul 2024 18:15:16 +0200
Subject: [PATCH] Recreate ci_finished_pipelines ClickHouse table

Changelog: added
---
 ...00_recreate_ci_finished_pipelines_table.rb | 55 +++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 db/click_house/migrate/main/20240703165200_recreate_ci_finished_pipelines_table.rb

diff --git a/db/click_house/migrate/main/20240703165200_recreate_ci_finished_pipelines_table.rb b/db/click_house/migrate/main/20240703165200_recreate_ci_finished_pipelines_table.rb
new file mode 100644
index 0000000000000..3ac9b87a5543a
--- /dev/null
+++ b/db/click_house/migrate/main/20240703165200_recreate_ci_finished_pipelines_table.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+class RecreateCiFinishedPipelinesTable < ClickHouse::Migration
+  def up
+    execute <<~SQL
+      DROP TABLE IF EXISTS ci_finished_pipelines
+    SQL
+
+    execute <<~SQL
+      CREATE TABLE ci_finished_pipelines
+      (
+        `id` UInt64 DEFAULT 0,
+        `path` String DEFAULT '0/',
+        `committed_at` DateTime64(6, 'UTC') DEFAULT 0,
+        `created_at` DateTime64(6, 'UTC') DEFAULT 0,
+        `started_at` DateTime64(6, 'UTC') DEFAULT 0,
+        `finished_at` DateTime64(6, 'UTC') DEFAULT 0,
+        `duration` UInt64 DEFAULT 0,
+        `date` Date32 MATERIALIZED toStartOfMonth(finished_at),
+        `status` LowCardinality(String) DEFAULT '',
+        `source` LowCardinality(String) DEFAULT '',
+        `ref` String DEFAULT ''
+      )
+      ENGINE = ReplacingMergeTree
+      PARTITION BY toYear(finished_at)
+      ORDER BY (id)
+    SQL
+  end
+
+  def down
+    execute <<~SQL
+      DROP TABLE IF EXISTS ci_finished_pipelines
+    SQL
+
+    execute <<~SQL
+      CREATE TABLE ci_finished_pipelines
+      (
+        `id` UInt64 DEFAULT 0,
+        `project_id` UInt64 DEFAULT 0,
+        `committed_at` DateTime64(6, 'UTC') DEFAULT 0,
+        `created_at` DateTime64(6, 'UTC') DEFAULT 0,
+        `started_at` DateTime64(6, 'UTC') DEFAULT 0,
+        `finished_at` DateTime64(6, 'UTC') DEFAULT 0,
+        `duration` Int64,
+        `date` Date32 MATERIALIZED toStartOfMonth(finished_at),
+        `status` LowCardinality(String) DEFAULT '',
+        `source` LowCardinality(String) DEFAULT '',
+        `ref` String DEFAULT ''
+      )
+      ENGINE = ReplacingMergeTree
+      PARTITION BY toYear(finished_at)
+      ORDER BY (id)
+    SQL
+  end
+end
-- 
GitLab